config.json
{"description":"FSS canvas + LEAP","endpoint":"","display":"div","public":true,"require":[{"name":"fss","url":"https://raw.github.com/wagerfield/flat-surface-shader/master/deploy/fss.min.js"}],"fileconfigs":{"inlet.js":{"default":true,"vim":false,"emacs":false,"fontSize":12},"_.md":{"default":true,"vim":false,"emacs":false,"fontSize":12},"config.json":{"default":true,"vim":false,"emacs":false,"fontSize":12},"index.html":{"default":true,"vim":false,"emacs":false,"fontSize":12},"leap.js":{"default":true,"vim":false,"emacs":false,"fontSize":12}},"fullscreen":false,"play":true,"loop":false,"restart":false,"autoinit":true,"pause":true,"loop_type":"period","bv":false,"nclones":15,"clone_opacity":0.4,"duration":3000,"ease":"linear","dt":0.01,"thumbnail":"http://i.imgur.com/ZWMMd4k.png"}
leap.js
tributary.leap = {
events: _.clone(Backbone.Events)
};
if ((typeof(WebSocket) == 'undefined') &&
(typeof(MozWebSocket) != 'undefined')) {
WebSocket = MozWebSocket;
}
tributary.leap.init = function() {
if(tributary.ws) {
tributary.ws.close();
}
console.log("Starting");
tributary.ws = new WebSocket("ws://localhost:6437/");
var ws = tributary.ws;
ws.onopen = function(event) {
console.log("Open");
tributary.leap.connected = true;
tributary.leap.events.trigger("open");
};
ws.onmessage = function(event) {
tributary.leap.events.trigger("frame", JSON.parse(event.data));
};
ws.onclose = function(event) {
ws = null;
tributary.leap.connected = false;
tributary.leap.events.trigger("close");
}
ws.onerror = function(event) {
console.error("Received error");
};
}
var socketState;
if(!tributary.ws || tributary.ws.readyState != 1) {
tributary.leap.connected = false;
} else {
tributary.leap.connected = true;
}
tributary.leap.toggle = function() {
if(tributary.ws.readyState === 1) {
tributary.ws.close();
} else {
tributary.leap.init();
}
}
tributary.leap.init();
tributary.events.on("restart", function() {
tributary.leap.init();
})