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

* 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>
This commit is contained in:
Michael Wu 2024-10-01 22:07:02 +08:00 committed by GitHub
parent 18bf67c007
commit 4261dd2189
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}