{"version":3,"sources":["webrtc-interface.ts"],"sourcesContent":["import { logger } from \"../../datex_all.ts\";\nimport { Pointer } from \"../../runtime/pointers.ts\";\nimport { Endpoint } from \"../../types/addressing.ts\";\nimport { PermissionError } from \"../../types/errors.ts\";\nimport { communicationHub } from \"../communication-hub.ts\";\nimport { CommunicationInterface, CommunicationInterfaceSocket, InterfaceDirection, InterfaceProperties } from \"../communication-interface.ts\";\n\n@endpoint class WebRTCSignaling {\n\n    /**\n     * signaling: offer|accept\n     */\n    @property static negotiation(data: RTCSessionDescriptionInit) {\n        if (!datex.meta.signed) throw new PermissionError(\"unauthorized\");\n        if (data.type == \"offer\") WebRTCInterface.handleOffer(datex.meta.caller, data);\n        else if (data.type == \"answer\") WebRTCInterface.handleAnswer(datex.meta.caller, data);\n        else throw new Error(\"Unsupported session description type: \" + data.type);\n    }\n\n    /**\n     * signaling: candidate\n     */\n    @property static candidate(data: RTCIceCandidateInit) {\n        if (!datex.meta.signed) throw new PermissionError(\"unauthorized\");\n        WebRTCInterface.handleCandidate(datex.meta.caller, data);\n    }\n\n    /**\n     * request a specfic media stream - only works once a webrtc connection is established\n     */\n    @property static requestMediaStream(ptrId: string) {\n        if (!datex.meta.signed) throw new PermissionError(\"unauthorized\");\n        return WebRTCInterface.requestMediaStream(datex.meta.caller, ptrId);\n    }\n}\n\nexport class WebRTCInterfaceSocket extends CommunicationInterfaceSocket {\n\n    constructor(public inChannel: RTCDataChannel, public outChannel: RTCDataChannel) {\n        super()\n    }\n\n    handleReceive = (event: MessageEvent) => {\n        if (event.data instanceof ArrayBuffer) {\n            this.receive(event.data)\n        }\n    }\n\n    open() {\n        this.inChannel.addEventListener(\"message\", this.handleReceive);\n    }\n\n    close() {\n        this.inChannel.removeEventListener('message', this.handleReceive);\n    }\n\n    send(dxb: ArrayBuffer) {\n        try {\n            this.outChannel.send(dxb)\n            return true;\n        }\n        catch {\n            return false;\n        }\n    }\n}\n\n/**\n * Creates a direct DATEX communication channel between two WebRTC clients\n */\nexport class WebRTCInterface extends CommunicationInterface {\n    \n    public properties: InterfaceProperties = {\n        type: \"webrtc\",\n        direction: InterfaceDirection.IN_OUT,\n\t\tlatency: 20,\n        bandwidth: 50_000\n    }\n\n    #socket?: WebRTCInterfaceSocket;\n    #sessionInit?: RTCSessionDescriptionInit\n    #endpoint: Endpoint;\n    #connection?: RTCPeerConnection;\n\n    #stunServers: RTCIceServer[]\n    #turnServers: RTCIceServer[]\n\n    #resolveTrackReceivedPromise!: (track: MediaStreamTrack) => void;\n    #trackReceivedPromise!: Promise<MediaStreamTrack>\n\n\n    constructor(endpoint: Endpoint, sesionInit?: RTCSessionDescriptionInit, stunServers?: RTCIceServer[], turnServers?: RTCIceServer[]) {\n        if (WebRTCInterface.connectedInterfaces.has(endpoint)) throw new Error(\"A WebRTCInterface for \" + endpoint + \" already exists\");\n        super()\n\n        this.generateTrackReceivedPromise();\n        this.#endpoint = endpoint;\n        this.#sessionInit = sesionInit;\n        this.properties.name = this.#endpoint.toString();\n        this.#stunServers = stunServers ?? [{urls: 'stun:195.201.173.190:3478'}];\n        this.#turnServers = turnServers ?? [{urls: 'turn:195.201.173.190:3478', username: '1525325424', credential: 'YuzkH/Th9BBaRj4ivR03PiCfr+E='}]; // TODO: get turn server credentials from server\n    }\n\n    connect() {\n\n        WebRTCInterface.connectingInterfaces.set(this.#endpoint, this);\n\n        const {promise, resolve} = Promise.withResolvers<boolean>()\n\n        // try to establish a WebRTC connection, exchange keys first\n        this.#connection = new RTCPeerConnection({\n            iceServers: [...this.#stunServers, ...this.#turnServers]\n        });\n\n        const dataChannelOut = this.#connection.createDataChannel(\"datex\", {protocol: \"datex\"});\n\n        // listeners\n\n        this.#connection.onicecandidate = (e) => {\n            if (e.candidate) WebRTCSignaling.candidate.to(this.#endpoint)(e.candidate.toJSON())\n        };\n\n        // connected\n        this.#connection.onconnectionstatechange = _ => {\n            switch(this.#connection?.connectionState) {\n                case \"disconnected\":\n                case \"closed\":\n                case \"failed\": {\n                    if (this.#socket) this.removeSocket(this.#socket);\n                    resolve(false);\n                }\n                \n            }              \n        };\n\n        // received data channel \n        this.#connection.ondatachannel = (event) => {\n            this.logger.debug(\"received WebRTC data channel\");\n            const dataChannelIn = event.channel\n\n            this.#socket = new WebRTCInterfaceSocket(dataChannelIn, dataChannelOut);\n            this.#socket.endpoint = this.#endpoint;\n            this.addSocket(this.#socket);\n            \n            if (WebRTCInterface.connectingInterfaces.has(this.#endpoint)) {\n                WebRTCInterface.connectingInterfaces.delete(this.#endpoint);\n                WebRTCInterface.connectedInterfaces.set(this.#endpoint, this);\n            }\n            resolve(true);\n        };\n    \n        // received track\n        this.#connection.ontrack = (event) => {\n            this.#resolveTrackReceivedPromise(event.track);\n            this.generateTrackReceivedPromise()\n        }\n\n        this.#connection.onnegotiationneeded = async () => {\n            try {\n                await this.#connection!.setLocalDescription();\n                WebRTCSignaling.negotiation.to(this.#endpoint)(this.#connection!.localDescription!.toJSON())\n            }\n            catch (e) {\n                console.error(e)\n            }\n        }\n\n        // handle initial offer\n        if (this.#sessionInit) {\n            this.handleOffer(this.#sessionInit);\n        }\n\n        return promise;\n    }\n\n    generateTrackReceivedPromise() {\n        const {promise, resolve} = Promise.withResolvers<MediaStreamTrack>();\n        this.#trackReceivedPromise = promise;\n        this.#resolveTrackReceivedPromise = resolve;\n    }\n\n    async collectMediaStreamTracks(count: number) {\n        if (!this.#connection) throw new Error(\"No WebRTC connection found to collect media stream tracks\");\n\n        let tracks: MediaStreamTrack[];\n        let previousCount = -1;\n        while ((tracks = this.#connection.getReceivers().map(receiver => receiver.track)).length < count) {\n            // throw if no new track was added (would lead to infinite loop)\n            if (previousCount == tracks.length) throw new Error(\"Track promise was resolved, but no new track added to connection\");\n            previousCount = tracks.length;\n            await this.#trackReceivedPromise\n        }\n        const mediaStream = new MediaStream();\n        for (const track of tracks) {\n            mediaStream.addTrack(track);\n        }\n        return mediaStream;\n    }\n\n\n    async handleOffer(data: RTCSessionDescriptionInit) {\n        await this.#connection!.setRemoteDescription(data);\n        const answer = await this.#connection!.createAnswer();\n        await this.#connection!.setLocalDescription(answer);\n        WebRTCSignaling.negotiation.to(this.#endpoint)(this.#connection!.localDescription!.toJSON())\n    }\n\n\n    disconnect() {\n        this.#connection?.close();\n        WebRTCInterface.connectedInterfaces.delete(this.#endpoint);\n    }\n\n    override removeSocket(socket: WebRTCInterfaceSocket) {\n        super.removeSocket(socket);\n        WebRTCInterface.connectedInterfaces.delete(this.#endpoint);\n        WebRTCInterface.connectingInterfaces.delete(this.#endpoint);\n    }\n    \n    cloneSocket(socket: WebRTCInterfaceSocket) {\n        return new WebRTCInterfaceSocket(socket.inChannel, socket.outChannel);\n    }\n\n    /**\n     * MediaStream handling\n     */\n\n    attachMediaStream(mediaStream: MediaStream) {\n        if (!this.#connection) throw new Error(\"No WebRTC connection found to attach media stream\");\n        for (const track of mediaStream.getTracks()) {\n            this.#connection.addTrack(track, mediaStream);\n        }\n    }\n\n    static async getMediaStream(ptrId: string) {\n        const pointerOrigin = Pointer.getOriginFromPointerId(ptrId);\n        console.debug(\"requesting mediastream $\" + ptrId + \", origin \" + pointerOrigin)\n        if (!this.connectedInterfaces.has(pointerOrigin)) await communicationHub.addInterface(new WebRTCInterface(pointerOrigin));\n        const interf = this.connectedInterfaces.get(pointerOrigin)!;\n        if (!interf.#connection) throw new Error(\"No WebRTC connection could be established to get media stream\");\n\n        const tracksCount = await WebRTCSignaling.requestMediaStream.to(pointerOrigin)(ptrId);\n        const mediaStream = await interf.collectMediaStreamTracks(tracksCount);\n        console.debug(\"received mediastream\",mediaStream)\n        return mediaStream;\n    }\n\n    /**\n     * Register a media stream to be used by the WebRTC interface\n     * @param mediaStream \n     */\n    static registerMediaStream(mediaStream: MediaStream) {\n        mediaStream = Pointer.proxifyValue(mediaStream) // make sure the media stream is bound to a pointer\n        this.registeredMediaStreams.set(Pointer.getId(mediaStream)!, new WeakRef(mediaStream));\n    }\n\n\n    static registeredMediaStreams = new Map<string, WeakRef<MediaStream>>(); // TODO: garbage collect weakrefs\n    static connectingInterfaces = new Map<Endpoint, WebRTCInterface>();\n    static connectedInterfaces = new Map<Endpoint, WebRTCInterface>();\n\n    static getInterfaceForEndpoint(endpoint: Endpoint, findConnecting = true, findConnected = true) {\n        return (\n            (findConnecting ? this.connectingInterfaces.get(endpoint) : undefined) ??\n            (findConnected ? this.connectedInterfaces.get(endpoint) : undefined)\n        )\n    }\n\n    static getInterfaceConnection(endpoint: Endpoint, findConnecting = true, findConnected = true) {\n        if (!findConnecting && !findConnected) throw new Error(\"Cannot find WebRTC connection: both findConnecting and findConnected are false\");\n\n        let interf = this.getInterfaceForEndpoint(endpoint, findConnecting, findConnected)\n\n        // try with main instance\n        if (!interf) {\n            interf = this.getInterfaceForEndpoint(endpoint.main, findConnecting, findConnected);\n            if (interf) interf.#endpoint = endpoint; // specify received endpoint instance\n        }\n\n        if (!interf) {\n            console.warn(\"No WebRTC interface found for endpoint \" + endpoint);\n            return null;\n        }\n        else if (!interf.#connection) {\n            console.warn(\"No WebRTC connection found for endpoint \" + endpoint);\n            return null;\n        }\n        else return interf.#connection\n    }\n\n    static handleAnswer(endpoint: Endpoint, data: RTCSessionDescriptionInit) {\n        const connection = this.getInterfaceConnection(endpoint, true, true);\n        if (connection) connection.setRemoteDescription(data);\n    }\n\n    static async handleOffer(endpoint: Endpoint, data: RTCSessionDescriptionInit) {\n        const interf = this.getInterfaceForEndpoint(endpoint, true, true);\n        // offer for existing interface\n        if (interf) {\n            await interf.handleOffer(data);\n        }\n        // create new interface\n        else {\n            logger.info(\"Received WebRTC offer from \" + endpoint + \", creating new interface...\")\n            await communicationHub.addInterface(new WebRTCInterface(endpoint, data));\n        }\n    }\n\n\n    static handleCandidate(endpoint: Endpoint, data: RTCIceCandidateInit) {\n        const connection = this.getInterfaceConnection(endpoint, true, true);\n        if (connection) connection.addIceCandidate(data);\n    }\n\n    static requestMediaStream(endpoint: Endpoint, ptrId: string) {\n        const connection = this.getInterfaceConnection(endpoint, false, true);\n        if (!connection) throw new Error(\"Cannot request MediaStream $\" + ptrId + \": no WebRTC connection available\");\n        \n        const mediaStream = this.registeredMediaStreams.get(ptrId)?.deref();\n        if (!mediaStream) throw new Error(\"MediaStream $\" + ptrId + \" not found\");\n        \n        console.debug(endpoint + \" requested mediastream $\" + ptrId)\n        const tracks = mediaStream.getTracks();\n        for (const track of tracks) {\n            connection.addTrack(track, mediaStream);\n        }\n        return tracks.length\n    }\n\n}"],"names":["logger","Pointer","PermissionError","communicationHub","CommunicationInterface","CommunicationInterfaceSocket","InterfaceDirection","WebRTCSignaling","property","negotiation","candidate","requestMediaStream","endpoint","data","datex","meta","signed","type","WebRTCInterface","handleOffer","caller","handleAnswer","Error","handleCandidate","ptrId","WebRTCInterfaceSocket","constructor","inChannel","outChannel","handleReceive","event","ArrayBuffer","receive","open","addEventListener","close","removeEventListener","send","dxb","properties","direction","IN_OUT","latency","bandwidth","sesionInit","stunServers","turnServers","connectedInterfaces","has","generateTrackReceivedPromise","name","toString","urls","username","credential","connect","connectingInterfaces","set","promise","resolve","Promise","withResolvers","RTCPeerConnection","iceServers","dataChannelOut","createDataChannel","protocol","onicecandidate","e","to","toJSON","onconnectionstatechange","_","connectionState","removeSocket","ondatachannel","debug","dataChannelIn","channel","addSocket","delete","ontrack","track","onnegotiationneeded","setLocalDescription","localDescription","console","error","collectMediaStreamTracks","count","tracks","previousCount","getReceivers","map","receiver","length","mediaStream","MediaStream","addTrack","setRemoteDescription","answer","createAnswer","disconnect","socket","cloneSocket","attachMediaStream","getTracks","getMediaStream","pointerOrigin","getOriginFromPointerId","addInterface","interf","get","tracksCount","registerMediaStream","proxifyValue","registeredMediaStreams","getId","WeakRef","Map","getInterfaceForEndpoint","findConnecting","findConnected","undefined","getInterfaceConnection","main","warn","connection","info","addIceCandidate","deref"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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