Created
December 31, 2024 19:31
Using WebSocket in Lens Studio.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { WebSocketConnection } from "./Scripts/WebSocketConnection"; | |
@component | |
export class SampleUsageWebSocket extends BaseScriptComponent { | |
private websocket: WebSocketConnection; | |
onAwake() { | |
this.websocket = new WebSocketConnection(); | |
this.websocket.onMessage((event) => { | |
this.receiveAudioFromServer(event); | |
}); | |
//Sample sending data to sever | |
this.websocket.send("Hello World"); | |
} | |
receiveAudioFromServer(event: WebSocketMessageEvent) { | |
let blob = event.data as Blob; | |
blob.text().then((text) => { | |
print("Received: " + text); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment