From 4261dd21896965042bc82e9c61a46d0d6e4b053a Mon Sep 17 00:00:00 2001 From: Michael Wu <79647006+michaelwuwar@users.noreply.github.com> Date: Tue, 1 Oct 2024 22:07:02 +0800 Subject: [PATCH] fix(SimpleWebTransport): Improve SimpleWeb.jslib to fit more platforms (#3904) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Improve SimpleWeb.jslib to fit more platforms * fix: Improve SimpleWeb.jslib to fit more platforms * Update Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com> * Update Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com> --------- Co-authored-by: “michaelwuwar” <“2443973716@qq.com”> Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com> --- .../Client/Webgl/plugin/SimpleWeb.jslib | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib index 2fdefc382..f0ab1ac7d 100644 --- a/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib +++ b/Assets/Mirror/Transports/SimpleWeb/SimpleWeb/Client/Webgl/plugin/SimpleWeb.jslib @@ -49,23 +49,21 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP const index = SimpleWeb.AddNextSocket(webSocket); // Connection opened - webSocket.addEventListener('open', function (event) + webSocket.onopen = function(event) { console.log("Connected to " + address); Runtime.dynCall('vi', openCallbackPtr, [index]); - }); - webSocket.addEventListener('close', function (event) + }; + + webSocket.onclose = function(event) { console.log("Disconnected from " + address); Runtime.dynCall('vi', closeCallBackPtr, [index]); - }); + }; - // Listen for messages - webSocket.addEventListener('message', function (event) + webSocket.onmessage = function(event) { - if (event.data instanceof ArrayBuffer) - { - // TODO dont alloc each time + if (event.data instanceof ArrayBuffer) { var array = new Uint8Array(event.data); var arrayLength = array.length; @@ -80,13 +78,13 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP { console.error("message type not supported") } - }); + }; - webSocket.addEventListener('error', function (event) + webSocket.onerror = function(event) { console.error('Socket Error', event); Runtime.dynCall('vi', errorCallbackPtr, [index]); - }); + }; return index; }