Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: CL-28753337751…

This branch is 16 commits ahead and 286 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Get your very own registration keys at http://www.pubnub.com/account

PubNub 3.3 Real-time Cloud Push API for Titanium

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 millions of web and mobile clients simultaneously.

API Usage Summary

API Usage summary follows. But checkout the real working examples in examples 3.3/mobile!

Init

Ti.include('pubnub.js');

var pubnub = PUBNUB.init({
    publish_key       : 'demo',
    subscribe_key     : 'demo',
    ssl               : false,
    native_tcp_socket : false,
    origin            : 'pubsub.pubnub.com'
});

If you run into firewall issues on some iPhone deployments, try to set native_tcp_socket to true.

Subscribe and Presence

For a given channel, subscribe to the channel (subscribe), or subscribe to the channel's join/leave events (presence)

pubnub.subscribe({
    channel  : "hello_world",
    callback : function(message) { Ti.API.log(message) }
})

Publish

Send messages to a channel.

pubnub.publish({
    channel : "hello_world",
    message : "Hi."
})

Message History ( history() is deprecated, please migrate your apps to use detailedHistory instead. )

Get the message history for a channel.

        var paramobj = {};
        paramobj['channel'] = channel.value;
        paramobj['callback'] = function(message) {
            append_data( JSON.stringify(message));
        }    
        paramobj.error = function() {
            append_data("Lost connection ... ","#f00");
        }
        if (start.value != "Start Timestamp" && start.value != "") 
            paramobj['start'] = start.value;
        if (end.value != "End Timestamp" && end.value != "") 
            paramobj['end'] = end.value;
        if (count.value != "Count" && count.value != "") 
            paramobj['count'] = count.value;
        else
            paramobj['count'] = 100;
        pubnub.detailedHistory(paramobj);

Here_now

Get real time occupancy stats for a channel. Used complimentarily with Presence

        pubnub.here_now({
            channel  : channel.value,
            connect  : function() {
                    append_data("Receiving Here Now data ...");
            },
            callback : function(message) {
                    append_data( JSON.stringify(message) );
            },
            error : function() {
                    append_data( "Lost Connection...", "#f00" );
            }
        });
Something went wrong with that request. Please try again.