Create a Simple Chat Room with PubNub
Example: Simple Messenger
Before looking at the full HTML chat, take a look at the code for this simple chat client out on Plnkr. PubNub calls itself an “Internet two-way radio with bidirectional JSON.” At least that’s what their catchy jingle says! You can see how simple it is to get started in the script file. You just call subscribe with a channel name and a callback function which the PubNub library code will call you back on for any new messages sent to that channel. To send, you simply call publish on a channel and pass a message object to it.
The Catch: MongoLab’s REST API Security (Lack of)
I’ll show the other code after I get it loaded in a more secure way. The problem is that the MongoLab REST API only supports user-account based API keys, not database-user-specific accounts. This isn’t very secure for data that is not mean to be public.
In the mean time, here’s a screen shot of the full app: