WebAssembly / proposals

Tracking WebAssembly proposals
1k stars 58 forks source link

Is WebRTC usable? #96

Closed Regenhardt closed 8 months ago

Regenhardt commented 3 years ago

I there a way to directly use WebRTC from WASM yet? P2P-Chat is a typical use case for web apps, and it would be nice to be able to use WebRTC APIs without js interop.

Unfortunately as someone only barely touching the topic, it's very complicated to find a direct answer to this online, as there are no examples.

MaxDesiatov commented 3 years ago

In the browser everything you can do from JavaScript can be done from WebAssembly, assuming you have some "glue" code working that bridges calls from Wasm to the JavaScript Web API. How readily and how easily the glue code is available depends on the source language that you compile to Wasm.

MaxDesiatov commented 3 years ago

Not sure what you mean by "directly" though. If that assumes a complete absence of any JavaScript glue code, then the answer is "no". Not only for WebRTC, but for any API. I believe that will be the case until implementations for proposals like Interface Types start becoming available in the actual browser.

fgmccabe commented 3 years ago

If I understand correctly, when you instantiate a wasm module with an API import, (assuming not additional JS glue code), most engines will 'import' a call to the actual API. That still has a JS-style internal interface (calling C from JS) and that is not likely to go away any time soon.

MaxDesiatov commented 3 years ago

Just curious, what API import are you referring to? Can you provide an example?

fgmccabe commented 3 years ago

Any WebAPI; especially one that only takes/provides numeric results. (String arguments/results do require glue code in one form or another.)

MaxDesiatov commented 3 years ago

Ah, right, you mean by providing every function as something to be imported in a Wasm module? As there's no such thing as a WebRTC module, I imagine you would have to enumerate every function manually and pass as separate imported functions, right? And then in WebRTC most of them aren't plainly numeric.

fgmccabe commented 3 years ago

That is the strength of it. With interface types, the glue code would be auto-generated and (depending on the specifics of the situation) in pure wasm. However, for WebAPIs, this also depends on browser implementations, ...

Regenhardt commented 3 years ago

Looks like i still have a big gap in my understanding of WASM.

Can a WASM application interact with the browser in any way without using javascript? Like making http requests? Or is the access to the browser always done through javascript interop? I thought the plan was to make something that could actually replace JS in the long run.

If literally every interaction between WASM and the browser is through JS anyway, would it be just as fast to explicitely use JS interop from my application, or would the "WASM-native" glue code have optimizations or ways to work faster?

mihaiav commented 3 years ago

@Regenhardt

Can a WASM application interact with the browser in any way without using javascript? Like making http requests?

No. You can't even load wasm without JS (e.g. you don't have Githubissues.

  • Githubissues is a development platform for aggregating issues.