forked from pubnub/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmx-bug-fix-test.html
More file actions
78 lines (69 loc) · 2.08 KB
/
mx-bug-fix-test.html
File metadata and controls
78 lines (69 loc) · 2.08 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!doctype html>
<html>
<head>
<!-- Hey, let's be friends! twitter.com/pubnub -->
<title>PubNub JavaScript Multiplexing Test</title>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
<style type=text/css>
#stop-test,
#finished-fail,
#finished-success,
.tpl {display:none}
</style>
</head>
<body><div class=container>
<div id=out>...</div>
<div id=pubnub></div>
<script src=../pubnub.min.js></script>
<script>(function(){
// --------------------------------
// Testing Examples
// --------------------------------
var pubnub = window.pubnub = PUBNUB.init({
subscribe_key : 'demo',
publish_key : 'demo',
origin : 'pubsub.pubnub.com'
});
// --------------------------------
// Subscribe Usage Style Examples
// --------------------------------
subscribe( 'cn', function() {
subscribe( 'b', function() {
publish( 'cn', function() {
publish( 'b', function() {
setTimeout( function() {
unsubscribe('b');
setTimeout( function() {
publish('cn');
publish('b');
}, 2000 );
}, 1000 );
} );
} );
} );
});
// --------------------------------
// Full Sub/UnSub Functions
// --------------------------------
function unsubscribe(channel) { pubnub.unsubscribe({
channel : channel
}); log("UNSUB: " + channel); }
function subscribe(channel,cb) { pubnub.subscribe({
channel : channel,
connect : function() {(cb||function(){})() },
message : function( message, envelope, channel ) {
log('RECIEVED "' + channel + '": ' + JSON.stringify(message));
}
}); log("SUB: " + channel); }
function publish( channel, cb ) { pubnub.publish({
channel : channel,
message : "HI-" + channel,
callback : cb
}); log("PUB: " + channel); }
function log(data) {
console.log(data);
PUBNUB.$('out').innerHTML += "<div>"+data+"</div>";
}
})();</script>
</div></body>
</html>