Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Outline

YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.


PubNub 3.5 Real-time Cloud Push API - JAVASCRIPT PHONE GAP

www.pubnub.com - PubNub Real-time Push Service in the Cloud.

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(){
    // ----------------------------------
    // PUBNUB
    // ----------------------------------
    var pubnub = PUBNUB({
        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>
    // ----------------------------------
    // PUBNUB
    // ----------------------------------
    var pubnub = PUBNUB({
        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>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.