endel / NativeWebSocket

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

Fix issues on Unity 2021.2 #54

Closed kentakang closed 2 years ago

kentakang commented 3 years ago

NativeWebSocket have an 2 issues in Unity 2021.2

  1. Build fails with TextEncoder #53
  2. Pointer_stringify is deprecated on emscripten (https://github.com/emscripten-core/emscripten/pull/8011)

Resolve 2 issues.

microperts commented 3 years ago

Tested, This works!! Thanks

wilg commented 2 years ago

cc @endel

endel commented 2 years ago

Hey, thanks for the PR. Is this backward-compatible with previous versions of Unity as well?

iplusMario commented 2 years ago

On which unity version does it work?

I have 2021.2.7f1 and I am getting the following error:

Invoking error handler due to ReferenceError: Runtime is not defined at WebSocket.instance.ws.onopen (http://localhost:54696/Build/nativewebsocket.framework.js:2536:30)

iplusMario commented 2 years ago

It seams that in unity 2021.2 variable Runtime doesn't exist and can be replaced with Module['dynCall_*'].

In webSocket.jslib change all Runtime.dynCall('1', 2, [3, 4]) for Module['dynCall_1'](2, 3, 4)

Example instance.ws.onopen function in WebSocket.jslib:

change Runtime.dynCall('vi', webSocketState.onOpen, [ instanceId ]);
for
Module['dynCall_vi'](webSocketState.onOpen, instanceId);
jeffreylanters commented 2 years ago

I've tested this using Unity 2021.2.6 and 2021.2.7, works like a charm.

iplusMario commented 2 years ago

It also works on Unity 2020.3.20

Travisism commented 2 years ago

It seams that in unity 2021.2 variable Runtime doesn't exist and can be replaced with Module['dynCall_*'].

In webSocket.jslib change all Runtime.dynCall('1', 2, [3, 4]) for Module['dynCall_1'](2, 3, 4)

Example instance.ws.onopen function in WebSocket.jslib:

change Runtime.dynCall('vi', webSocketState.onOpen, [ instanceId ]);
for
Module['dynCall_vi'](webSocketState.onOpen, instanceId);

Confirmed this fixes the WebGL Runtime error in 2021.2.7f1. There were 5 instances that needed to be updated.

Would be nice to get NativeWebSocket updated with these fixes.

Nayjest commented 2 years ago

Need this fix Why not merged? :(

Nayjest commented 2 years ago

I used this code and build finally not fails, but now I'm getting following error when trying to start network game on WebGL: ReferenceError: Runtime is not defined at WebSocket.instance.ws.onopen So, downgrading to Unity 2021.1 :(

endel commented 2 years ago

Thanks for the PR @kentakang, and everybody that participated! This has been merged, and the Runtime problem has been fixed, too! Please let me know if you have any issues