Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactoring Subscribe packaging.

  • Loading branch information...
commit 902174ff2179c06125f8acc659d8d6da331d9290 1 parent 0594448
geremy cohen authored
View
15 flash/3.3.1/src/PubNubFlexExample.mxml
@@ -12,10 +12,10 @@
import flash.external.*;
[Bindable]
- public var channel:String = 'hello_world';
+ public var channel:String = 'a,b,c';
[Bindable]
- public var origin:String = 'pubsub.pubnub.com';
+ public var origin:String = 'multiplexing.pubnub.com';
[Bindable]
public var pub_key:String = 'demo';
@@ -59,10 +59,18 @@
}
private function onSubscribeClick(e:MouseEvent):void {
- var channels:Array = channel.split(',');
+
+ /*** Non MX Support
+ var channels:Array = channel.split(',');
for each(var i:String in channels) {
Pn.subscribe(i);
}
+ */
+
+ /*** MX Support */
+
+ Pn.subscribe(channel);
+
}
private function onSubscribe(e:PnEvent):void {
@@ -70,6 +78,7 @@
switch (e.status) {
case OperationStatus.DATA:
callExternalInterface("console.log", ("Subscribe [DATA], channel : " + e.channel + ', result : ' + e.data.result));
+ trace('result is: ' + e.data.result);
break;
case OperationStatus.CONNECT:
View
2  flash/3.3.1/src/com/pubnub/Pn.as
@@ -19,7 +19,7 @@ package com.pubnub {
private var _initialized:Boolean = false;
private var operations:Dictionary;
private var subscribes:Dictionary;
- private var origin:String = "http://pubsub.pubnub.com";
+ private var origin:String = "http://multiplexing.pubnub.com";
private var _publishKey:String = "demo";
private var _subscribeKey:String = "demo";
private var secretKey:String = "";
View
59 flash/3.3.1/src/com/pubnub/subscribe/Subscribe.as
@@ -2,7 +2,8 @@ package com.pubnub.subscribe {
import com.pubnub.*;
import com.pubnub.environment.*;
import com.pubnub.json.*;
- import com.pubnub.operation.*;
+import com.pubnub.json.PnJSON;
+import com.pubnub.operation.*;
import flash.events.*;
import flash.utils.*;
@@ -126,37 +127,31 @@ package com.pubnub.subscribe {
operation.addEventListener(OperationEvent.RESULT, onSubscribeResult);
operation.addEventListener(OperationEvent.FAULT, onSubscribeError);
}
-
- private function onSubscribeResult(e:OperationEvent):void {
- var result:Object = e.data;
- lastToken = result[1];
- var messages:Array = result[0];
- if(messages) {
- for (var i:int = 0; i < messages.length; i++) {
- if(cipherKey.length > 0){
- _data = {
- channel:_name,
- result:[i+1,PnCrypto.decrypt(cipherKey,messages[i])],
- envelope: result,
- timeout:1
- }
- dispatchEvent(new SubscribeEvent(SubscribeEvent.DATA, _data));
- }
- else {
- _data = {
- channel:_name,
- result:[i+1,PnJSON.stringify(messages[i])],
- envelope: result,
- timeout:1
- }
- dispatchEvent(new SubscribeEvent(SubscribeEvent.DATA, _data));
- }
- }
- }
- subscribeLastToken();
- }
-
- private function subscribeLastToken():void {
+
+ private function onSubscribeResult(e:OperationEvent):void {
+ var eventData:Object = e.data;
+ lastToken = eventData[1];
+ var messages:Array = eventData[0];
+ if (messages) {
+
+ for (var i:int = 0; i < messages.length; i++) {
+
+ var msg:* = cipherKey.length > 0 ? PnJSON.parse(PnCrypto.decrypt(cipherKey, messages[i])) : messages[i];
+
+ _data = {
+ channel:_name,
+ result:[i + 1, msg],
+ //envelope:eventData,
+ timeout:1
+ }
+
+ dispatchEvent(new SubscribeEvent(SubscribeEvent.DATA, _data));
+ }
+ }
+ subscribeLastToken();
+ }
+
+ private function subscribeLastToken():void {
//trace('subscribeLastToken : ' + lastToken);
getOperation(Operation.WITH_TIMETOKEN).close();
subscribeToken(lastToken);
Please sign in to comment.
Something went wrong with that request. Please try again.