Created
September 23, 2011 17:06
-
-
Save edstenson/1237903 to your computer and use it in GitHub Desktop.
Websockets example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var ws = new WebSocket('ws://websocket.datasift.com/<hash>?username=<username>&api_key=<api_key>'); | |
| ws.onopen = function(evt) { | |
| // connection event | |
| } | |
| ws.onmessage = function(evt) { | |
| // parse received message | |
| console.log(evt.data); | |
| } | |
| ws.onclose = function(evt) { | |
| // parse event | |
| } | |
| // No event object is passed to the event callback, so no useful debugging can be done | |
| ws.onerror = function() { | |
| // Some error occurred | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
{"status": "failure", "message": "Something goes here"} {"status": "warning", "message": "Something goes here"} {"status": "info", "message": "Something goes here"} {"status": "success", "message": "Something goes here"}For the above messages, there may also be an unlimited number of arbitrary keys e.g.:
{"status": "warning", "message": "Something goes here", "foo": "bar"}On initial connection, we send a tick with a status of "initialised":
{"tick": 1234567890, "status": "initialised", "message": "Waiting for data"}Then if there is no data for 30 seconds, we send another tick, but with a status of "connected"
{"tick": 1234567890, "status": "connected", "message": "Waiting for data"}Finally, we also send normal interactions, new line delimited