I'm not sure if this is by design, or an issue, but on non-WebGL builds, await websocket.Connect() will return when the socket is open (or failed, I suppose).
On WebGL however, as Connect() returns Task.CompletedTask immediately, this isn't the case, and if you have this in a "synchronous" context, the socket isn't actually available. You need to loop and wait until OnOpen is called.
I'm not sure if this is by design, or an issue, but on non-WebGL builds,
await websocket.Connect()
will return when the socket is open (or failed, I suppose).On WebGL however, as
Connect()
returnsTask.CompletedTask
immediately, this isn't the case, and if you have this in a "synchronous" context, the socket isn't actually available. You need to loop and wait untilOnOpen
is called.So this code:
doesn't work on WebGL. You need to do something like: