itisnajim / SocketIOUnity

A Wrapper for socket.io-client-csharp to work with Unity.
MIT License
393 stars 67 forks source link

Support for WebGL builds #3

Closed justinduynguyen closed 2 years ago

justinduynguyen commented 2 years ago

May you implement a version for WebGL or intent to do in future? I

itisnajim commented 2 years ago

Maybe.. if this (issue) got more votes :)

nekiwo commented 2 years ago

Is the issue with socket.io-client-csharp being not compatible with WebGL or this library's implementation?

nekiwo commented 2 years ago

Okay I found the incompatible code. The issue was inside socket.io-client-csharp and not the SocketIOUnity implementation.

SocketIOClient/Transport/HttpTransport.cs Uses the .NET library system.net.http, which is incompatible with WebGL Adding WebGL support should be as simple as implementing UnityWebRequest instead of HttpClient.

itisnajim commented 2 years ago

socket.io-client-csharp its not for a web project, needs a bridge so!

nekiwo commented 2 years ago

Another issue: socket.io-client-csharp uses threads which aren't compatible with WebGL Unity builds yet

Well I guess rewriting socket.io-client-csharp isn't as easy as I thought 😅

benji56 commented 1 year ago

I guess you don't see any possibility of it ever being compatible?

itisnajim commented 1 year ago

I guess you don't see any possibility of it ever being compatible?

I'm sorry, but the socket.io-client-csharp package is not compatible with the web. However, you can search for a web unity socket io package or create your own, check out Unity-WebGL-3D-Chat . And combine it with this package using an IF ELSE statement.

You can create two separate classes: one for web called SocketIOWebManager and one for native called SocketIONativeManager, and another class to communicate with one of the two depending on the current platform. You can do something similar to what is shown in the SocketManager file, where in the start method you can check the current platform and start either the SocketIOWebManager or SocketIONativeManager object.

I hope this helps!

winxinxinxin commented 5 months ago

hope webgl support

nekiwo commented 4 months ago

For those still looking for an answer, making a JS plug-in that calls socket.io seems to be the only way for now, although this solution isn't ideal.

LesBonsOeufs commented 2 months ago

@nekiwo Any news on this JS plug-in?