From 31cffcccaa8afbc540378abcccc57214c617974a Mon Sep 17 00:00:00 2001 From: SONIC3D Date: Wed, 10 Jan 2024 11:19:17 +0800 Subject: [PATCH] Fixed: The callback "onMessageStr" is not properly adapted. --- Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib | 13 +++++++------ .../Implementation/WebGL/WebSocketManager.cs | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib b/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib index a5ba581e..9549da51 100644 --- a/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib +++ b/Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib @@ -21,6 +21,7 @@ var WebSocketLibrary = /* Event listeners */ onOpen: null, onMessage: null, + onMessageStr: null, onError: null, onClose: null }, @@ -46,7 +47,7 @@ var WebSocketLibrary = }, /** - * Set onMessage callback + * Set onMessageStr callback * * @param callback Reference to C# static function */ @@ -106,9 +107,9 @@ var WebSocketLibrary = if (!instance) return -1; var protocol = UTF8ToString(protocolPtr); - - if(instance.subProtocols == null) - instance.subProtocols = []; + + if(instance.subProtocols == null) + instance.subProtocols = []; instance.subProtocols.push(protocol); @@ -137,7 +138,7 @@ var WebSocketLibrary = return 0; }, - + /** * Connect WebSocket to the server * @@ -328,7 +329,7 @@ var WebSocketLibrary = var instance = webSocketManager.instances[instanceId]; if (!instance) return -1; if (instance.ws === null) return 3; // socket null as closed - + return instance.ws.readyState; } }; diff --git a/Assets/UnityWebSocket/Scripts/Runtime/Implementation/WebGL/WebSocketManager.cs b/Assets/UnityWebSocket/Scripts/Runtime/Implementation/WebGL/WebSocketManager.cs index 357d95e8..f77847ba 100644 --- a/Assets/UnityWebSocket/Scripts/Runtime/Implementation/WebGL/WebSocketManager.cs +++ b/Assets/UnityWebSocket/Scripts/Runtime/Implementation/WebGL/WebSocketManager.cs @@ -97,7 +97,7 @@ public static void DelegateOnMessageEvent(int instanceId, IntPtr msgPtr, int msg } } - [MonoPInvokeCallback(typeof(OnMessageCallback))] + [MonoPInvokeCallback(typeof(OnMessageStrCallback))] public static void DelegateOnMessageStrEvent(int instanceId, IntPtr msgStrPtr) { if (sockets.TryGetValue(instanceId, out var socket))