Skip to content

Instantly share code, notes, and snippets.

@gritzko
Created July 6, 2014 14:14
Show Gist options
  • Save gritzko/d0395a57853d4ce098a8 to your computer and use it in GitHub Desktop.
Save gritzko/d0395a57853d4ce098a8 to your computer and use it in GitHub Desktop.
var app = app || {};
(function () {
'use strict';
// print every op to the console
Swarm.debug = true;
// ...
// compose a WebSocket URI to connect back to the server;
// 'ws:' URIs are served by WSStream
app.wsServerUri = 'ws://'+window.location.host;
// create a Host (no cache, no storage)
app.host = Swarm.localhost = new Swarm.Host(app.id+app.session_id);
// ...
// create a Mouse object
var mickey = app.mouse = new Mouse(app.id);
mickey.on('.init',function(){
if (this._version!=='!0') return; // FIXME default values
mickey.set({
x:100+(0|(Math.random()*100)),
y:100+(0|(Math.random()*100)),
symbol: String.fromCharCode(10000+ssnInt%60) // dingbats
});
})
// open #mice, list our object in the collection
app.mice = app.host.get('/Mice#mice', function(){
app.mice.addObject(mickey);
});
// connect to the server
app.host.connect(app.wsServerUri);
// ...
window.onbeforeunload = function(e) {
// going to sleep, remove mickey from the list
app.mice.removeObject(mickey);
app.host.close(); // zzz
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment