diff --git a/server.ts b/server.ts index 9fb7369..7cf6bdc 100644 --- a/server.ts +++ b/server.ts @@ -62,11 +62,13 @@ class Client { send(message: Message) { try { - this.socket.send( - typeof message === "object" - ? ("json:" + JSON.stringify(message)) - : message, - ); + if (this.isConnected()) { + this.socket.send( + typeof message === "object" + ? ("json:" + JSON.stringify(message)) + : message, + ); + } } catch (e) { console.error( `Failed to send on socket ${this.socket} to client ${this.id}. Disconnecting and removing...`, diff --git a/signaller_client.gd b/signaller_client.gd index 3fc6716..a720785 100644 --- a/signaller_client.gd +++ b/signaller_client.gd @@ -35,7 +35,7 @@ func connect_to_websocket_signaller(url: String): print("Attempting to connect to WebSocket signalling server at ", url) var _result = ws.connect_to_url(url) -func _closed(): +func _closed(_unknown): emit_signal("websocket_disconnected") func _close_request(code: int, reason: String):