Skip to content

Draft: feat(proxy): add support for js,wasm build target

WofWca requested to merge WofWca/snowflake:wasm into main

This allows running the WASM build of proxy in browsers. The example extension that can run it can be found in the proxy/wasm-browser-extension directory. See proxy/README.md for instructions.

I'm marking this MR as "draft" because, as was discussed in the previous anti-censorship meeting, the Snowflake maintainers are not quite sure if they want to migrate the original Snowflake extension to WASM, and, without that, they're not quite sure if they want to maintain support for WASM. But feel free to un-mark as draft, and merge. I'd be happy.

Porting to WASM was surprisingly easy. The changes to the code base are fairly minimal. The behavior of the standalone proxy version (not WASM) is not affected (same for other components of Snowflake (except for the addition of "wasm" proxy type to the broker, but that is a one-line change)).
All thanks to Pion developers!

The WASM build of the proxy uses the browser's built-in WebSocket and WebRTC classes.

For those who are not aware, the current Snowflake extension does not use WASM. That's a pure JS implementation.

The summary of the changes that this MR makes:

  • Abstract away the WebSocket implementation (see common/websocket).
  • Add an option to use the coder/websocket package, instead of gorilla/websocket which we currently use. The point of this change is that the Gorilla WebSocket library cannot run in browsers: it tries to use raw DNS and TCP instead of relying on the built-in JavaScript WebSocket class, which is what coder/websocket does.
  • Add conditions to only run certain code in the standalone (non-WASM) version. Browsers do not support some stuff that standalone Pion does, namely -ephemeral-ports-range, -metrics, -outbound-address.
  • Bring back StripLocalAddresses(). Browsers do not support SetIPFilter(). This does not affect the standalone proxy.
  • Add the proxy/wasm-browser-extension directory. This is a simple, non production-ready browser extension that runs the WASM version of the proxy.

The commit history of this MR is IMO pretty tidy. Merging them one by one (in sequence) is possible if needed. See commit messages for more info (but I laid out pretty much everything in the MR description already).

If you're interested why I worked on this: I'm working on a fork of Snowflake (see https://github.com/WofWca/snowflake-generalized), and I decided that it'd probably be easier to port the Go version to WASM than it would be to port my changes to the Go proxy code to the JavaScript version of Snowflake proxy.

Edit: just FYI, I made a post about this MR on the forum.

Edited by WofWca

Merge request reports

Loading