Skip to content

Commit 5b18e53

Browse files
author
gcohen
committed
init and connect based on test object config working.
1 parent a1d4294 commit 5b18e53

2 files changed

Lines changed: 95 additions & 102 deletions

File tree

web/examples/presenceTest350.html

Lines changed: 94 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -3,109 +3,108 @@
33

44
var channelA = "gecA";
55
var channelB = "gecB";
6+
var randomSuffix = "";
7+
8+
var ssl = false;
9+
var clientLevel = "";
10+
var serverLevel = "";
11+
12+
var pubKey = "";
13+
var subKey = "";
14+
15+
var listenerUUID = "PN_LISTENER";
16+
var actorUUID = "PN_ACTOR";
17+
18+
var pnLoadedInterval = "";
19+
var listener = "";
20+
var actor = "";
21+
var extraCompat = "";
22+
23+
624
var keysets = {
725

826
"keyset1": {
9-
"pub": "pub-c-fb5fa283-0d93-424f-bf86-d9aca2366c86",
10-
"sub": "sub-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe",
11-
"sec": "sec-c-MmI2YjRjODAtNWU5My00ZmZjLTg0MzUtZGM1NGExNjJkNjg1",
27+
"pubKey": "pub-c-fb5fa283-0d93-424f-bf86-d9aca2366c86",
28+
"subKey": "sub-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe",
29+
"secKey": "sec-c-MmI2YjRjODAtNWU5My00ZmZjLTg0MzUtZGM1NGExNjJkNjg1",
1230
"description": "Compatibility Mode ON"
1331
},
1432

1533
"keyset2": {
16-
"pub": "pub-c-c9b0fe21-4ae1-433b-b766-62667cee65ef",
17-
"sub": "sub-c-d91ee366-9dbd-11e3-a759-02ee2ddab7fe",
18-
"sec": "sec-c-ZDUxZGEyNmItZjY4Ny00MjJmLWE0MjQtZTQyMDM0NTY2MDVk",
34+
"pubKey": "pub-c-c9b0fe21-4ae1-433b-b766-62667cee65ef",
35+
"subKey": "sub-c-d91ee366-9dbd-11e3-a759-02ee2ddab7fe",
36+
"secKey": "sec-c-ZDUxZGEyNmItZjY4Ny00MjJmLWE0MjQtZTQyMDM0NTY2MDVk",
1937
"description": "Compatibility Mode OFF"
2038
}
2139
};
2240

