Skip to content

Commit 38e46c7

Browse files
author
Devendra
committed
Merge branch 'master' into develop
2 parents 8536ab3 + 7c5eb22 commit 38e46c7

File tree

6 files changed

+212
-8
lines changed

6 files changed

+212
-8
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
1+
# Please direct all Support Questions and Concerns to [email protected]
2+
3+
###### YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
24
Create an account at http://www.pubnub.com/account
35

46
## The PubNub Network JavaScript Real-time SDK v3.6.1
@@ -1027,3 +1029,5 @@ And a bit more detail on how it all fits together:
10271029
3. First mocha tests are run. If they succeed...
10281030
4. Jenkins creates a job on testswarm to execute qunit tests across various browsers. Cross-browser testing is done via BrowserStack. A script runs on the server which keeps querying testswarm for the swarm state . The state defines which browsers are required by swarm. This script then spawns those browsers on BrowserStack. The browsers not required any more are killed. This way whenever a job is submitted, the script will start browsres and kill them once done.
10291031
5. The job creation script keeps polling swarm for test results. If the results indicate success, the build status is set as passed... if the tests indicate failure, build status is set as failure, and mail is sent to PubNub support for further investigation.
1032+
1033+
# Please direct all Support Questions and Concerns to [email protected]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>PubNub Clock Sync Drift Detection</title>
5+
<style>
6+
#latency {
7+
font-size: 30px;
8+
font-family: "Helvetica Neue";
9+
font-weight: 200;
10+
color: #eeeee2;
11+
background: #444;
12+
padding: 10px;
13+
border-radius: 500px;
14+
text-align: center;
15+
16+
-webkit-transition: all 0.1s;
17+
-moz-transition: all 0.1s;
18+
-ms-transition: all 0.1s;
19+
-o-transition: all 0.1s;
20+
transition: all 0.1s;
21+
}
22+
h1 {
23+
font-family: "Helvetica Neue";
24+
text-align: center;
25+
font-weight: 100;
26+
}
27+
</style>
28+
</head>
29+
<body>
30+
31+
<!-- Clock Drift -->
32+
<h1>PubNub Clock Sync Drift Detection</h1>
33+
<div id=latency>40</div>
34+
<div id=pubnub></div>
35+
<h3>Checking drift once per second.</h3>
36+
37+
38+
<script src="https://cdn.pubnub.com/pubnub.min.js"></script>
39+
<script>(function(){
40+
41+
// Drift Functions
42+
function now(){ return+new Date }
43+
function clock_drift(cb) {
44+
clock_drift.start = now();
45+
PUBNUB.time(function(timetoken){
46+
var latency = (now() - clock_drift.start) / 2
47+
, server_time = (timetoken / 10000) + latency
48+
, local_time = now()
49+
, drift = local_time - server_time;
50+
51+
cb(drift);
52+
});
53+
54+
if (clock_drift.ival) return;
55+
clock_drift.ival = setInterval( function(){clock_drift(cb)}, 1000 );
56+
}
57+
58+
// This is how you use the code
59+
// Periodically Get Latency in Miliseconds
60+
clock_drift(function(latency){
61+
var out = PUBNUB.$('latency');
62+
out.innerHTML = "Clock Drift Delta: " + latency + "ms";
63+
64+
// Flash Update
65+
PUBNUB.css( out, { background : latency > 2000 ? '#f32' : '#5b5' } );
66+
setTimeout( function() {
67+
PUBNUB.css( out, { background : '#444' } );
68+
}, 300 );
69+
});
70+
71+
72+
})();</script>
73+
</body>
74+
</html>
75+

node.js/tests/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# PubNub Pool for Many Channels
2+
3+
The pool manager will allow you to subscribe to more
4+
channels than the maximum recommended.
5+
6+
```javascript
7+
// Init
8+
var pubnub = require('./pnpool')( 25, {
9+
publish_key : 'demo',
10+
subscribe_key : 'demo'
11+
} );
12+
13+
// Subscribe to Many Channels
14+
pubnub(channel).subscribe({
15+
channel : channel,
16+
message : function(msg) { console.log(msg },
17+
});
18+
19+
// Send Message
20+
pubnub(channel).publish({
21+
channel : channel,
22+
message : channel
23+
});
24+
25+
```

node.js/tests/more-channels.js

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
var test_channel_count = 500;
2+
var pubnub = require('./pnpool')( 25, {
3+
publish_key : 'demo',
4+
subscribe_key : 'demo'
5+
} );
6+
7+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
8+
// Subscribe/Publish Many Channels
9+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
10+
(new Array(test_channel_count)).join().split(',').forEach(function(_,a){
11+
var channel = 'channel-'+(a+1);
12+
13+
// Subscribe
14+
pubnub(channel).subscribe({
15+
channel : channel,
16+
message : message,
17+
connect : function() {
18+
setTimeout( function() {
19+
20+
// Send Message
21+
pubnub(channel).publish({
22+
channel : channel,
23+
message : channel
24+
});
25+
26+
}, 100 * a );
27+
}
28+
});
29+
});
30+
31+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
32+
// Printing
33+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
34+
var received = 0;
35+
function message(result) {
36+
received++;
37+
console.log( received, 'RECEIVED!', result );
38+
}

node.js/tests/pnpool.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
var PUBNUB = require('../pubnub.js')
2+
var CHANNELS = {};
3+
var currentpn = null;
4+
var totalpn = 0;
5+
var setup = {};
6+
var countpn = 0;
7+
var grouppn = 0; // Channels Per PN Instance
8+
var received = 0;
9+
10+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
11+
// PubNub Pooling Creator
12+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
13+
module.exports = function( pool_size, settings ) {
14+
setup = settings;
15+
grouppn = pool_size;
16+
17+
return get_pubnub;
18+
};
19+
20+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
21+
// PubNub Pooling
22+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
23+
function get_pubnub(channel) {
24+
if (channel in CHANNELS) return CHANNELS[channel];
25+
26+
// Create a new PN Instance
27+
if (!(countpn++ % grouppn)) {
28+
var settings = clone(setup);
29+
settings.origin = uuid().split('-')[4] + '.pubnub.com';
30+
settings.total = totalpn++;
31+
currentpn = PUBNUB.init(settings);
32+
}
33+
34+
// console.log( 'countpn', countpn, 'totalpn', totalpn );
35+
36+
// Save PN Instance
37+
CHANNELS[channel] = currentpn;
38+
return CHANNELS[channel];
39+
}
40+
41+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
42+
// UUID
43+
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
44+
function uuid(callback) {
45+
var u = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
46+
function(c) {
47+
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
48+
return v.toString(16);
49+
});
50+
if (callback) callback(u);
51+
return u;
52+
}
53+
function clone(a) {
54+
return JSON.parse(JSON.stringify(a));
55+
}

node.js/tests/publish-test.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
var pubnub = require('../pubnub.js').init({})
22

33
function error(result) {
4-
console.log( 'Error with', result }
4+
console.log( 'Error with', result )
5+
}
56

67
console.log('Publishing... Waiting for Result!\n')
78

8-
pubnub.publish({
9-
channel : 'bbq',
10-
message : { 'hah?' : 'lol' },
11-
callback : function(result){ console.log(result) },
12-
error : error
13-
})
9+
pub({ 'hah' : 'lol' });
10+
pub({ 'hah?' : 'lol' });
11+
12+
function pub(msg) {
13+
pubnub.publish({
14+
channel : 'bbq',
15+
message : msg,
16+
callback : function(result){ console.log(result) },
17+
error : error
18+
})
19+
}
20+

0 commit comments

Comments
 (0)