Skip to content

fix: WebSocketTransport Re-use and Compatibility #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var LibraryWebSocket = {
}

if (state.onOpen) {
Runtime.dynCall('v', state.onOpen, []);
Module['dynCall_v'](state.onOpen);
}
};

Expand All @@ -59,7 +59,7 @@ var LibraryWebSocket = {
HEAPU8.set(dataBuffer, buffer);

try {
Runtime.dynCall('vii', state.onMessage, [buffer, dataBuffer.length]);
Module['dynCall_vii'](state.onMessage, buffer, dataBuffer.length);
} finally {
_free(buffer);
}
Expand All @@ -78,7 +78,7 @@ var LibraryWebSocket = {
stringToUTF8(msg, msgBuffer, msgBytes);

try {
Runtime.dynCall('vi', state.onError, [msgBuffer]);
Module['dynCall_vi'](state.onError, msgBuffer)
} finally {
_free(msgBuffer);
}
Expand All @@ -91,7 +91,7 @@ var LibraryWebSocket = {
}

if (state.onClose) {
Runtime.dynCall('vi', state.onClose, [ev.code]);
Module['dynCall_vi'](state.onClose, ev.code)
}
};
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void Close(CloseStatusCode code = CloseStatusCode.Normal, string reason =

if (ReadyState == WebSocketSharp.WebSocketState.Closed)
{
throw new InvalidOperationException("Socket is already closed");
return;
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Netcode.Transports.WebSocket
{
public class WebSocketClientFactory
{
#if UNITY_WEBGL
public static JSWebSocketClient Client = new JSWebSocketClient();
#if (UNITY_WEBGL && !UNITY_EDITOR)
public static JSWebSocketClient Client;

internal delegate void OnOpenCallback();
internal delegate void OnMessageCallback(IntPtr messagePointer, int messageSize);
Expand Down Expand Up @@ -67,7 +67,8 @@ internal static void OnCloseEvent(int disconnectCode)

public static IWebSocketClient Create(string url)
{
#if UNITY_WEBGL
#if (UNITY_WEBGL && !UNITY_EDITOR)
Client = new JSWebSocketClient();
_SetUrl(url);
_SetOnOpen(OnOpenEvent);
_SetOnMessage(OnMessageEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Netcode.Transports.WebSocket
{
public class WebSocketTransport : NetworkTransport
{
private static WebSocketServer WebSocketServer = null;
private static IWebSocketClient WebSocketClient = null;
private static bool IsStarted = false;
private WebSocketServer WebSocketServer = null;
private IWebSocketClient WebSocketClient = null;
private bool IsStarted = false;

[Header("Transport")]
public string ConnectAddress = "127.0.0.1";
Expand Down Expand Up @@ -101,6 +101,7 @@ public override void Shutdown()
{
WebSocketServer.Stop();
}
IsStarted = false;
}

public override bool StartClient()
Expand Down