From 64af28747fbaccb8acaaad5684701bcd4a54b6e9 Mon Sep 17 00:00:00 2001 From: DigiEggz Date: Tue, 8 Aug 2023 12:55:53 -0400 Subject: [PATCH] Disconnect fix (barisyild) + deprecation error fix --- .../v2/bitswarm/BitSwarmClient.hx | 13 +++++-- .../v2/bitswarm/wsocket/WSClient.hx | 3 +- .../serialization/DefaultSFSDataSerializer.hx | 38 +++++++++---------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx b/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx index 7b6008f..cdf5987 100644 --- a/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx +++ b/com/smartfoxserver/v2/bitswarm/BitSwarmClient.hx @@ -488,7 +488,7 @@ class BitSwarmClient extends EventDispatcher * reconnection to the server. */ _attemptingReconnection = true; - _firstReconnAttempt=haxe.Timer.stamp(); + _firstReconnAttempt = haxe.Timer.stamp() * 1000; _reconnCounter=1; // Fire event and retry @@ -503,8 +503,8 @@ class BitSwarmClient extends EventDispatcher if(!_attemptingReconnection) return; - var reconnectionSeconds:Int=sfs.getReconnectionSeconds()* 1000; - var now:Float=haxe.Timer.stamp(); + var reconnectionSeconds:Int = sfs.getReconnectionSeconds() * 1000; + var now:Float = haxe.Timer.stamp() * 1000; var timeLeft:Float=(_firstReconnAttempt + reconnectionSeconds)- now; if(timeLeft>0) @@ -562,6 +562,13 @@ class BitSwarmClient extends EventDispatcher private function processIOError(error:String):Void { + // Reconnection failure + if(_attemptingReconnection) + { + reconnect(); + return; + } + trace("## SocketError:" + error); var event:BitSwarmEvent = new BitSwarmEvent(BitSwarmEvent.IO_ERROR); event.params = { diff --git a/com/smartfoxserver/v2/bitswarm/wsocket/WSClient.hx b/com/smartfoxserver/v2/bitswarm/wsocket/WSClient.hx index 13629df..1279b2d 100644 --- a/com/smartfoxserver/v2/bitswarm/wsocket/WSClient.hx +++ b/com/smartfoxserver/v2/bitswarm/wsocket/WSClient.hx @@ -1,4 +1,4 @@ -package com.smartfoxserver.v2.bitswarm.wsocket; +package com.smartfoxserver.v2.bitswarm.wsocket; import openfl.events.Event; import openfl.Lib; @@ -102,4 +102,3 @@ class WSClient extends EventDispatcher ws.close(); } } - diff --git a/com/smartfoxserver/v2/protocol/serialization/DefaultSFSDataSerializer.hx b/com/smartfoxserver/v2/protocol/serialization/DefaultSFSDataSerializer.hx index 8712189..7c752f9 100644 --- a/com/smartfoxserver/v2/protocol/serialization/DefaultSFSDataSerializer.hx +++ b/com/smartfoxserver/v2/protocol/serialization/DefaultSFSDataSerializer.hx @@ -907,7 +907,7 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer if(classFullName==null) throw new SFSCodecError("Cannot detect class name:" + sfsObj); - if(!(Std.is(asObj, SerializableSFSType))) + if(!(Std.isOfType(asObj, SerializableSFSType))) throw new SFSCodecError("Cannot serialize object:" + asObj + ", type:" + classFullName + " -- It doesn't implement the SerializableSFSType Interface"); var fieldList:ISFSArray = SFSArray.newInstance(); @@ -958,13 +958,13 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer var wrapper:SFSDataWrapper=null; var type:String = Type.getClassName(Type.getClass(value)); - if(Std.is(value, Bool)) + if(Std.isOfType(value, Bool)) wrapper = new SFSDataWrapper(SFSDataType.BOOL, value); - else if(Std.is(value, Int) || Std.is(value,Int)) + else if(Std.isOfType(value, Int) || Std.isOfType(value,Int)) wrapper = new SFSDataWrapper(SFSDataType.INT, value); - else if(Std.is(value, Float)) + else if(Std.isOfType(value, Float)) { // Differntiate between decimal(Double)and non-decimal(Long) if(value==Math.floor(value)) @@ -973,16 +973,16 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer wrapper = new SFSDataWrapper(SFSDataType.DOUBLE, value); } - else if(Std.is(value, String)) + else if(Std.isOfType(value, String)) wrapper = new SFSDataWrapper(SFSDataType.UTF_STRING, value); - else if(Std.is(value, Array)) + else if(Std.isOfType(value, Array)) wrapper = new SFSDataWrapper(SFSDataType.SFS_ARRAY, unrollArray(value)); - else if(Std.is(value, SerializableSFSType)) + else if(Std.isOfType(value, SerializableSFSType)) wrapper = new SFSDataWrapper(SFSDataType.SFS_OBJECT, as2sfs(value)); - else if(Std.is(value, Dynamic)) + else if(Std.isOfType(value, Dynamic)) wrapper = new SFSDataWrapper(SFSDataType.SFS_OBJECT, unrollDictionary(value)); return wrapper; @@ -1027,7 +1027,7 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer var theClass:Class = Type.resolveClass(className); asObj = Type.createInstance(theClass,[]); - if(!(Std.is(asObj, SerializableSFSType))) + if(!(Std.isOfType(asObj, SerializableSFSType))) throw new SFSCodecError("Cannot deserialize object:" + asObj + ", type:" + className + " -- It doesn't implement the SerializableSFSType Interface"); //trace("CLASS:" + className) @@ -1145,19 +1145,19 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer // Call recursively _scanGenericObject(item, subSfso, forceToNumber); } - else if(Std.is(item, Array)) + else if(Std.isOfType(item, Array)) sfso.putSFSArray(key, genericArrayToSFSArray(item, forceToNumber)); - else if(Std.is(item, Bool)) + else if(Std.isOfType(item, Bool)) sfso.putBool(key, item); - else if(Std.is(item, Int) && !forceToNumber) + else if(Std.isOfType(item, Int) && !forceToNumber) sfso.putInt(key, item); - else if(Std.is(item, Float)) + else if(Std.isOfType(item, Float)) sfso.putDouble(key, item); - else if(Std.is(item, String)) + else if(Std.isOfType(item, String)) sfso.putUtfString(key, item); } @@ -1231,7 +1231,7 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer else if(Type.typeof(item) == ValueType.TObject) sfsa.addSFSObject(genericObjectToSFSObject(item, forceToNumber)); - else if(Std.is(item, Array)) + else if(Std.isOfType(item, Array)) { var subSfsa:ISFSArray = new SFSArray(); sfsa.addSFSArray(subSfsa); @@ -1240,16 +1240,16 @@ class DefaultSFSDataSerializer implements ISFSDataSerializer _scanGenericArray(item, subSfsa, forceToNumber); } - else if(Std.is(item, Bool)) + else if(Std.isOfType(item, Bool)) sfsa.addBool(item); - else if(Std.is(item, Int) && !forceToNumber) + else if(Std.isOfType(item, Int) && !forceToNumber) sfsa.addInt(item); - else if(Std.is(item, Float)) + else if(Std.isOfType(item, Float)) sfsa.addDouble(item); - else if(Std.is(item, String)) + else if(Std.isOfType(item, String)) sfsa.addUtfString(item); }