{"_id":"555fc09928249c1900618a91","__v":6,"version":{"_id":"555f9bf814d68e0d0096658a","project":"555f9bf814d68e0d00966587","__v":9,"createdAt":"2015-05-22T21:13:28.470Z","releaseDate":"2015-05-22T21:13:28.470Z","categories":["555f9bf814d68e0d0096658b","555f9e9ed7777119003acfee","555fa040d7777119003acffd","555fa344d7777119003ad00b","555fa3e6d7777119003ad00f","555fb694336c041700a9b86e","555fb779336c041700a9b86f","555fb86bd7777119003ad039","555fbf1a336c041700a9b87f"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"category":{"_id":"555fbf1a336c041700a9b87f","pages":["555fc09928249c1900618a91","556b7dbe9d4bb723007caa48"],"project":"555f9bf814d68e0d00966587","version":"555f9bf814d68e0d0096658a","__v":2,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-05-22T23:43:22.085Z","from_sync":false,"order":4,"slug":"connectors","title":"Connectors"},"project":"555f9bf814d68e0d00966587","parentDoc":null,"user":"555f9a010758330d000d531a","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-22T23:49:45.210Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:embed]\n{\n \"html\": \"<iframe class=\\\"embedly-embed\\\" src=\\\"//cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fjsfiddle.net%2FL60eq6eg%2F&src=%2F%2Fjsfiddle.net%2FL60eq6eg%2Fembedded%2F&type=text%2Fhtml&key=02466f963b9b4bb8845a05b53d3235d7&schema=jsfiddle\\\" width=\\\"None\\\" height=\\\"300\\\" scrolling=\\\"no\\\" frameborder=\\\"0\\\" allowfullscreen></iframe>\",\n \"url\": \"http://jsfiddle.net/L60eq6eg/\",\n \"title\": \"Edit fiddle - JSFiddle\",\n \"favicon\": \"http://jsfiddle.net/favicon.png\"\n}\n[/block]\nThe WebSocket connector allows for easy receiving of push messages. The server will send two types of messages: `message` and `subscription`. The message object will contain a single message. The subscription object indicates that the subscriptions have changed. This can be because the user has subscribed or unsubscribed from a service or a service has been deleted. The subscription object should be compared to the local subscription cache to test if the subscription was added or removed. \n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"subscriptions = get_subscriptions()\\nfor notification in lazy_receive():\\n if 'message' in notification:\\n handle_message(notification)\\n else:\\n service = notification['subscription']['service']\\n try:\\n index = next(i for i in range(len(subscriptions)) \\n if subscriptions[i]['public'] == service['public'])\\n del subscriptions[index]\\n except StopIteration:\\n subscriptions.append(service)\",\n \"language\": \"python\"\n }\n ]\n}\n[/block]","excerpt":"","slug":"websocket","type":"basic","title":"WebSocket"}

Connectors

GCM

WebSocket

[block:embed]
{
"html": "<iframe class=\"embedly-embed\" src=\"//cdn.embedly.com/widgets/media.html?url=http%3A%2F%2Fjsfiddle.net%2FL60eq6eg%2F&src=%2F%2Fjsfiddle.net%2FL60eq6eg%2Fembedded%2F&type=text%2Fhtml&key=02466f963b9b4bb8845a05b53d3235d7&schema=jsfiddle\" width=\"None\" height=\"300\" scrolling=\"no\" frameborder=\"0\" allowfullscreen></iframe>",
"url": "http://jsfiddle.net/L60eq6eg/",
"title": "Edit fiddle - JSFiddle",
"favicon": "http://jsfiddle.net/favicon.png"
}
[/block]
The WebSocket connector allows for easy receiving of push messages. The server will send two types of messages: `message` and `subscription`. The message object will contain a single message. The subscription object indicates that the subscriptions have changed. This can be because the user has subscribed or unsubscribed from a service or a service has been deleted. The subscription object should be compared to the local subscription cache to test if the subscription was added or removed.
[block:code]
{
"codes": [
{
"code": "subscriptions = get_subscriptions()\nfor notification in lazy_receive():\n if 'message' in notification:\n handle_message(notification)\n else:\n service = notification['subscription']['service']\n try:\n index = next(i for i in range(len(subscriptions)) \n if subscriptions[i]['public'] == service['public'])\n del subscriptions[index]\n except StopIteration:\n subscriptions.append(service)",
"language": "python"
}
]
}
[/block]