Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 99 lines (88 sloc) 3.105 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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
<!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(['chan1','chan2','chan3']); // ARRAY
subscribe('chan4,chan6,chan7'); // LIST
subscribe('chan8'); // ONE AT A TIME
subscribe('chan9'); // ONE AT A TIME

// --------------------------------
// UnSubscribe Usage Style Examples
// --------------------------------
unsubscribe(['chan1','chan2','chan3']); // ARRAY
unsubscribe('chan4,chan6,chan7'); // LIST
unsubscribe('chan8'); // ONE AT A TIME
unsubscribe('chan9'); // ONE AT A TIME

// --------------------------------
// Change Subscribe Anytime Later
// --------------------------------
setTimeout( function(){ subscribe('m') }, 4000 );
setTimeout( function(){ unsubscribe('a') }, 6000 );
setTimeout( function(){ unsubscribe('b') }, 8000 );

// --------------------------------
// Testing Examples
// --------------------------------
subscribe(['h','j','i','k']); // Will Subscribe in ORDER
subscribe('g,e,d,f'); // Will Subscribe in ORDER
subscribe('a,g,e,d,f'); // Will Subscribe in ORDER
subscribe('a');
subscribe('c');
subscribe('b');
subscribe('d'); // Okay Duplicate Subscribe
subscribe('d'); // Okay Duplicate Subscribe
unsubscribe('d');
subscribe('d'); // Okay Duplicate Subscribe
subscribe('d'); // Okay Duplicate Subscribe
unsubscribe('f');
subscribe('x');

// --------------------------------
// Full Sub/UnSub Functions
// --------------------------------
function unsubscribe(channel) { pubnub.unsubscribe({
    channel : channel
}) }

function subscribe(channel) { pubnub.subscribe({
    channel : channel,
    restore : true,
    connect : function() { log('NETWORK CONNECTED!!!') },
    disconnect : function() { log('NETWORK DISCONNECTED!!!') },
    reconnect : function() { log('NETWORK RECONNECTED!!!') },
    presence : function( message, envelope, channel ) {
        log('PRESENCE ON "' + channel + '": ' + JSON.stringify(message));
    },
    message : function( message, envelope, channel ) {
        log('CHANNEL "' + channel + '": ' + JSON.stringify(message));
    }
}) }

function log(data) {
    console.log(data);
    PUBNUB.$('out').innerHTML += "<div>"+data+"</div>";
}

})();</script>
</div></body>
</html>
Something went wrong with that request. Please try again.