mirror of
https://github.com/koush/scrypted.git
synced 2026-04-26 18:00:21 +01:00
22 lines
670 B
TypeScript
22 lines
670 B
TypeScript
import { RpcPeer } from "@scrypted/server/src/rpc";
|
|
import type { RTCSignalingSession } from "@scrypted/sdk";
|
|
|
|
export async function createBrowserSignalingSession(ws: WebSocket, localName: string, remoteName: string) {
|
|
const peer = new RpcPeer(localName, remoteName, (message, reject) => {
|
|
const json = JSON.stringify(message);
|
|
try {
|
|
ws.send(json);
|
|
}
|
|
catch (e) {
|
|
reject?.(e);
|
|
}
|
|
});
|
|
ws.onmessage = message => {
|
|
const json = JSON.parse(message.data);
|
|
peer.handleMessage(json);
|
|
};
|
|
|
|
const session: RTCSignalingSession = await peer.getParam('session');
|
|
return session;
|
|
}
|