// N2O CORE var active = false, debug = false, session = "site-sid", protocol = window.location.protocol == 'https:' ? "wss://" : "ws://", querystring = window.location.pathname + window.location.search, host = window.location.hostname, port = window.location.hostname == 'localhost' ? window.location.port : transition.port; function N2O_start(){ ws = new bullet(protocol + host + (port == "" ? "" : ":" + port) + "/ws" + querystring); ws.onmessage = function(evt){ // formatters loop for(var i = 0;i < protos.length; i++){ p = protos[i]; if(p.on(evt, p.do).status == "ok") return; } }; ws.onopen = function(){ if(!active){ console.log('Connect'); ws.send('N2O,' + transition.pid); active = true; } }; ws.onclose = function(){ active = false; console.log('Disconnect'); }; next(); } function qi(name){ return document.getElementById(name); } function qs(name){ return document.querySelector(name); } function qa(name){ return document.querySelectorAll(name); } function qn(name){ return document.createElement(name); } function is(x, num, name){ return x == undefined ? false : (x.t == 106 ? false : (x.v.length === num && x.v[0].v === name)); } function co(name){ match = document.cookie.match(new RegExp(name + '=([^;]+)')); return match ? match[1] : undefined; } /// N2O Protocols var $io = {}; $io.on = function onio(r, cb){ if(is(r, 3, 'io')){ if(typeof cb == 'function') cb(r); var evalex = utf8_arr(r.v[1].v); try{ console.log("from n2o.js:46 \n", evalex); eval(evalex); return { status: "ok" }; }catch(e){ console.error("Eval failed: \n", e); return { status: '' }; } }else return { status: '' }; }; var $file = {}; $file.on = function onfile(r, cb){ //console.log('r ', r); //console.log('is ', is(r,13,'ftp')); if(is(r,13,'ftp')){ if(typeof cb == 'function') cb(r); return { status: "ok" }; }else return { status: ''}; }; var $bin = {}; $bin.on = function onbin(r, cb){ if(is(r,2,'bin')){ if(typeof cb == 'function') cb(r); return { status: "ok" }; }else return { status: '' }; }; // BERT Formatter var $bert = {}; $bert.protos = [$io, $bin, $file]; $bert.on = function onbert(evt, cb){ if(ArrayBuffer.prototype.isPrototypeOf(evt.data) && (evt.data.byteLength > 0)){ try{ var erlang = dec(evt.data); //console.log(JSON.stringify(erlang)); if(typeof cb == 'function') cb(erlang); for(var i = 0; i < $bert.protos.length; i++){ p = $bert.protos[i]; var ret = p.on(erlang, p.do); if(ret != undefined && ret.status == "ok") return ret; } }catch(e){ console.error(e); } return { status: "ok" }; }else return { status: "error", desc: "data" }; }; var protos = [ $bert ];