Last active
August 29, 2015 14:06
-
-
Save olebedev/2697d98fd4677be74451 to your computer and use it in GitHub Desktop.
This file contains 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 app = app || { | |
id: "unique application instance id", | |
session_id: "unique session id", | |
render: function(){ | |
console.log("%c %s","font-size: 50px;color:yellow;", | |
"chat changed!"); | |
console.table(chat); | |
} | |
}; | |
// extend a Backbone.Collection | |
var SwarmChat = Swarm.Set.extend(Backbone.Collection); | |
// create a Swarm Host | |
app.host = new Swarm.Host(app.id+app.session_id); | |
// create a syncable Chat object | |
var chat = app.chat = new SwarmChat(app.id); | |
// initialize the collection | |
chat.on('.init', function(){/* do stuff */}); | |
// subscribe on changes | |
chat.on('set', app.render); | |
// connect to the WebSocket endpoint; | |
app.host.connect('ws://<your-app>.swarmix.io/v1/websocket'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment