WebSocket: Undefined union2 decode function
Closed this issue · 8 comments
When trying to use WebSocket, the browser says:
Uncaught ReferenceError: spasm_decode_union2_string_sequence is not defined
Example code:
import spasm.bindings;
import spasm.dom;
auto ws = window.WebSocket("ws://localhost:8080", SumType!(string, Sequence!string)(""));
On master.
You will need to run the bindgen utility after compilation. It will generate the required js glue code. See the readme for instructions. After that you will need to run it any time you call new bindings. On what os are you? There are known issues on Windows. Hope to fix them in the coming days.
I did run dub run spasm:webidl -- --bindgen
after compiling.
I'm on Linux.
Here is a minimal test case exhibiting the issue:
websocket.tar.gz
Built using:
dub build --compiler=ldc --build=release && dub run spasm:webidl -- --bindgen && npx webpack && npm run start
I have found the issue. The bindgen utility doesn't create js decoders/encoders for arguments on exposed constructors. Hope to fix it today.
Great news! 👍
You can try version 0.1.13
You will need to wait until dub picks up the changes. And don't forget to re-compile and rerun the bindgen utility. Thanks for trying this out!
I can confirm that it's working. Tested with a Vibe.d WebSocket.
For anybody reading this in the future: If you don't want to require a subprotocol (Vibe.d doesn't support it), you need to initialize the WebSocket like this:
window.WebSocket("wss://localhost/ws", SumType!(string, Sequence!string)(Sequence!string()));
Empty strings and null doesn't work.