Skip to content

Commit

Permalink
Fixed up logic for when a reconnect fails. It was not firing the reco…
Browse files Browse the repository at this point in the history
…nnect failed message.

Added a test for this to ensure forward compatibility.
  • Loading branch information
Jake Hilton committed May 21, 2014
1 parent 35678e0 commit f321499
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
Binary file modified bin/netconnectionsmart.swc
Binary file not shown.
18 changes: 11 additions & 7 deletions src/com/gearsandcogs/utils/NetConnectionSmart.as
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
VERSION: 1.3.3
VERSION: 1.3.4
DATE: 05/09/2014
ACTIONSCRIPT VERSION: 3.0
DESCRIPTION:
Expand Down Expand Up @@ -117,7 +117,7 @@ package com.gearsandcogs.utils
private static const RTMFP:String = "rtmfp";
private static const RTMP:String = "rtmp";
private static const RTMPT:String = "rtmpt";
public static const VERSION:String = "NetConnectionSmart v 1.3.3";
public static const VERSION:String = "NetConnectionSmart v 1.3.4";

public var append_guid:Boolean;
public var auto_reconnect:Boolean;
Expand All @@ -138,17 +138,18 @@ package com.gearsandcogs.utils
public var reconnect_count_limit:uint = 10;
public var reconnect_max_time_wait:uint = 10;

protected var _connect_string_init:String;
protected var _ncTypes:Vector.<NetConnectionType>;

private var _connectParams:Array;
private var _connectParamsInit:Array;
private var _portArray:Array = [443, 80, 1935];
private var _initial_connect_run:Boolean;
private var _is_connecting:Boolean;
private var _was_connected:Boolean;
private var _ncClient:Object;
private var _nc:PortConnection;
private var _app_string:String;
private var _connect_string_init:String;
private var _guid:String;
private var _proxy_type:String = "none";
private var _server_string:String;
Expand Down Expand Up @@ -339,7 +340,10 @@ package com.gearsandcogs.utils
return;

if (!is_dirty)
{
_was_connected = false;
_nc.was_connected = false;
}

_nc.close();

Expand Down Expand Up @@ -567,8 +571,7 @@ package com.gearsandcogs.utils

dispatchEvent(e);

if (!auto_reconnect || !_nc || !_nc.was_connected ||
(e.info.code != "NetConnection.Connect.Closed" && e.info.code != "NetConnection.Connect.Failed"))
if (!auto_reconnect || !_was_connected || (e.info.code != "NetConnection.Connect.Closed" && e.info.code != "NetConnection.Connect.Failed"))
return;

if (reconnect_count_limit == 0 || (_reconnect_count < reconnect_count_limit))
Expand Down Expand Up @@ -629,11 +632,12 @@ package com.gearsandcogs.utils
}
else if (!connected && curr_connection.connected)
{
acceptNc(curr_connection);
handleNetStatus(curr_connection.status);
_is_connecting = false;
_was_connected = true;
_reconnect_count = 0;
_connection_attempt_count = 0;
acceptNc(curr_connection);
handleNetStatus(curr_connection.status);
return;
}
else if (!rejected_connection && curr_connection.rejected)
Expand Down
43 changes: 40 additions & 3 deletions testSrc/com/gearsandcogs/utils/NetConnectionSmartReconnectTest.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ package com.gearsandcogs.utils

public class NetConnectionSmartReconnectTest extends NetConnectionSmart
{
private var valid_connect_server:String = "wowzaec2demo.streamlock.net/vod/";
private var invalid_connect_server:String = "wowzaec2demo.streamlockbad.net/vod/";

public function NetConnectionSmartReconnectTest()
{
super();
Expand All @@ -21,7 +24,8 @@ package com.gearsandcogs.utils
public function setUp():void
{
auto_reconnect = true;
connect("wowzaec2demo.streamlock.net/vod/");
reconnect_count_limit = 1;
connect(valid_connect_server);
Async.proceedOnEvent(this, this, NetStatusEvent.NET_STATUS, 60000);
}

Expand All @@ -32,7 +36,7 @@ package com.gearsandcogs.utils
}

[Test(async)]
public function testDisconnectReconnect():void
public function testDisconnectReconnectSuccess():void
{
assertTrue(connected);

Expand All @@ -51,5 +55,38 @@ package com.gearsandcogs.utils
assertEquals(e.info.code, NETCONNECTION_CONNECT_SUCCESS);
}
}

[Test(async)]
public function testDisconnectReconnectFail():void
{
var ref:NetConnectionSmartReconnectTest = this;

assertTrue(connected);

Async.handleEvent(ref, ref, NetStatusEvent.NET_STATUS, handleNetStatusClose, 1000, ref);

_connect_string_init = invalid_connect_server;
close(true);
assertFalse(connected);

Async.handleEvent(ref, ref, NetStatusEvent.NET_STATUS, handleNetStatusReconnect, 60000, ref);

function handleNetStatusClose(e:NetStatusEvent, test:NetConnectionSmartReconnectTest):void
{
assertEquals(NETCONNECTION_CONNECT_CLOSED, e.info.code);
}
function handleNetStatusReconnect(e:NetStatusEvent, test:NetConnectionSmartReconnectTest):void
{
//expect a connection failed first
assertEquals(NETCONNECTION_CONNECT_FAILED, e.info.code);

//then make sure we get a connection reconnect failed second
Async.handleEvent(ref, ref, NetStatusEvent.NET_STATUS, handleNetStatusReconnectFail, 60000, ref);
}
function handleNetStatusReconnectFail(e:NetStatusEvent, test:NetConnectionSmartReconnectTest):void
{
assertEquals(NETCONNECTION_RECONNECT_FAILED, e.info.code);
}
}
}
}
}

0 comments on commit f321499

Please sign in to comment.