Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tests with a short OPERATION_TIMEOUT

  • Loading branch information...
commit 4f0cd9e62744dbb0b6dbe20e116af9910c614791 1 parent 947f060
Maxim Firsov fmaxx authored
4 flash/3.4/src/com/pubnub/Pn.as
View
@@ -46,7 +46,6 @@ package com.pubnub {
}
private function setup():void {
- //Security.loadPolicyFile('http://pubsub.pubnub.com/crossdomain.xml');
operationsFactory = new Dictionary();
operationsFactory[INIT_OPERATION] = createInitOperation;
@@ -59,9 +58,6 @@ package com.pubnub {
environment.addEventListener(EnvironmentEvent.SHUTDOWN, onEnvironmentShutdown);
environment.addEventListener(NetMonEvent.HTTP_ENABLE, onEnvironmentHttpEnable);
environment.addEventListener(NetMonEvent.HTTP_DISABLE, onEnvironmentHttpDisable);
-
- //Security.loadPolicyFile('http://pubsub.pubnub.com/crossdomain.xml:80');
-
}
private function onEnvironmentHttpDisable(e:NetMonEvent):void {
4 flash/3.4/src/com/pubnub/Settings.as
View
@@ -15,7 +15,9 @@ package com.pubnub {
// ie, 100 times, every 3 seconds for a network connection
// time in millseconds to wait for web server to return a response. DO NOT CHANGE unless requested by support
- public static const OPERATION_TIMEOUT:uint = 310000;
+ public static const OPERATION_TIMEOUT:uint = 15000;
+
+ //public static const RESUBCRIBE_WITH_LAST_TOKEN_TIMEOUT:uint = 5000;
// for wait a response of a ping operation with [PING_OPERATION_URL], ms
public static const PING_OPERATION_TIMEOUT:uint = 2000;
32 flash/3.4/src/com/pubnub/connection/AsyncConnection.as
View
@@ -1,12 +1,23 @@
package com.pubnub.connection {
+ import com.pubnub.net.URLLoaderEvent;
import com.pubnub.operation.Operation;
+ import com.pubnub.operation.OperationEvent;
+ import com.pubnub.Settings;
import flash.events.Event;
+ import flash.utils.clearTimeout;
+ import flash.utils.setTimeout;
/**
* ...
* @author firsoff maxim, firsoffmaxim@gmail.com, icq : 235859730
*/
public class AsyncConnection extends Connection {
+ protected var timeout:int;
+
+ override protected function init():void {
+ super.init();
+ }
+
override public function sendOperation(operation:Operation):void {
super.sendOperation(operation);
if (ready) {
@@ -31,8 +42,29 @@ package com.pubnub.connection {
}
private function doSendOperation(operation:Operation):void {
+ clearTimeout(timeout);
+ timeout = setTimeout(onTimeout, Settings.OPERATION_TIMEOUT, operation);
this.operation = operation;
loader.load(operation.request);
}
+
+ private function onTimeout(operation:Operation):void {
+ dispatchEvent(new OperationEvent(OperationEvent.TIMEOUT, operation));
+ }
+
+ override public function close():void {
+ clearTimeout(timeout);
+ super.close();
+ }
+
+ override protected function onError(e:URLLoaderEvent):void {
+ clearTimeout(timeout);
+ super.onError(e);
+ }
+
+ override protected function onClose(e:Event):void {
+ clearTimeout(timeout);
+ super.onClose(e);
+ }
}
}
1  flash/3.4/src/com/pubnub/connection/SyncConnection.as
View
@@ -57,7 +57,6 @@ package com.pubnub.connection {
//trace(this, 'onTimeout');
if (operation) {
logTimeoutError(operation);
- Log.logTimeout(Errors.OPERATION_TIMEOUT + ', ' + operation.request.url);
operation.onError( { message:Errors.OPERATION_TIMEOUT, operation:operation } );
removeOperation(operation);
}
4 flash/3.4/src/com/pubnub/environment/NetMon.as
View
@@ -52,7 +52,6 @@ package com.pubnub.environment {
private function onLoaderHTTPStatus(e:HTTPStatusEvent):void {
if (_isRunning == false) return;
- //trace('onLoaderHTTPStatus : ' + e.status);
var pingEndTime:int = getTimer() - pingStartTime;
clearTimeout(pingDelayTimeout);
clearTimeout(pingTimeout);
@@ -65,13 +64,12 @@ package com.pubnub.environment {
if (pingEndTime >= Settings.PING_OPERATION_INTERVAL) {
ping();
}else {
- //trace('### : ' + (Settings.PING_OPERATION_INTERVAL - pingEndTime));
pingDelayTimeout = setTimeout(ping, Settings.PING_OPERATION_INTERVAL - pingEndTime);
}
}
private function ping():void {
- trace('Ping!');
+ //trace('Ping!');
if (_isRunning == false) return;
clearTimeout(pingTimeout);
pingStartTime = getTimer();
2  flash/3.4/src/com/pubnub/net/URLLoader.as
View
@@ -5,6 +5,7 @@ package com.pubnub.net {
import flash.errors.IOError;
import flash.events.*;
import flash.net.Socket;
+ import flash.system.Security;
import flash.utils.*;
/**
@@ -67,6 +68,7 @@ package com.pubnub.net {
var port:int = getPort(url);
socket = getSocket(url);
//trace('connect : ' + host, port, socket);
+ //Security.loadPolicyFile("xmlsocket://pubsub.pubnub.com:80");
socket.connect(host, port);
}
1  flash/3.4/src/com/pubnub/operation/OperationEvent.as
View
@@ -9,6 +9,7 @@ package com.pubnub.operation {
public static const RESULT:String = 'OperationEvent.result';
public static const FAULT:String = 'OperationEvent.fault';
+ public static const TIMEOUT:String = 'OperationEvent.timeout';
private var _data:Object;
33 flash/3.4/src/com/pubnub/subscribe/Subscribe.as
View
@@ -3,7 +3,6 @@ package com.pubnub.subscribe {
import com.pubnub.connection.*;
import com.pubnub.environment.*;
import com.pubnub.json.*;
- import com.pubnub.log.Log;
import com.pubnub.net.*;
import com.pubnub.operation.*;
import flash.events.*;
@@ -16,6 +15,7 @@ package com.pubnub.subscribe {
* @author firsoff maxim, support@pubnub.com
*/
public class Subscribe extends EventDispatcher {
+
static public const PNPRES_PREFIX:String = '-pnpres';
static public const SUBSCRIBE:String = 'subscribe';
static public const INIT_SUBSCRIBE:String = 'init_subscribe';
@@ -38,7 +38,8 @@ package com.pubnub.subscribe {
protected var savedTimetoken:String
protected var connection:AsyncConnection;
- protected var _networkEnabled:Boolean
+ protected var _networkEnabled:Boolean;
+
public function Subscribe() {
super(null);
@@ -53,6 +54,20 @@ package com.pubnub.subscribe {
factory[LEAVE] = getLeaveOperation;
connection = new AsyncConnection();
+ connection.addEventListener(OperationEvent.TIMEOUT, onTimeout);
+ }
+
+ private function onTimeout(e:OperationEvent):void {
+ var operation:Operation = e.data as Operation;
+ if (_networkEnabled) {
+ var tkn:String = Settings.RESUME_ON_RECONNECT ? _lastToken : '0';
+ var chs:Array = _channels.concat();
+ trace('saved_channels : ' + chs, Boolean(savedChannels && savedChannels.length > 0));
+ close('Resubcribe with a timeout');
+ if (chs && chs.length > 0) {
+ subcribe(chs.join(','), tkn);
+ }
+ }
}
/**
@@ -133,6 +148,7 @@ package com.pubnub.subscribe {
}
private function doUnsubscribeAll(reason:Object = null):void {
+ //clearInterval(resubTimer);
var allChannels:String = _channels.join(',');
unsubscribe(allChannels, reason);
}
@@ -213,6 +229,7 @@ package com.pubnub.subscribe {
/*---------------------------SUBSCRIBE---------------------------*/
private function doSubscribe():void {
+ //trace('doSubscribe');
var operation:Operation = getOperation(SUBSCRIBE);
connection.sendOperation(operation);
}
@@ -366,18 +383,6 @@ package com.pubnub.subscribe {
connection = null;
}
- /*public function reconnect():void {
- // save current channels
- var channels:String = _channels.join(',');
- // disconnect and leave from all channels
- unsubscribeAll('reconnect...');
- Log.log("Network Restored: Resubscribing on " + 0);
- // restore connection with last channels
- if (channels.length > 0) {
- subcribe(channels);
- }
- }*/
-
public function close(reason:String = null):void {
doUnsubscribeAll(reason);
connection.close();
Please sign in to comment.
Something went wrong with that request. Please try again.