endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.13k stars 155 forks source link

Is support for WebGL builds approved/condoned by Unity? #51

Closed jsharf closed 2 years ago

jsharf commented 2 years ago

Hello,

I'm thinking about using this for a game I'm developing, and wanted to know if support for WebGL is stable. Reading the Unity documentation, I see:

WebGL does not allow direct access to IP Sockets, but you can use WebSockets or WebRTC (the two most common networking protocols supported by browsers) to get around this. While WebSockets are widely supported, WebRTC allows peer-to-peer connections between browsers and unreliable connections. Unity does not have a built-in API that allows you to use WebSockets or WebRTC, but you can use a JavaScript plugin to implement this

https://docs.unity3d.com/Manual/webgl-networking.html

Maybe I'm misreading this message, but it sounds like the last sentence implies that C# binaries built with Unity have no way of creating websocket connections unless you create one from javascript and then tunnel your socket connection through javascript. I looked at this repository and I don't see you doing this, so how exactly does support for WebGL work here? It seems to use System.Net.Websockets, but I'm not convinced that this is in agreement with the Unity doc I linked above.

Is System.Net.Websockets deprecated in WebGL builds for new versions of Unity? Is there something I've missed?

PS sorry if I've placed this in the wrong spot and been a bother. If there's a better place to followup with this, close the issue and let me know where to post instead.

MaxEden commented 2 years ago

https://github.com/endel/NativeWebSocket/blob/master/NativeWebSocket/Assets/WebSocket/WebSocket.jslib is where it's done.

jsharf commented 2 years ago

Oh cool, thank you so much (I had searched for ".js" files, but not ".jslib").