Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: CL-30155684478…

This branch is 0 commits ahead and 214 commits behind master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

..
Octocat-spinner-32 README
Octocat-spinner-32 index.html
Octocat-spinner-32 pubnub-3.1.js
Octocat-spinner-32 pubnub.js
Octocat-spinner-32 pubnub.min.js
README
## ---------------------------------------------------
##
## YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
## http://www.pubnub.com/account
##
## USE "DEMO" INCLUDES (BELOW) FREE! WHILE DEVELOPING
##
## ----------------------------------------------------

## ------------------------------------------------------
## PubNub 3.1 Real-time Cloud Push API - JAVASCRIPT webOS
## ------------------------------------------------------
##
## www.pubnub.com - PubNub Real-time Push Service in the Cloud. 
## http://www.pubnub.com/tutorial/javascript-push-api
##
## PubNub is a Massively Scalable Real-time Service for Web and Mobile Games.
## This is a cloud-based service for broadcasting Real-time messages
## to thousands of web and mobile clients simultaneously.

<!-- ============================= -->
<!-- INCLUDE SCRIPT PREFERED STYLE -->
<!-- ============================= -->
<script src=pubnub.min.js></script>
<script>(function(){
    // ----------------------------------
    // INIT PUBNUB
    // ----------------------------------
    var pubnub = PUBNUB.init({
        publish_key   : 'demo',
        subscribe_key : 'demo',
        ssl           : false,
        origin        : 'pubsub.pubnub.com'
    });

    // ----------------------------------
    // LISTEN FOR MESSAGES
    // ----------------------------------
    pubnub.subscribe({
        channel  : 'test',
        callback : function(message) {
            console.log(JSON.stringify(message));
        },
        error : function() {
            // The internet is gone.
            console.log("Connection Lost");
        }
    });

    // ----------------------------------
    // SEND MESSAGE
    // ----------------------------------
    setInterval( function() {
        pubnub.publish({
            channel  : 'test',
            message  : { example : "Hello World!" },
            callback : function(info) {
                if (info[0])
                    console.log("Successfully Sent Message!");
                else
                    // The internet is gone.
                    console.log("Failed! -> " + info[1]);
            }
        });
    }, 1000 );
})();</script>

<!-- ============================= -->
<!-- SIMPLE EXAMPLE USE PUBNUB API -->
<!-- ============================= -->
<script>
    // ----------------------------------
    // INIT PUBNUB
    // ----------------------------------
    var pubnub = PUBNUB.init({
        publish_key   : 'demo',
        subscribe_key : 'demo',
        ssl           : false,
        origin        : 'pubsub.pubnub.com'
    });


    // -------------------
    // LISTEN FOR MESSAGES
    // -------------------
    pubnub.subscribe({
        channel  : "hello_world",
        callback : function(message) { alert(message) }
    })

    // ------------
    // SEND MESSAGE
    // ------------
    pubnub.publish({
        channel : "hello_world",
        message : "Hi."
    })

</script>
Something went wrong with that request. Please try again.