Created
July 6, 2014 14:14
-
-
Save gritzko/d0395a57853d4ce098a8 to your computer and use it in GitHub Desktop.
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 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