Created
December 31, 2024 19:31
-
-
Save skang2-sc/a9b4141c1e79808a56d18ce826e7b44f to your computer and use it in GitHub Desktop.
Using WebSocket in Lens Studio.
This file contains hidden or 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