Free up to 1MM monthly messages. No credit card required.
In this tutorial, we’ll build off the previous example and add history (also know as Storage & Playback), so our previous doodles are saved and displayed when the page is reloaded.
You’ll notice clear difference, besides the background color- in the new demo, you see previously drawn canvas, while the previous demo starts with a brand-new canvas.
You’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Portal. Once you have, clone the GitHub repository, and enter your unique PubNub keys on the PubNub initialization, for example:
You can easily retrieve last drawing data using
history() API. This function fetches historical messages of a channel. This Storage & Playback feature provides real-time access to a history for all messages published to PubNub.
To simply retrieve last 100 messages, this is all you need to do:
history() returns a list of up to 100 messages, the start time token and the ending time token. The response from
history() looks like:
[['message1', 'message2', 'message3',... ],'Start Time Token', 'End Time Token']
Let’s add this feature to your canvas app. With the API, make the app to automatically display the 50 previously drawn strokes on canvas. Before you start, you need to enable the feature on your admin dashboard (this is why you’ll first need to sign up for a PubNub account).
Once you call the history function, at the success call back, call the function
drawFromStream, created at the previous HTML5 canvas tutorial.
Boom. Now, at the initial load, you get old drawings from strangers! If you would like, the entire HTML5 canvas source code of the demo is on GitHub.
A roundtable discussion led by PubNub’s COO, Casey Clegg, exploring the topics of what it means to be human in a virtual world.
Dr. Joe Kvedar, Chair of the Board for the American Telemedicine Association, joins our COO, Casey Clegg, to discuss why...
Today, we are glad to announce that we are currently in the process of implementing ISO-27001 security standards.