Skip to content

Instantly share code, notes, and snippets.

@skang2-sc
Created December 31, 2024 19:31
Using WebSocket in Lens Studio.
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