23-
2441
var tests = {
25-
// test1
26-
// 1. actor subscribes to a
27-
// 2. expect a join from actor on UUID PN_ACTOR_UUID within 5s
2842

2943
"35_35_SSL_OFF": {
3044

31-
"description": "3.5 -> 3.5 Base Compatibility, SSL Off.",
32-
"client": "3.5",
33-
"server": "3.5",
34-
"keyset": keysets.keyset1,
35-
"ssl": false,
45+
"common": {
46+
"description": "3.5 -> 3.5 Base Compatibility, SSL Off.",
47+
"client": "3.5",
48+
"server": "3.5",
49+
"keyset": keysets.keyset1,
50+
"ssl": false,
51+
"maxSteps": 3
52+
},
3653

37-
"max_steps": 3,
54+
"testSpecific": {
3855

39-
1: {
40-
"actor": ["subscribe", channelA, 0],
41-
"listener": ["join", channelA, 5]
4256
},
4357

44-
2: {
45-
"actor": ["subscribe", channelB, 5],
46-
47-
"listener": [
48-
["leave", channelA, 5],
49-
["join", channelA, 5],
50-
["join", channelB, 5]
51-
]
58+
"platformSpecific": {
59+
"JS_WEB": {
60+
"clientExtraCompatibilityFlag": true // actually doesn't matter for 3.5 -> 3.5
61+
}
5262
},
5363

54-
3: {
55-
"actor": ["unsubscribe", channelA, 5],
56-
"listener": [
57-
["leave", channelA, 5],
58-
["leave", channelB, 5],
59-
["join", channelB, 5]
60-
]
64+
"steps": {
65+
1: {
66+
"actor": ["subscribe", channelA, 0],
67+
"listener": ["join", channelA, 5]
68+
},
69+
70+
2: {
71+
"actor": ["subscribe", channelB, 5],
72+
73+
"listener": [
74+
["leave", channelA, 5],
75+
["join", channelA, 5],
76+
["join", channelB, 5]
77+
]
78+
},
79+
80+
3: {
81+
"actor": ["unsubscribe", channelA, 5],
82+
"listener": [
83+
["leave", channelA, 5],
84+
["leave", channelB, 5],
85+
["join", channelB, 5]
86+
]
87+
}
6188
}
6289
}
6390
};
6491

65-
runTest(tests["35_35"]);
6692

93+
runTest(tests["35_35_SSL_OFF"]);
6794

68-
function runTest(testNub){
95+
function runTest(testNub) {
6996
console.log("Running test: " + testNub.description);
70-
97+
ssl = testNub.common.ssl;
98+
clientLevel = testNub.common.client;
99+
serverLevel = testNub.common.server;
100+
pubKey = testNub.common.keyset.pubKey;
101+
subKey = testNub.common.keyset.subKey;
102+
extraCompat = testNub.platformSpecific.JS_WEB.clientExtraCompatibilityFlag;
71103
}
72104

73-
var PN_LISTENER_UUID = "PN_LISTENER";
74-
var PN_ACTOR_UUID = "PN_ACTOR";
75-
76-
var compatMode = true;
77-
var ssl = false;
78-
var clientLevel = "3.5";
79-
var serverLevel = "3.6";
80105
var pnLoading = true;
81-
var pnLoadedInterval = "";
82-
83-
var pubKey = (compatMode == true) ? keysets.keyset1.pub : keysets.keyset2.pub;
84-
var subKey = (compatMode == true) ? keysets.keyset1.sub : keysets.keyset2.sub;
85-
86106
loadPNLib();
87107

88-
var listener = "";
89-
var actor = "";
90-
91-
function waitForPNLoad() {
92-
if (pnLoading) {
93-
console.log("Waiting for PN to finish loading.");
94-
pnLoadedInterval = setInterval(waitForPNLoad, 1000);
95-
} else {
96-
console.log("Initializing listener and actor instances.");
97-
clearInterval(pnLoadedInterval);
98-
99-
listener = pnInit(ssl, subKey, true);
100-
actor = pnInit(ssl, subKey, false);
101-
102-
// Start the Listener. The actor will be spawned after the listener is connected.
103-
subToA(listener, actor);
104-
105-
106-
}
107-
}
108-
109108
function loadPNLib() {
110109
if (typeof PUBNUB === 'undefined') {
111110

@@ -155,29 +154,44 @@
155154
}
156155

157156

158-
function initLog(compat, ssl, key, extra_compat, origin) {
159-
console.log(key + "\nOrigin: " + origin + "\nClient level: " + clientLevel + "\nServer level: " + serverLevel + "\nCompat: " + compat + "\nClient extra compat flag: " + extra_compat + "\nSSL: " + ssl);
160-
}
157+
function waitForPNLoad() {
158+
if (pnLoading) {
159+
console.log("Waiting for PN to finish loading.");
160+
pnLoadedInterval = setInterval(waitForPNLoad, 1000);
161+
} else {
162+
console.log("Initializing listener and actor instances.");
163+
clearInterval(pnLoadedInterval);
164+
165+
randomSuffix = Math.floor((Math.random() * 10000) + 1);
166+
167+
actorUUID = actorUUID + randomSuffix;
168+
listenerUUID = listenerUUID + randomSuffix;
169+
170+
listener = pnInit(ssl, subKey, true);
171+
actor = pnInit(ssl, subKey, false);
172+
173+
// Start the Listener. The actor will be spawned after the listener is connected.
174+
subToA(listener, actor);
161175

162-
function pnInit(ssl, key, isListener, extra_compat) {
163176

164-
if (extra_compat == null) {
165-
extra_compat = false;
166177
}
178+
}
167179

168-
var uuid = isListener ? PN_LISTENER_UUID : PN_ACTOR_UUID;
180+
function pnInit(ssl, key, isListener) {
181+
182+
var uuid = isListener ? listenerUUID : actorUUID;
169183
var origin = (clientLevel == "3.6") ? "presence-beta.pubnub.com" : "pubsub.pubnub.com";
170184

171185
var pubnub = PUBNUB.init({
172186
publish_key: 'demo',
173187
subscribe_key: key,
174188
origin: origin,
175189
ssl: ssl,
176-
"compatible_3.5": extra_compat,
190+
"compatible_3.5": extraCompat,
177191
uuid: uuid
178192
});
179193

180-
initLog(true, ssl, key, extra_compat, origin);
194+
console.log(uuid + ": " + key + "\nOrigin: " + origin + "\nClient level: " + clientLevel + "\nServer level: " + serverLevel + "\nCompat: " + true + "\nClient extra compat flag: " + extraCompat + "\nSSL: " + ssl);
181195
return pubnub;
182196
}
183197

@@ -190,7 +204,7 @@
190204
console.log("Listener heard: " + m);
191205
},
192206
presence: function (msg, e, ch) {
193-
if (msg.uuid != PN_LISTENER_UUID && msg.uuid == PN_ACTOR_UUID) {
207+
if (msg.uuid != listenerUUID && msg.uuid == actorUUID) {
194208
console.log("Presence Listener: " + msg.action + " on " + msg.uuid + ": " + ch);
195209
}
196210

@@ -250,26 +264,5 @@
250264

251265
</script>
252266

253-
<style>
254-
div {
255-
margin-bottom: 10
256-
}
257-
</style>
258-
259-
<hr/>
260-
INIT
261-
<div onclick="pnInit(true,'sub-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe')">Compat On - SSL ON</div>
262-
<div onclick="pnInit(false,'sub-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe')">Compat On - SSL OFF</div>
263-
<hr/>
264-
<div onclick="compatOff(true, 'sub-c-d91ee366-9dbd-11e3-a759-02ee2ddab7fe')">Compat Off - SSL ON</div>
265-
<div onclick="compatOff(false, 'sub-c-d91ee366-9dbd-11e3-a759-02ee2ddab7fe')">Compat Off - SSL OFF</div>
266-
<hr/>
267-
Test Steps
268-
<div onclick="subToA()">Sub To A</div>
269-
<div onclick="subToB()">Sub To B</div>
270-
<div onclick="unsubToa()">UnSub To A</div>
271-
<hr>
272-
<div onclick="unsubTob()">UnSub To B</div>
273-
274267

275268
</html>

web/examples/presenceValidation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
// var pubnub = PUBNUB.init({
99
// publish_key: 'demo',
10-
// subscribe_key: 'sub-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe',
10+
// subscribe_key: 'subKey-c-d247d250-9dbd-11e3-8008-02ee2ddab7fe',
1111
// origin: "presence-beta.pubnub.com",
1212
// ssl: false
1313
// })

0 commit comments

Comments
 (0)