sipsorcery icon indicating copy to clipboard operation
sipsorcery copied to clipboard

How do I have WebRTC run on both browser and native?

Open ValorZard opened this issue 1 year ago • 1 comments

Hello! I'm working on an application all in C# that uses WebRTC, and I want to set it up so that when compiled for desktop, it uses SIPScorcery's webrtc implementation, but if it's compiled for the web, it uses the web's WebRTC api. What would be the best way to do that?

Edit: if it helps, this is something that pion can do quite well: https://github.com/pion/webrtc/tree/master/examples/data-channels-detach

ValorZard avatar Oct 07 '24 17:10 ValorZard

I don't think the repo there points to a pion example that does this. node-webrtc [1] and node-libdatachannel [2] have shims to do this and those are aimed at the browser API compatibility too (and can be used as drop-in to each other with a simple import name change). I think the equivalent code for the pion subdirectory can be obtained from [3] .

Certain WebRTC API-like behaviour, including waiting with a synchronous timeout, do not work well with SipSorcery. SipSorcery also does not work in some cases when WebRTC-rs just works (with a STUN server instead of TURN). TURN-UDP support is mostly complete and it works. I think you may have to come up with your own, as the API names aren't that compatible (but everything else is)!

[1] https://github.com/WonderInventions/node-webrtc/ [2] https://github.com/murat-dogan/node-datachannel/tree/master/src/polyfill [3] https://github.com/sipsorcery/webrtc-echoes

Regards, Rishi

ris-work avatar Oct 09 '24 04:10 ris-work

...but if it's compiled for the web...

You'll need to elaborate what you mean here. Unless you're using something like WebAssembly, or a very out of fashion plugin technolog (ActiveX, Flash, SilverlIght) it's unlikely you're compiling anything for a web app.

Or do you mean a desktop app and a web server app? In this case there's no real difference. This library exposes an approximate interface that matches the Browser WebRTC spec. Using if from an ASP.NET app or a desktop .NET app is the same and there are examples of both in the WebRTC examples directory.

sipsorcery avatar Oct 27 '24 21:10 sipsorcery

@sipsorcery i meant specifically compiling for webassembly. As in, being able to replace the native c# calls with calls to the javascript webrtc api

ValorZard avatar Nov 03 '24 23:11 ValorZard

Ok, I understand what you're asking but I have no idea how to do it. I've never built a WebASM app. It seems like the question is more about that than this library.

sipsorcery avatar Nov 04 '24 23:11 sipsorcery