|
| 1 | +<!doctype html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <!-- Hey, let's be friends! twitter.com/pubnub --> |
| 5 | + <title>PubNub JavaScript HERE NOW Test</title> |
| 6 | + <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet"> |
| 7 | + <style type=text/css> |
| 8 | + #stop-test, |
| 9 | + #finished-fail, |
| 10 | + #finished-success, |
| 11 | + .tpl {display:none} |
| 12 | + </style> |
| 13 | +</head> |
| 14 | +<body><div class=container> |
| 15 | + |
| 16 | +<div id=out>...</div> |
| 17 | + |
| 18 | +<div id=pubnub></div> |
| 19 | +<script src=../pubnub.min.js></script> |
| 20 | +<script>(function(){ |
| 21 | + |
| 22 | +// -------------------------------- |
| 23 | +// Testing Examples |
| 24 | +// -------------------------------- |
| 25 | +var pubnub = window.pubnub = PUBNUB.init({ |
| 26 | + subscribe_key : 'demo', |
| 27 | + publish_key : 'demo', |
| 28 | + origin : 'pubsub.pubnub.com' |
| 29 | +}); |
| 30 | + |
| 31 | +// -------------------------------- |
| 32 | +// Channels and Shards |
| 33 | +// -------------------------------- |
| 34 | +var shards = { |
| 35 | + 'a': 'hello8', |
| 36 | + 'c': 'hello2', |
| 37 | + 'b': 'hello19', |
| 38 | + 'e': 'hello4', |
| 39 | + 'd': 'hello13', |
| 40 | + 'f': 'hello14', |
| 41 | + '1': 'hello20', |
| 42 | + '3': 'hello7', |
| 43 | + '2': 'hello15', |
| 44 | + '5': 'hello1', |
| 45 | + '4': 'hello16', |
| 46 | + '7': 'hello0', |
| 47 | + '6': 'hello10', |
| 48 | + '9': 'hello3', |
| 49 | + '8': 'hello9' |
| 50 | +}; |
| 51 | + |
| 52 | +var chans = []; |
| 53 | +PUBNUB.each( shards, function( shard, channel ) { |
| 54 | + chans.push(channel); |
| 55 | +} ); |
| 56 | + |
| 57 | +pubnub.subscribe({ |
| 58 | + channel : chans, |
| 59 | + message : function(){}, |
| 60 | + connect : function() { } |
| 61 | +}) |
| 62 | + |
| 63 | +log(["loading, please wait..."]); |
| 64 | +setTimeout( function() { |
| 65 | + PUBNUB.each( shards, function( shard, channel ) { |
| 66 | + pubnub.here_now({ channel : channel, callback : function(data) { |
| 67 | + log([ |
| 68 | + data.occupancy > 1 ? "PASS! (hurray!)" : "FAIL! (BAD)", |
| 69 | + " channel: " + channel, |
| 70 | + " shard: " + shard, |
| 71 | + " occupancy: " + data.occupancy |
| 72 | + ]); |
| 73 | + } }); |
| 74 | + } ); |
| 75 | +}, 4000 ); |
| 76 | + |
| 77 | +// -------------------------------- |
| 78 | +// UnSubscribe Usage Style Examples |
| 79 | +// -------------------------------- |
| 80 | + |
| 81 | +function log(data) { |
| 82 | + console.log(data); |
| 83 | + PUBNUB.$('out').innerHTML += "<div>"+data+"</div>"; |
| 84 | +} |
| 85 | + |
| 86 | +})();</script> |
| 87 | +</div></body> |
| 88 | +</html> |
0 commit comments