centrifuge-go
centrifuge-go copied to clipboard
Compile to WebAssembly
Relates #67
This pull requests adds possibility to use centrifuge-go
in browser using compilation to WebAssembly. The implementation here is an adapted code from https://github.com/nhooyr/websocket which supports WASM env for some time already. PR contains a simple example that demonstrates how centrifuge-go
and wasm
can be used together to build a browser app.
The example shown in the PR weights 12 MB when using standard Go compiler. Which is quite sad. And this makes me skeptical a bit about the idea - not sure whether someone wants to put file of this size to the browser app.
For Tinygo the situation is quite bad at the moment:
- We can't use segmentio/encoding package -
github.com/segmentio/[email protected]/json/reflect.go:12:23: ArrayOf not declared by package reflect
- may be fixed by switching to stdlib JSON and using build tags in protocol package or when https://github.com/tinygo-org/tinygo/issues/2115 solved - Tinygo does not support
(reflect.Type).PkgPath()
- https://github.com/tinygo-org/tinygo/issues/2668 - Tinygo does not implement timers https://github.com/tinygo-org/tinygo/issues/1037 -
Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #13 module="env" function="time.stopTimer" error: function import requires a callable
Tinygo could help reduce 12 MB to ~3 MB when all the issues mentioned above solved.