Skip to content

Commit ac62646

Browse files
committed
improve behavior
1 parent 8ccbef3 commit ac62646

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/com/smartfoxserver/v2/bitswarm/wsocket/WSClient.hx

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ class WSClient extends EventDispatcher
5151
throw "WebSocket session is already connected";
5252
}
5353
_useSSL = useSSL;
54+
55+
if(ws != null)
56+
{
57+
ws.onopen = function () {};
58+
ws.onmessageBytes = function(bytes:Bytes) {};
59+
ws.onclose = function(?e:Dynamic) {};
60+
ws.onerror = function(error:String) {};
61+
}
62+
5463
ws = WebSocket.create(protocol + url + ":" + port +"/BlueBox/websocket", null, _debug);
5564
ws.onopen = function () {
5665
_connected = true;
@@ -64,7 +73,8 @@ class WSClient extends EventDispatcher
6473
}));
6574
};
6675
ws.onclose = function(?e:Dynamic) {
67-
handleConnectionLost();
76+
_connected = false;
77+
dispatchEvent(new WSEvent(WSEvent.CLOSED, {}));
6878
};
6979
ws.onerror = function(error:String) {
7080
handleIOError(error);
@@ -110,20 +120,9 @@ class WSClient extends EventDispatcher
110120

111121
public function close() : Void
112122
{
113-
handleConnectionLost(false);
114-
}
115-
116-
private function handleConnectionLost(fireEvent:Bool=true):Void
117-
{
118-
if(_connected)
119-
{
120-
_connected = false;
121-
ws.close();
122-
123-
// Fire event to Bitswarm client
124-
if(fireEvent)
125-
dispatchEvent(new WSEvent(WSEvent.CLOSED, { }));
126-
}
123+
ws.onclose = function(?e:Dynamic) {};
124+
_connected = false;
125+
ws.close();
127126
}
128127

129128
private function handleIOError(error:String):Void

0 commit comments

Comments
 (0)