SelectSmartTV Storage & Playback API Reference for Realtime Apps

 

This SDK has been deprecated.

If you have questions about the PubNub for SmartTV SDK, please contact us at support@pubnub.com.

The PubNub Storage and Playback Service provides realtime access to history for all messages published to PubNub. Each published message is timestamped to the nearest 10 nanoseconds, and is stored across multiple availability zones in several geographical data center locations. Stored messages can be encrypted with AES-256 message encryption, ensuring that they are not readable while stored on PubNub's network.

Messages can be stored for a configurable duration or forever, as controlled by the retention policy that is configured on your account. The following options are available: 1 day, 7 days, 1 month, and Forever.


Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function fetches historical messages of a channel.
It is possible to control how messages are returned and in what order, for example you can:
  • Search for messages starting on the newest end of the timeline (default behavior - reverse = false)
  • Search for messages from the oldest end of the timeline by setting reverse to true.
  • Page through results by providing a start OR end time token.
  • Retrieve a slice of the time line by providing both a start AND end time token.
  • Limit the number of messages to a specific quantity using the count parameter.
 
Start & End parameter usage clarity:
If only the start parameter is specified (without end), you will receive messages that are older than and up to that start timetoken value.
If only the end parameter is specified (without start) you will receive messages that match that end timetoken value and newer.
Specifying values for both start and end parameters will return messages between those timetoken values (inclusive on the end value).
Keep in mind that you will still receive a maximum of 100 messages even if there are more messages that meet the timetoken values. Iterative calls to history adjusting the start timetoken is necessary to page through the full set of results if more than 100 messages meet the timetoken values.
To run History you can use the following method(s) in the SmartTV SDK
  1. ParameterTypeRequiredDescription
    callbackFunctionYesCallback that is called on success.
    channelStringYesSpecifies channel to return history messages from.
    countNumberOptionalSpecifies the number of historical messages to return.

    default/maximum is 100.
    endNumberOptionalTime token delimiting the end of time slice (inclusive) to pull messages from.
    startNumberOptionalTime token delimiting the start of time slice (exclusive) to pull messages from.
    reverseBooleanOptionalSetting to true will traverse the time line in reverse starting with the oldest message first. Default is false. If both start and end arguments are provided, reverse is ignored and messages are returned starting with the newest message.
    include_tokenBooleanOptionalIf true the message post timestamps will be included in the history response.

    default: false
    errorFunctionOptionalSpecify callback to call on error event.
Retrieve the last 100 messages on a channel:
pubnub.history({
    channel : 'history_channel',
    callback : function(m){
        console.log(JSON.stringify(m))
    },
    count : 100, // 100 is the default
    reverse : false // false is the default
});
The SmartTV SDK returns false on fail. An array is returned on success. The history() function returns a list of up to 100 messages, the time token of the first (oldest) message and the time token of the last (newest) message in the resulting set of messages. The output below demonstrates the format for a history() response:

[
	["message1", "message2", "message3",... ],
	"Start Time Token",
	"End Time Token"
]
  1. // get last 3 messages published to my_channel
    
    pubnub.history({
    	channel : 'my_channel',
    	count : '3',
    	reverse : true,
    	callback : function(history){
    		console.log(history)
    	}
    });
    
     [
    	["Pub1","Pub2","Pub3"],
    	13406746729185766,
    	13406746780720711
    ]
    
  2. // get messages starting at timetoken order oldest first
    
    pubnub.history({
    	channel : 'my_channel',
        start : '13406746780720711',
        reverse : true,
        callback : function(history){
    		console.log(history)
    	}
    });
    
     [
    	["Pub3","Pub4","Pub5"],
    	13406746780720711,
    	13406746845892666
    ]
    
  3. // return 100 messages ending on timetoken
    
    pubnub.history({
        channel : 'my_channel',
        end : '13406746780720711',
        callback : function(history){
    		console.log(history)
    	}
    });
    
    [
    	["Pub3","Pub4","Pub5"],
    	13406746780720711,
    	13406746845892666
    ]
    
  4.  
    Usage!
    You can call the method by passing 0 or a valid time token as the argument.
    getAllMessages = function(timetoken) {
    	pubnub.history({
    		start : timetoken,
    		channel : 'history_test',
    		callback : function(payload) {
    			var msgs = payload[0];
    			var start = payload[1];
    			var end = payload[2];
    			// if msgs were retrieved, do something useful with them
    			if (msgs != undefined && msgs.length > 0) {
    				console.log(msgs.length);
    				console.log("start : " + start);
    				console.log("end : " + end);
    			}
    			// if 100 msgs were retrieved, there might be more; call history again
    			if (msgs.length == 100)
    				getAllMessages(start);
    		}
    	});
    }
     
    //Usage examples:
    //getAllMessages();
    //getAllMessages(null);
    //getAllMessages(14264873967138188);