MirrorNetworking / Mirror

#1 Open Source Unity Networking Library
https://mirror-networking.com
MIT License
5.26k stars 777 forks source link

fix: Improve SimpleWeb.jslib to fit more platforms #3904

Closed michaelwuwar closed 1 month ago

michaelwuwar commented 2 months ago

Older versions of the addEventListener() solution will fail to call this api properly in some environments. Changing to webSocket.onopen, webSocket.onclose, webSocket.onmessage, webSocket.onerror It does not affect the original browser operation, and enhances additional support for environments such as applets.

James-Frowen commented 1 month ago

Older versions of the addEventListener() solution will fail to call this api properly in some environments. Changing to webSocket.onopen, webSocket.onclose, webSocket.onmessage, webSocket.onerror It does not affect the original browser operation, and enhances additional support for environments such as applets.

Can you give more details on when this fails? both addEventListener and onevent are in the JavaScript spec for websocket so either should work

michaelwuwar commented 1 month ago

Older versions of the addEventListener() solution will fail to call this api properly in some environments. Changing to webSocket.onopen, webSocket.onclose, webSocket.onmessage, webSocket.onerror It does not affect the original browser operation, and enhances additional support for environments such as applets.

Can you give more details on when this fails? both addEventListener and onevent are in the JavaScript spec for websocket so either should work

This operating environment is probably relatively rare. Currently unity in China supports wechat applets, an environment that runs programs within wechat, a mobile software Wechat applets support unity by providing a simulation of a web environment, but that environment is different from traditional web environments in that it doesn't support addEventListener. Very soon, there will be many unity developers for the Chinese market may also run into similar problems as mine, and I'd like to replace it with onevent to provide support for WeChat.

James-Frowen commented 1 month ago

tested the changes here https://github.com/James-Frowen/SimpleWebTransport/commit/a342e9f5ff4ccd4323af6da812cffc38f744edbd

seems to work fine, should be good to merge