From 4bd253427cfeb52a595a00a05ab44919e79571ab Mon Sep 17 00:00:00 2001 From: DigiEggz Date: Thu, 10 Aug 2023 20:07:52 -0400 Subject: [PATCH] Fix BlueBox crash on HashLink Prevent HashLink from crashing when attempting to connect through BlueBox to a closed socket. --- com/smartfoxserver/v2/SmartFox.hx | 3 ++- com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/com/smartfoxserver/v2/SmartFox.hx b/com/smartfoxserver/v2/SmartFox.hx index 42405ff..193ea98 100644 --- a/com/smartfoxserver/v2/SmartFox.hx +++ b/com/smartfoxserver/v2/SmartFox.hx @@ -2214,9 +2214,10 @@ class SmartFox extends EventDispatcher private function handleConnectionProblem(evt:BitSwarmEvent):Void { - // Socket failed, attempt using the BBox + // Socket failed, attempt using BlueBox if(_bitSwarm.connectionMode==ConnectionMode.SOCKET && _useBlueBox) { + _bitSwarm.disconnect(); _bitSwarm.forceBlueBox(true); var bbPort:Int = config != null ? config.httpPort:DEFAULT_HTTP_PORT; diff --git a/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx b/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx index cdf5987..be4ad47 100644 --- a/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx +++ b/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx @@ -154,7 +154,7 @@ class BitSwarmClient extends EventDispatcher public function forceBlueBox(value:Bool):Void { - if(!connected) + if(!connected || _attemptingReconnection) _useBlueBox = value; else throw new IllegalOperationError("You can't change the BlueBox mode while the connection is running"); @@ -627,8 +627,8 @@ class BitSwarmClient extends EventDispatcher { processIOError(evt.toString()); - // Android _socket not receiving Event.CLOSE; manually disconnect on I/O error - #if android + // Android and HashLink _socket not receiving Event.CLOSE; manually disconnect on I/O error + #if (android || hl) disconnect(); #end } @@ -674,8 +674,10 @@ class BitSwarmClient extends EventDispatcher trace("## BlueBox Dynamic:" + evt.params.message); var event:BitSwarmEvent = new BitSwarmEvent(BitSwarmEvent.IO_ERROR); event.params = { message:evt.params.message }; - - dispatchEvent(event); + + + //dispatchEvent(event); + onBBDisconnect(evt); } function get_connectionPort():Int