❔ Blazor JS Interop - Return RTCPeerConnection from js to Blazor in order to close it

Hi, I've quite a complex task:
In my Blazor application I use javascript to read webrtc data produced by https://github.com/deepch/RTSPtoWeb, which basically take streams from a bunch of RTSP IP Cameras and publishes them as webrtc streams.

Now, everything works fine, the only problem I have is that, after the webrtc connection is open, at a certain point (e.g. if the user leaves the page) I need to close such connection.

In order to establish the connection I use the javascript script provided by the above-mentioned project: https://github.com/deepch/RTSPtoWeb/blob/master/docs/examples/webrtc/main.js, mutatis mutandae.

Now, inside the javascript file, the RTCPeerConnection is created by means of
    const webrtc = new RTCPeerConnection({
      iceServers: [{
        urls: ['stun:stun.l.google.com:19302']
      }],
      sdpSemantics: 'unified-plan'
    })

And in order to close it, I suppose I need to return the created 'webrtc' object to the calling Blazor method, so that Blazor side I can close the RTCPeerCOnnection when needed. But Blazor side, I don't know which object I need to use to "store" the result.

Do you have any tip about how should I proceed?

Thanks
Was this page helpful?