Skip to content

Commit

Permalink
fix: using on events instead of addEventListener
Browse files Browse the repository at this point in the history
some platforms such as WeChat, see
MirrorNetworking/Mirror#3904
  • Loading branch information
James-Frowen committed Oct 1, 2024
1 parent 09e037d commit a342e9f
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions source/Runtime/Client/Webgl/plugin/SimpleWeb.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@ 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);
dynCall('vi', openCallbackPtr, [index]);
});
webSocket.addEventListener('close', function (event) {
}
webSocket.onclose = function (event) {
console.log("Disconnected from " + address);
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
var array = new Uint8Array(event.data);
Expand All @@ -61,13 +61,13 @@ function Connect(addressPtr, openCallbackPtr, closeCallBackPtr, messageCallbackP
else {
console.error("message type not supported")
}
});
}

webSocket.addEventListener('error', function (event) {
webSocket.onerror = function (event) {
console.error('Socket Error', event);

dynCall('vi', errorCallbackPtr, [index]);
});
}

return index;
}
Expand Down

0 comments on commit a342e9f

Please sign in to comment.