Skip to content

Instantly share code, notes, and snippets.

@olebedev
Last active August 29, 2015 14:06
Show Gist options
  • Save olebedev/2697d98fd4677be74451 to your computer and use it in GitHub Desktop.
Save olebedev/2697d98fd4677be74451 to your computer and use it in GitHub Desktop.
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