Skip to content

Commit

Permalink
fix onmessage string callback
Browse files Browse the repository at this point in the history
  • Loading branch information
psygames committed Aug 22, 2024
1 parent dc4037e commit e44a2ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions Assets/UnityWebSocket/Plugins/WebGL/WebSocket.jslib
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var WebSocketLibrary =
/* Event listeners */
onOpen: null,
onMessage: null,
onMessageStr: null,
onError: null,
onClose: null
},
Expand All @@ -45,7 +46,7 @@ var WebSocketLibrary =
},

/**
* Set onMessage callback
* Set onMessageStr callback
*
* @param callback Reference to C# static function
*/
Expand Down Expand Up @@ -104,7 +105,7 @@ var WebSocketLibrary =

var protocol = UTF8ToString(protocolPtr);

if(instance.subProtocols == null)
if (instance.subProtocols == null)
instance.subProtocols = [];

instance.subProtocols.push(protocol);
Expand Down Expand Up @@ -146,7 +147,7 @@ var WebSocketLibrary =
if (!instance) return -1;
if (instance.ws !== null) return -2;

if(instance.subProtocols != null)
if (instance.subProtocols != null)
instance.ws = new WebSocket(instance.url, instance.subProtocols);
else
instance.ws = new WebSocket(instance.url);
Expand All @@ -172,7 +173,7 @@ var WebSocketLibrary =
_free(buffer);
}
}
else if(typeof ev.data == 'string')
else if (typeof ev.data == 'string')
{
var length = lengthBytesUTF8(ev.data) + 1;
var buffer = _malloc(length);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if !UNITY_EDITOR && UNITY_WEBGL
#if !UNITY_EDITOR && UNITY_WEBGL
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit e44a2ae

Please sign in to comment.