forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmore-channels.js
More file actions
40 lines (35 loc) · 1.19 KB
/
Copy pathmore-channels.js
File metadata and controls
40 lines (35 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var test_channel_count = 1000;
var pubnub = require('./pnpool')( 30, {
publish_key : 'demo',
subscribe_key : 'demo'
} );
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Subscribe/Publish Many Channels
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
var channel_count = 0;
(new Array(test_channel_count)).join().split(',').forEach(function(_,a){
var channel = 'channel-'+(a+1);
// Subscribe
pubnub(channel).subscribe({
channel : channel,
message : message,
connect : function() {
console.log( 'connected to', ++channel_count, 'channels' );
setTimeout( function() {
// Send Message
pubnub(channel).publish({
channel : channel,
message : channel
});
}, 100 * a );
}
});
});
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Printing
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
var received = 0;
function message(result) {
received++;
console.log( received, 'RECEIVED!', result );
}