Namdak Tonpa 6 лет назад
Родитель
Сommit
a5b080b297

+ 1 - 1
include/mad.hrl

@@ -1 +1 @@
--define(VERSION,"777f6e").
+-define(VERSION,"5.4-14-g7810b8d").


+ 8 - 8
priv/mqtt/priv/static/index.htm

@@ -4,7 +4,7 @@
     <meta charset="utf-8">
     <meta http-equiv="x-ua-compatible" content="ie=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href='synrc.css?v=210' type='text/css' rel='stylesheet'>
+    <link href='synrc.css' type='text/css' rel='stylesheet'>
     <title>Chat</title>
 </head>
 
@@ -25,14 +25,14 @@
 
     </main>
     <script src="//cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js"></script>
-    <script src='/n2o/utf8.js?v=11'></script>
-    <script src='/n2o/bert.js?v=11'></script>
-    <script src='/n2o/ieee754.js?v=11'></script>
-    <script src='/n2o/n2o.js?v=11'></script>
+    <script src='https://ws.n2o.space/priv/utf8.js'></script>
+    <script src='https://ws.n2o.space/priv/bert.js'></script>
+    <script src='https://ws.n2o.space/priv/ieee754.js'></script>
+    <script src='https://ws.n2o.space/priv/n2o.js'></script>
     <script>host = location.hostname === 'review.n2o.space' ? 'ns.synrc.com' : location.hostname; port = 8000;</script>
-    <script src='/n2o/ftp.js?v=10'></script>
-    <script src='/n2o/nitro.js?v=10'></script>
-    <script src='/n2o/mq.js?v=10'></script>
+    <script src='https://ws.n2o.space/priv/ftp.js'></script>
+    <script src='https://ws.n2o.space/priv/nitro.js'></script>
+    <script src='https://ws.n2o.space/priv/mq.js'></script>
 </body>
 
 </html>

+ 8 - 8
priv/mqtt/priv/static/login.htm

@@ -4,7 +4,7 @@
     <meta charset="utf-8">
     <meta http-equiv="x-ua-compatible" content="ie=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href='synrc.css?v=103' type='text/css' rel='stylesheet'>
+    <link href='synrc.css' type='text/css' rel='stylesheet'>
     <title>Login</title>
 </head>
 
@@ -22,14 +22,14 @@
     </form>
     <footer>Brought to you with ♡ by N2O developers.</footer>
     <script src="//cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.1/mqttws31.js"></script>
-    <script src='/n2o/utf8.js?v=11'></script>
-    <script src='/n2o/bert.js?v=11'></script>
-    <script src='/n2o/ieee754.js?v=11'></script>
-    <script src='/n2o/n2o.js?v=11'></script>
+    <script src='https://ws.n2o.space/priv/utf8.js'></script>
+    <script src='https://ws.n2o.space/priv/bert.js'></script>
+    <script src='https://ws.n2o.space/priv/ieee754.js'></script>
+    <script src='https://ws.n2o.space/priv/n2o.js'></script>
     <script>host = location.hostname === 'review.n2o.space' ? 'ns.synrc.com' : location.hostname; port = 8000;</script>
-    <script src='/n2o/ftp.js?v=11'></script>
-    <script src='/n2o/nitro.js?v=11'></script>
-    <script src='/n2o/mq.js?v=11'></script>
+    <script src='https://ws.n2o.space/priv/ftp.js'></script>
+    <script src='https://ws.n2o.space/priv/nitro.js'></script>
+    <script src='https://ws.n2o.space/priv/mq.js'></script>
     <script> qi('pass').value = module == "login" ? "" : module; </script>
 </body>
 

+ 0 - 158
priv/mqtt/priv/static/n2o/bert.js

@@ -1,158 +0,0 @@
-
-// API
-
-function tuple() { return { t: 104, v: Array.apply(null, arguments) }; }
-function list() { return { t: 108, v: Array.apply(null, arguments) }; }
-function map() { return { t: 116, v: Array.apply(null, arguments) }; }
-function atom(o) { return { t: 100, v: utf8_enc(o) }; }
-function string(o) { return { t: 107, v: utf8_enc(o) }; }
-function float(o) { return { t: 70, v: o }; }
-function number(o) {
-  var s, isInteger = (o % 1 === 0);
-  if (isInteger && o >= 0 && o < 256) { return { t: 97, v: o };  }
-  if (isInteger && o >= -134217728 && o <= 134217727) { return {t: 98, v: o}; }
-  return {t: 110, v: o}; }
-function bin(o) {
-  return { t: 109, v: o instanceof ArrayBuffer ? new Uint8Array(o) :
-                      o instanceof Uint8Array  ? o : utf8_enc(o) }; }
-
-// ENCODER
-
-function enc(o) { return fl([131, ein(o)]); }
-function ein(o) { return Array.isArray(o) ? en_108({ t: 108, v: o }) : eval('en_' + o.t)(o); }
-function en_undefined(o) { return [106]; }
-function en_70(o) {
-  var x = Array(8).fill(0).flat();
-  write_Float(x,o.v,0,false,52,8);
-  return [70].concat(x);
-}
-function en_97(o) { return [97, o.v]; }
-function en_98(o) { return [98, o.v >>> 24, (o.v >>> 16) & 255, (o.v >>> 8) & 255, o.v & 255]; }
-function en_99(o) {
-  var obj = o.v.toExponential(20),
-      match = /([^e]+)(e[+-])(\d+)/.exec(obj),
-      exponentialPart = match[3].length == 1 ? "0" + match[3] : match[3],
-      num = Array.from(bin(match[1] + match[2] + exponentialPart).v);
-  return [o.t].concat(num).concat(Array(31 - num.length).fill(0).flat());
-}
-function en_106(o) { return [106]; }
-function en_115(o) { return [115, o.v.length, ar(o)]; }
-function en_119(o) { return [119, ar(o).length, ar(o)]; }
-function en_118(o) { return [118, ar(o).length >>> 8, ar(o).length & 255, ar(o)]; }
-function en_100(o) { return [100, o.v.length >>> 8, o.v.length & 255, ar(o)]; }
-function en_107(o) { return [107, o.v.length >>> 8, o.v.length & 255, ar(o)]; }
-function en_104(o) {
-  var l = o.v.length, r = [];
-  for (var i = 0; i < l; i++)r[i] = ein(o.v[i]);
-  return [104, l, r];
-}
-function en_109(o) {
-  var l = o.v instanceof ArrayBuffer ? o.v.byteLength : o.v.length;
-  return [109, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255, ar(o)];
-}
-function en_108(o) {
-  var l = o.v.length, r = [];
-  for (var i = 0; i < l; i++)r.push(ein(o.v[i]));
-  return o.v.length == 0 ? [106] :
-         [108, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255, r, 106];
-}
-function en_116(o) {
-  var l=o.v.length,x=[],r = [];
-  for (var i = 0; i < l; i++) r.push([ein(o.v[i].k),ein(o.v[i].v)]);
-  x = [116, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255];
-  return o.v.length == 0 ? x : [x,r];
-}
-function en_110(o) {
-  var s=int_to_bytes(o.v); return [110,s.length,(o.v<0)?1:0,...s];
-}
-
-// DECODER
-
-function nop(b) { return []; };
-function big(b) {
-  var sk = b == 1 ? sx.getUint8(ix++) : sx.getInt32((a = ix, ix += 4, a));
-  var ret = 0, sig = sx.getUint8(ix++), count = sk;
-  while (count-- > 0) { ret = 256 * ret + sx.getUint8(ix + count); }
-  ix += sk; return ret * (sig == 0 ? 1 : -1);
-}
-function int(b) {
-  return b == 1 ? sx.getUint8(ix++) : sx.getInt32((a = ix, ix += 4, a));
-}
-function dec(d) {
-  sx = new DataView(d); ix = 0;
-  if (sx.getUint8(ix++) !== 131) throw ("BERT?");
-  return din();
-}
-function str(b) {
-  var dv, sz = (b==2?sx.getUint16(ix):(b==1?sx.getUint8(ix):sx.getUint32(ix)));
-  ix += b; var r = sx.buffer.slice(ix, ix += sz);
-  return utf8_arr(r);
-}
-function run(b) {
-  var sz = (b == 1 ? sx.getUint8(ix) : sx.getUint32(ix)), r = []; ix += b;
-  for (var i = 0; i < sz; i++) r.push(din());
-  return r;
-}
-function rut(b) {
-  var sz = (b == 1 ? sx.getUint8(ix) : sx.getUint32(ix)), r = []; ix += b;
-  for (var i = 0; i < sz; i++) r.push(din()); din();
-  return r;
-}
-function dic(b) {
-  var sz = sx.getUint32(ix), r = []; ix += 4;
-  for (var i = 0; i < sz; i++) r.push({k:din(),v:din()});
-  return r;
-}
-function iee(x) {
-  return read_Float(new Uint8Array(sx.buffer.slice(ix,ix+=8)),0,false,52,8);
-}
-function flo(x) {
-  return parseFloat(utf8_arr(sx.buffer.slice(ix, ix += 31)));
-}
-function arr(b) {
-  var dv, sz = sx.getUint16(ix); ix += b;
-  return new Uint8Array(sx.buffer.slice(ix, ix += sz));
-}
-function din() {
-  var c = sx.getUint8(ix++), x; switch (c) {
-    case  97: x = [int, 1]; break; case  98: x = [int, 4]; break;
-    case  99: x = [flo, 0]; break; case  70: x = [iee, 0]; break;
-    case 100: x = [str, 2]; break; case 104: x = [run, 1]; break;
-    case 107: x = [arr, 2]; break; case 108: x = [rut, 4]; break;
-    case 109: x = [str, 4]; break; case 110: x = [big, 1]; break;
-    case 111: x = [big, 4]; break; case 115: x = [str, 1]; break;
-    case 118: x = [str, 2]; break; case 119: x = [str, 1]; break;
-    case 105: x = [run, 4]; break; case 116: x = [dic, 4]; break;
-    default:  x = [nop, 0];
-  } return { t: c, v: x[0](x[1]) };
-}
-
-// HELPERS
-
-function int_to_bytes(Int) {
-  var isNegative, OriginalInt, i, Rem, s = [];
-  isNegative = (Int < 0);
-  if (isNegative) { Int = - Int - 1; }
-  OriginalInt = Int;
-  var length = 0;
-  while (Int !== 0) { Rem = Int % 256;
-    if (isNegative) { Rem = 255 - Rem; }
-    s.push(Rem); Int = Math.floor(Int / 256); length++; }
-  if (Int > 0) { throw ("Argument out of range: " + OriginalInt); }
-  return s;
-}
-function uc(u1, u2) {
-  if (u1.byteLength == 0) return u2; if (u2.byteLength == 0) return u1;
-  var a = new Uint8Array(u1.byteLength + u2.byteLength);
-  a.set(u1, 0); a.set(u2, u1.byteLength); return a;
-}
-function ar(o) {
-  return o.v instanceof ArrayBuffer ? new Uint8Array(o.v) : o.v instanceof Uint8Array ? o.v :
-    Array.isArray(o.v) ? new Uint8Array(o.v) : new Uint8Array(utf8_enc(o.v));
-}
-function fl(a) {
-  return a.reduce(function (f, t) {
-    return uc(f, t instanceof Uint8Array ? t :
-      Array.isArray(t) ? fl(t) : new Uint8Array([t]));
-  }, new Uint8Array());
-}

+ 0 - 89
priv/mqtt/priv/static/n2o/ftp.js

@@ -1,89 +0,0 @@
-
-// N2O File Transfer Protocol
-
-function uuid() {
-  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
-  var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); });
-}
-
-var ftp = {
-    queue: [],
-    init: function (file) {
-        var item = {
-            id: uuid(),
-            status: 'init',
-            autostart: ftp.autostart || false,
-            name: ftp.filename || file.name,
-            sid: ftp.sid || token(), // co(session),
-            meta: ftp.meta || bin(client()),
-            offset: ftp.offset || 0,
-            block: 1,
-            total: file.size,
-            file: file
-        };
-        ftp.queue.push(item);
-        ftp.send(item, '', 1);
-        return item.id;
-    },
-    start: function (id) {
-        if (ftp.active) { id && (ftp.item(id).autostart = true); return false; }
-        var item = id ? ftp.item(id) : ftp.next();
-        if (item) { ftp.active = true; ftp.send_slice(item); }
-    },
-    stop: function (id) {
-        var item = ftp.item(id);
-        var index = ftp.queue.indexOf(item);
-        ftp.queue.splice(index, 1);
-        ftp.active = false;
-        ftp.start();
-    },
-    send: function (item, data) {
-        ws.send(enc(tuple(atom('ftp'),
-            bin(item.id),
-            bin(item.sid),
-            bin(item.name),
-            item.meta,
-            number(item.total),
-            number(item.offset),
-            number(item.block || data.byteLength),
-            bin(data),
-            bin(item.status || 'send')
-        )));
-    },
-    send_slice: function (item) {
-        this.reader = new FileReader();
-        this.reader.onloadend = function (e) {
-            var res = e.target, data = e.target.result;
-            if (res.readyState === FileReader.DONE && data.byteLength >= 0) {
-//                console.log(item);
-                ftp.send(item, data);
-            }
-        };
-        this.reader.readAsArrayBuffer(item.file.slice(item.offset, item.offset + item.block));
-    },
-    item: function (id) { return ftp.queue.find(function (item) { return item && item.id === id; }); },
-    next: function () { return ftp.queue.find(function (next) { return next && next.autostart }); }
-};
-
-$file.do = function (rsp) {
-    var offset = rsp.v[6].v, block = rsp.v[7].v, status = utf8_arr(rsp.v[9].v);
-    switch (status) {
-        case 'init':
-            if(block == 1) return;
-            var item = ftp.item(utf8_arr(rsp.v[1].v)) || '0';
-            item.offset = offset;
-            item.block = block;
-            item.name = utf8_arr(rsp.v[3].v);
-            item.status = undefined;
-            if (item.autostart) ftp.start(item.id);
-            break;
-        case 'send':
-            var x = qi('ftp_status'); if (x) x.innerHTML = offset;
-            var item = ftp.item(utf8_arr(rsp.v[1].v));
-            item.offset = offset;
-            item.block = block;
-            (block > 0 && ftp.active) ? ftp.send_slice(item) : ftp.stop(item.id)
-            break;
-        case 'relay': debugger; if (typeof ftp.relay === 'function') ftp.relay(rsp); break;
-    }
-};

+ 0 - 35
priv/mqtt/priv/static/n2o/heart.js

@@ -1,35 +0,0 @@
-
-// WebSocket Transport
-
-$ws = { heart: true, interval: 5000,
-        creator: function(url) { return window.WebSocket ? new window.WebSocket(url) : false; },
-        onheartbeat: function() { this.channel.send('PING');
-                                  } };
-
-// N2O Reliable Connection
-
-$conn = { onopen: nop, onmessage: nop, onclose: nop, onconnect: nop,
-          send:  function(data)   { if (this.port.channel) this.port.channel.send(data); },
-          close: function()       { if (this.port.channel) this.port.channel.close(); } };
-
-ct = 0;
-transports = [ $ws ];
-heartbeat = null;
-reconnectDelay = 1000;
-maxReconnects = 100;
-
-function nop() { }
-function bullet(url) { $conn.url = url; return $conn; }
-function xport() { return maxReconnects <= ct ? false : transports[ct++ % transports.length]; }
-function reconnect() { setTimeout(function() { connect(); }, reconnectDelay); }
-function next() { $conn.port = xport(); return $conn.port ? connect() : false; }
-function connect() {
-    $conn.port.channel = $conn.port.creator($conn.url);
-    if (!$conn.port.channel) return next();
-    $conn.port.channel.onmessage = function(e) { $conn.onmessage(e); };
-    $conn.port.channel.onopen = function() {
-        if ($conn.port.heart) heartbeat = setInterval(function(){$conn.port.onheartbeat();}, $conn.port.interval);
-        $conn.onopen();
-        $conn.onconnect(); };
-    $conn.port.channel.onclose = function() { $conn.onclose(); clearInterval(heartbeat); reconnect(); };
-    return $conn; }

+ 0 - 75
priv/mqtt/priv/static/n2o/ieee754.js

@@ -1,75 +0,0 @@
-
-function read_Float(buffer, offset, isLE, mLen, nBytes) {
-  var e, m
-  var eLen = (nBytes * 8) - mLen - 1
-  var eMax = (1 << eLen) - 1
-  var eBias = eMax >> 1
-  var nBits = -7
-  var i = isLE ? (nBytes - 1) : 0
-  var d = isLE ? -1 : 1
-  var s = buffer[offset + i]
-  i += d
-  e = s & ((1 << (-nBits)) - 1)
-  s >>= (-nBits)
-  nBits += eLen
-  for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
-  m = e & ((1 << (-nBits)) - 1)
-  e >>= (-nBits)
-  nBits += mLen
-  for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
-  if (e === 0) {
-    e = 1 - eBias
-  } else if (e === eMax) {
-    return m ? NaN : ((s ? -1 : 1) * Infinity)
-  } else {
-    m = m + Math.pow(2, mLen)
-    e = e - eBias
-  }
-  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
-}
-
-function write_Float(buffer, value, offset, isLE, mLen, nBytes) {
-  var e, m, c
-  var eLen = (nBytes * 8) - mLen - 1
-  var eMax = (1 << eLen) - 1
-  var eBias = eMax >> 1
-  var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
-  var i = isLE ? 0 : (nBytes - 1)
-  var d = isLE ? 1 : -1
-  var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
-  value = Math.abs(value)
-  if (isNaN(value) || value === Infinity) {
-    m = isNaN(value) ? 1 : 0
-    e = eMax
-  } else {
-    e = Math.floor(Math.log(value) / Math.LN2)
-    if (value * (c = Math.pow(2, -e)) < 1) {
-      e--
-      c *= 2
-    }
-    if (e + eBias >= 1) {
-      value += rt / c
-    } else {
-      value += rt * Math.pow(2, 1 - eBias)
-    }
-    if (value * c >= 2) {
-      e++
-      c /= 2
-    }
-    if (e + eBias >= eMax) {
-      m = 0
-      e = eMax
-    } else if (e + eBias >= 1) {
-      m = ((value * c) - 1) * Math.pow(2, mLen)
-      e = e + eBias
-    } else {
-      m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
-      e = 0
-    }
-  }
-  for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
-  e = (e << mLen) | m
-  eLen += mLen
-  for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
-  buffer[offset + i - d] |= s * 128
-}

+ 0 - 56
priv/mqtt/priv/static/n2o/mq.js

@@ -1,56 +0,0 @@
-var match, pl = /\+/g, search = /([^&=]+)=?([^&]*)/g,
-    decode_uri = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
-    query = window.location.search.substring(1),
-    nodes = 4,
-    params = {}; while (match = search.exec(query)) params[decode_uri(match[1])] = decode_uri(match[2]);
-var l = location.pathname,
-    x = l.substring(l.lastIndexOf("/") + 1),
-    ll = x.lastIndexOf("."),
-    module = x == "" ? "index" : (ll > 0 ? x.substring(0, ll) : x);
-var ws = { send: function (payload, qos) {
-        var message = new Paho.MQTT.Message(payload);
-        message.destinationName = topic("events");
-        message.qos = qos || 2;
-        mqtt.send(message); } };
-
-var subscribeOptions = {
-    qos: 2,  // QoS
-    invocationContext: { foo: true },  // Passed to success / failure callback
-    onSuccess: function (x) { console.log("MQTT Subscribe"); },
-    onFailure: function (m) { console.log("MQTT Subscription failed: " + m.errorMessage); },
-    timeout: 2 };
-
-var options = {
-    timeout: 2,
-    userName: module,
-    password: token(),
-    cleanSession: false,
-    onFailure: function (m) { console.log("MQTT Connection failed: " + m.errorMessage); },
-    onSuccess: function ()  { console.log("MQTT Connect");
-                              ws.send(enc(tuple(atom('init'),bin(token()))));
-                            } };
-
-function gen_client()  { return Math.random().toString(36).substring(2) + (new Date()).getTime().toString(36); }
-function pageModule()  { return module || 'api'; }
-function client()      { var c = localStorage.getItem("client"), a;
-                         if (null == c) { c = 'emqttd_' + gen_client(); }
-                         localStorage.setItem("client", c); return c; }
-function token()       { return localStorage.getItem("token")  || ''; };
-function topic(prefix) { return prefix + "/1/" + rnd() + "/" + pageModule() + "/anon/" + client() + "/" + token(); }
-function rnd()         { return Math.floor((Math.random() * nodes)+1); }
-
-  mqtt = new Paho.MQTT.Client(host, 8083, client());
-  mqtt.onConnectionLost = function (o) { console.log("connection lost: " + o.errorMessage); };
-  mqtt.onMessageArrived = function (m) {
-        var BERT = m.payloadBytes.buffer.slice(m.payloadBytes.byteOffset,
-            m.payloadBytes.byteOffset + m.payloadBytes.length);
-        try {
-            erlang = dec(BERT);
-            for (var i = 0; i < $bert.protos.length; i++) {
-                p = $bert.protos[i]; if (p.on(erlang, p.do).status == "ok") return;
-            }
-        } catch (e) { console.log(e); }
-  };
-
-mqtt.connect(options);
-

+ 0 - 69
priv/mqtt/priv/static/n2o/n2o.js

@@ -1,69 +0,0 @@
-
-// 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;
-
-function client() { return ''; }
-function token()  { return localStorage.getItem("token")  || ''; };
-function qi(name) { return document.getElementById(name); }
-function qs(name) { return document.querySelector(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; }
-
-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) { ws.send('N2O,'+token()); console.log('WS Connect'); active=true; } };
-    ws.onclose = function() { active = false; console.log('WS Disconnect'); }; next(); }
-
-/// N2O Protocols
-
-var $io = {}; $io.on = function onio(r, cb) {
-    if (is(r, 3, 'io')) {
-        if (r.v[2].v != undefined && r.v[2].v[1] != undefined &&
-            r.v[2].v.length == 2 && (r.v[2].v[0].v == "Token" || r.v[2].v[0].v == "Auth")) {
-            localStorage.setItem("token",utf8_arr(r.v[2].v[1].v));
-        }
-        try { eval(utf8_arr(r.v[1].v));
-              if (typeof cb == 'function') cb(r);
-              return { status: "ok" };
-        } catch (e)  { console.log("Eval error: "+r);
-                       return { status: '' }; }
-    } else return { status: '' };
-}
-
-var $file = {}; $file.on = function onfile(r, cb) {
-    if (is(r, 10, 'ftpack')) {
-        if (typeof cb == 'function') cb(r); return { status: "ok" };
-    } else return { status: '' };
-}
-
-// BERT Formatter
-
-var $bert = {}; $bert.protos = [$io, $file]; $bert.on = function onbert(evt, cb) {
-    if (Blob.prototype.isPrototypeOf(evt.data) &&
-       (evt.data.length > 0 || evt.data.size > 0)) {
-        var r = new FileReader();
-        r.addEventListener("loadend", function () {
-            try {
-                erlang = dec(r.result);
-                if (typeof cb == 'function') cb(erlang);
-                for (var i = 0; i < $bert.protos.length; i++) {
-                    p = $bert.protos[i];
-                    if (p.on(erlang, p.do).status == "ok") return;
-                }
-            } catch (e) { console.log(e); }
-        });
-        r.readAsArrayBuffer(evt.data);
-        return { status: "ok" };
-    } else return { status: "error", desc: "data" };
-}
-
-var protos = [$bert];

+ 0 - 40
priv/mqtt/priv/static/n2o/nitro.js

@@ -1,40 +0,0 @@
-// Nitrogen Compatibility Layer
-
-function validateSources() { return true; }
-
-function querySourceRaw(Id) {
-    var val, el = document.getElementById(Id);
-    if (!el) return "";
-    switch (el.tagName) {
-        case 'FIELDSET': val = document.querySelector('[id="' + Id + '"] :checked');
-            val = val ? val.value : ""; break;
-        case 'INPUT':
-            switch (el.getAttribute("type")) {
-                case 'radio': case 'checkbox': val = el.checked ? el.value : ""; break;
-                case 'date': val = new Date(Date.parse(el.value)) || ""; break;
-                case 'calendar': val = pickers[el.id]._d || ""; break;  //only 4 nitro #calendar{}
-                default: var edit = el.contentEditable;
-                    if (edit && edit === 'true') val = el.innerHTML;
-                    else val = el.value;
-            }
-            break;
-        default: var edit = el.contentEditable;
-            if (edit && edit === 'true') val = el.innerHTML;
-            else val = el.value;
-    }
-    return val;
-}
-
-function querySource(Id) {
-    var qs = querySourceRaw(Id);
-    if (qs instanceof Date) {
-       return tuple(number(qs.getFullYear()),
-                    number(qs.getMonth() + 1),
-                    number(qs.getDate())); }
-    else { return bin(qs); }
-}
-
-(function () {
-    window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
-        window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
-})();

+ 0 - 7
priv/mqtt/priv/static/n2o/utf8.js

@@ -1,7 +0,0 @@
-
-// N2O UTF-8 Support
-
-function utf8_dec(ab) { return (new TextDecoder()).decode(ab); }
-function utf8_enc(ab) { return (new TextEncoder("utf-8")).encode(ab); }
-function utf8_arr(ab) { if (!(ab instanceof ArrayBuffer)) ab = new Uint8Array(utf8_enc(ab)).buffer;
-                        return utf8_dec(ab); }

+ 0 - 1
priv/mqtt/priv/static/synrc.css

@@ -7,7 +7,6 @@
 body {
     font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
     color: #737373;
-//    background: url('back.jpg') center / cover;
     margin: 0;
 }
 

+ 1 - 1
priv/mqtt/rebar.config

@@ -1,7 +1,7 @@
 {deps, [
     {kvs,    ".*", {git, "git://github.com/synrc/kvs",    []}},
     {mad,    ".*", {git, "git://github.com/synrc/mad",    []}},
-    {n2o,    ".*", {git, "git://github.com/synrc/mqtt",   []}},
+    {n2o,    ".*", {git, "git://github.com/synrc/n2o",    []}},
     {emqttd, ".*", {git, "git://github.com/synrc/emqttd", []}},
     {nitro,  ".*", {git, "git://github.com/synrc/nitro",  []}}
 ]}.

+ 9 - 8
priv/web/priv/static/index.htm

@@ -4,7 +4,7 @@
     <meta charset="utf-8">
     <meta http-equiv="x-ua-compatible" content="ie=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href='synrc.css?v=202' type='text/css' rel='stylesheet'>
+    <link href='synrc.css' type='text/css' rel='stylesheet'>
     <title>Chat</title>
 </head>
 
@@ -24,15 +24,16 @@
         </history>
 
     </main>
-    <script src='n2o/utf8.js?v=1'></script>
-    <script src='n2o/bert.js?v=1'></script>
-    <script src='n2o/heart.js?v=1'></script>
-    <script src='n2o/ieee754.js?v=1'></script>
-    <script src='n2o/n2o.js?v=1'></script>
+    <script src='https://ws.n2o.space/priv/utf8.js'></script>
+    <script src='https://ws.n2o.space/priv/bert.js'></script>
+    <script src='https://ws.n2o.space/priv/heart.js'></script>
+    <script src='https://ws.n2o.space/priv/ieee754.js'></script>
+    <script src='https://ws.n2o.space/priv/n2o.js'></script>
         <script>host = location.hostname === 'sample.n2o.space' ? 'ns.synrc.com' : location.hostname;
                port = 8001;</script>
-        <script src='n2o/ftp.js?v=1'></script>
-        <script src='n2o/nitro.js?v=1'></script>
+        <script src='https://ws.n2o.space/priv/ftp.js'></script>
+        <script src='https://ws.n2o.space/priv/nitro.js'></script>
+        <script>$io.do = function(r) { console.log(r); };</script>
         <script>protos = [$bert]; N2O_start();</script>
 </body>
 

+ 10 - 8
priv/web/priv/static/login.htm

@@ -4,13 +4,13 @@
     <meta charset="utf-8">
     <meta http-equiv="x-ua-compatible" content="ie=edge">
     <meta name="viewport" content="width=device-width, initial-scale=1">
-    <link href='synrc.css?v=202' type='text/css' rel='stylesheet'>
+    <link href='synrc.css' type='text/css' rel='stylesheet'>
     <title>Login</title>
 </head>
 
 <body class="login">
     <header>
-        <a href="/app/index.htm">
+        <a href="index.htm">
         <img src="https://n2o.space/img/Synrc%20Neo.svg" style="margin-bottom:40px;"></a>
     </header>
     <form>
@@ -21,15 +21,17 @@
         <button id="loginButton">login</button>
     </form>
     <footer>Brought to you with ♡ by N2O developers.</footer>
-    <script src='n2o/utf8.js?v=1'></script>
-    <script src='n2o/bert.js?v=1'></script>
-    <script src='n2o/heart.js?v=1'></script>
-    <script src='n2o/n2o.js?v=1'></script>
+
+    <script src='https://ws.n2o.space/priv/utf8.js'></script>
+    <script src='https://ws.n2o.space/priv/bert.js'></script>
+    <script src='https://ws.n2o.space/priv/heart.js'></script>
+    <script src='https://ws.n2o.space/priv/n2o.js'></script>
         <script>host = location.hostname === 'sample.n2o.space' ? 'ns.synrc.com' : location.hostname;
                port = 8001;</script>
-        <script src='n2o/ftp.js?v=1'></script>
-        <script src='n2o/nitro.js?v=1'></script>
+        <script src='https://ws.n2o.space/priv/ftp.js'></script>
+        <script src='https://ws.n2o.space/priv/nitro.js'></script>
         <script>protos = [$bert]; N2O_start();</script>
+
 </body>
 
 </html>

+ 0 - 158
priv/web/priv/static/n2o/bert.js

@@ -1,158 +0,0 @@
-
-// API
-
-function tuple() { return { t: 104, v: Array.apply(null, arguments) }; }
-function list() { return { t: 108, v: Array.apply(null, arguments) }; }
-function map() { return { t: 116, v: Array.apply(null, arguments) }; }
-function atom(o) { return { t: 100, v: utf8_enc(o) }; }
-function string(o) { return { t: 107, v: utf8_enc(o) }; }
-function float(o) { return { t: 70, v: o }; }
-function number(o) {
-  var s, isInteger = (o % 1 === 0);
-  if (isInteger && o >= 0 && o < 256) { return { t: 97, v: o };  }
-  if (isInteger && o >= -134217728 && o <= 134217727) { return {t: 98, v: o}; }
-  return {t: 110, v: o}; }
-function bin(o) {
-  return { t: 109, v: o instanceof ArrayBuffer ? new Uint8Array(o) :
-                      o instanceof Uint8Array  ? o : utf8_enc(o) }; }
-
-// ENCODER
-
-function enc(o) { return fl([131, ein(o)]); }
-function ein(o) { return Array.isArray(o) ? en_108({ t: 108, v: o }) : eval('en_' + o.t)(o); }
-function en_undefined(o) { return [106]; }
-function en_70(o) {
-  var x = Array(8).fill(0).flat();
-  write_Float(x,o.v,0,false,52,8);
-  return [70].concat(x);
-}
-function en_97(o) { return [97, o.v]; }
-function en_98(o) { return [98, o.v >>> 24, (o.v >>> 16) & 255, (o.v >>> 8) & 255, o.v & 255]; }
-function en_99(o) {
-  var obj = o.v.toExponential(20),
-      match = /([^e]+)(e[+-])(\d+)/.exec(obj),
-      exponentialPart = match[3].length == 1 ? "0" + match[3] : match[3],
-      num = Array.from(bin(match[1] + match[2] + exponentialPart).v);
-  return [o.t].concat(num).concat(Array(31 - num.length).fill(0).flat());
-}
-function en_106(o) { return [106]; }
-function en_115(o) { return [115, o.v.length, ar(o)]; }
-function en_119(o) { return [119, ar(o).length, ar(o)]; }
-function en_118(o) { return [118, ar(o).length >>> 8, ar(o).length & 255, ar(o)]; }
-function en_100(o) { return [100, o.v.length >>> 8, o.v.length & 255, ar(o)]; }
-function en_107(o) { return [107, o.v.length >>> 8, o.v.length & 255, ar(o)]; }
-function en_104(o) {
-  var l = o.v.length, r = [];
-  for (var i = 0; i < l; i++)r[i] = ein(o.v[i]);
-  return [104, l, r];
-}
-function en_109(o) {
-  var l = o.v instanceof ArrayBuffer ? o.v.byteLength : o.v.length;
-  return [109, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255, ar(o)];
-}
-function en_108(o) {
-  var l = o.v.length, r = [];
-  for (var i = 0; i < l; i++)r.push(ein(o.v[i]));
-  return o.v.length == 0 ? [106] :
-         [108, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255, r, 106];
-}
-function en_116(o) {
-  var l=o.v.length,x=[],r = [];
-  for (var i = 0; i < l; i++) r.push([ein(o.v[i].k),ein(o.v[i].v)]);
-  x = [116, l >>> 24, (l >>> 16) & 255, (l >>> 8) & 255, l & 255];
-  return o.v.length == 0 ? x : [x,r];
-}
-function en_110(o) {
-  var s=int_to_bytes(o.v); return [110,s.length,(o.v<0)?1:0,...s];
-}
-
-// DECODER
-
-function nop(b) { return []; };
-function big(b) {
-  var sk = b == 1 ? sx.getUint8(ix++) : sx.getInt32((a = ix, ix += 4, a));
-  var ret = 0, sig = sx.getUint8(ix++), count = sk;
-  while (count-- > 0) { ret = 256 * ret + sx.getUint8(ix + count); }
-  ix += sk; return ret * (sig == 0 ? 1 : -1);
-}
-function int(b) {
-  return b == 1 ? sx.getUint8(ix++) : sx.getInt32((a = ix, ix += 4, a));
-}
-function dec(d) {
-  sx = new DataView(d); ix = 0;
-  if (sx.getUint8(ix++) !== 131) throw ("BERT?");
-  return din();
-}
-function str(b) {
-  var dv, sz = (b==2?sx.getUint16(ix):(b==1?sx.getUint8(ix):sx.getUint32(ix)));
-  ix += b; var r = sx.buffer.slice(ix, ix += sz);
-  return utf8_arr(r);
-}
-function run(b) {
-  var sz = (b == 1 ? sx.getUint8(ix) : sx.getUint32(ix)), r = []; ix += b;
-  for (var i = 0; i < sz; i++) r.push(din());
-  return r;
-}
-function rut(b) {
-  var sz = (b == 1 ? sx.getUint8(ix) : sx.getUint32(ix)), r = []; ix += b;
-  for (var i = 0; i < sz; i++) r.push(din()); din();
-  return r;
-}
-function dic(b) {
-  var sz = sx.getUint32(ix), r = []; ix += 4;
-  for (var i = 0; i < sz; i++) r.push({k:din(),v:din()});
-  return r;
-}
-function iee(x) {
-  return read_Float(new Uint8Array(sx.buffer.slice(ix,ix+=8)),0,false,52,8);
-}
-function flo(x) {
-  return parseFloat(utf8_arr(sx.buffer.slice(ix, ix += 31)));
-}
-function arr(b) {
-  var dv, sz = sx.getUint16(ix); ix += b;
-  return new Uint8Array(sx.buffer.slice(ix, ix += sz));
-}
-function din() {
-  var c = sx.getUint8(ix++), x; switch (c) {
-    case  97: x = [int, 1]; break; case  98: x = [int, 4]; break;
-    case  99: x = [flo, 0]; break; case  70: x = [iee, 0]; break;
-    case 100: x = [str, 2]; break; case 104: x = [run, 1]; break;
-    case 107: x = [arr, 2]; break; case 108: x = [rut, 4]; break;
-    case 109: x = [str, 4]; break; case 110: x = [big, 1]; break;
-    case 111: x = [big, 4]; break; case 115: x = [str, 1]; break;
-    case 118: x = [str, 2]; break; case 119: x = [str, 1]; break;
-    case 105: x = [run, 4]; break; case 116: x = [dic, 4]; break;
-    default:  x = [nop, 0];
-  } return { t: c, v: x[0](x[1]) };
-}
-
-// HELPERS
-
-function int_to_bytes(Int) {
-  var isNegative, OriginalInt, i, Rem, s = [];
-  isNegative = (Int < 0);
-  if (isNegative) { Int = - Int - 1; }
-  OriginalInt = Int;
-  var length = 0;
-  while (Int !== 0) { Rem = Int % 256;
-    if (isNegative) { Rem = 255 - Rem; }
-    s.push(Rem); Int = Math.floor(Int / 256); length++; }
-  if (Int > 0) { throw ("Argument out of range: " + OriginalInt); }
-  return s;
-}
-function uc(u1, u2) {
-  if (u1.byteLength == 0) return u2; if (u2.byteLength == 0) return u1;
-  var a = new Uint8Array(u1.byteLength + u2.byteLength);
-  a.set(u1, 0); a.set(u2, u1.byteLength); return a;
-}
-function ar(o) {
-  return o.v instanceof ArrayBuffer ? new Uint8Array(o.v) : o.v instanceof Uint8Array ? o.v :
-    Array.isArray(o.v) ? new Uint8Array(o.v) : new Uint8Array(utf8_enc(o.v));
-}
-function fl(a) {
-  return a.reduce(function (f, t) {
-    return uc(f, t instanceof Uint8Array ? t :
-      Array.isArray(t) ? fl(t) : new Uint8Array([t]));
-  }, new Uint8Array());
-}

+ 0 - 89
priv/web/priv/static/n2o/ftp.js

@@ -1,89 +0,0 @@
-
-// N2O File Transfer Protocol
-
-function uuid() {
-  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
-  var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16); });
-}
-
-var ftp = {
-    queue: [],
-    init: function (file) {
-        var item = {
-            id: uuid(),
-            status: 'init',
-            autostart: ftp.autostart || false,
-            name: ftp.filename || file.name,
-            sid: ftp.sid || token(), // co(session),
-            meta: ftp.meta || bin(client()),
-            offset: ftp.offset || 0,
-            block: 1,
-            total: file.size,
-            file: file
-        };
-        ftp.queue.push(item);
-        ftp.send(item, '', 1);
-        return item.id;
-    },
-    start: function (id) {
-        if (ftp.active) { id && (ftp.item(id).autostart = true); return false; }
-        var item = id ? ftp.item(id) : ftp.next();
-        if (item) { ftp.active = true; ftp.send_slice(item); }
-    },
-    stop: function (id) {
-        var item = ftp.item(id);
-        var index = ftp.queue.indexOf(item);
-        ftp.queue.splice(index, 1);
-        ftp.active = false;
-        ftp.start();
-    },
-    send: function (item, data) {
-        ws.send(enc(tuple(atom('ftp'),
-            bin(item.id),
-            bin(item.sid),
-            bin(item.name),
-            item.meta,
-            number(item.total),
-            number(item.offset),
-            number(item.block || data.byteLength),
-            bin(data),
-            bin(item.status || 'send')
-        )));
-    },
-    send_slice: function (item) {
-        this.reader = new FileReader();
-        this.reader.onloadend = function (e) {
-            var res = e.target, data = e.target.result;
-            if (res.readyState === FileReader.DONE && data.byteLength >= 0) {
-//                console.log(item);
-                ftp.send(item, data);
-            }
-        };
-        this.reader.readAsArrayBuffer(item.file.slice(item.offset, item.offset + item.block));
-    },
-    item: function (id) { return ftp.queue.find(function (item) { return item && item.id === id; }); },
-    next: function () { return ftp.queue.find(function (next) { return next && next.autostart }); }
-};
-
-$file.do = function (rsp) {
-    var offset = rsp.v[6].v, block = rsp.v[7].v, status = utf8_arr(rsp.v[9].v);
-    switch (status) {
-        case 'init':
-            if(block == 1) return;
-            var item = ftp.item(utf8_arr(rsp.v[1].v)) || '0';
-            item.offset = offset;
-            item.block = block;
-            item.name = utf8_arr(rsp.v[3].v);
-            item.status = undefined;
-            if (item.autostart) ftp.start(item.id);
-            break;
-        case 'send':
-            var x = qi('ftp_status'); if (x) x.innerHTML = offset;
-            var item = ftp.item(utf8_arr(rsp.v[1].v));
-            item.offset = offset;
-            item.block = block;
-            (block > 0 && ftp.active) ? ftp.send_slice(item) : ftp.stop(item.id)
-            break;
-        case 'relay': debugger; if (typeof ftp.relay === 'function') ftp.relay(rsp); break;
-    }
-};

+ 0 - 35
priv/web/priv/static/n2o/heart.js

@@ -1,35 +0,0 @@
-
-// WebSocket Transport
-
-$ws = { heart: true, interval: 5000,
-        creator: function(url) { return window.WebSocket ? new window.WebSocket(url) : false; },
-        onheartbeat: function() { this.channel.send('PING');
-                                  } };
-
-// N2O Reliable Connection
-
-$conn = { onopen: nop, onmessage: nop, onclose: nop, onconnect: nop,
-          send:  function(data)   { if (this.port.channel) this.port.channel.send(data); },
-          close: function()       { if (this.port.channel) this.port.channel.close(); } };
-
-ct = 0;
-transports = [ $ws ];
-heartbeat = null;
-reconnectDelay = 1000;
-maxReconnects = 100;
-
-function nop() { }
-function bullet(url) { $conn.url = url; return $conn; }
-function xport() { return maxReconnects <= ct ? false : transports[ct++ % transports.length]; }
-function reconnect() { setTimeout(function() { connect(); }, reconnectDelay); }
-function next() { $conn.port = xport(); return $conn.port ? connect() : false; }
-function connect() {
-    $conn.port.channel = $conn.port.creator($conn.url);
-    if (!$conn.port.channel) return next();
-    $conn.port.channel.onmessage = function(e) { $conn.onmessage(e); };
-    $conn.port.channel.onopen = function() {
-        if ($conn.port.heart) heartbeat = setInterval(function(){$conn.port.onheartbeat();}, $conn.port.interval);
-        $conn.onopen();
-        $conn.onconnect(); };
-    $conn.port.channel.onclose = function() { $conn.onclose(); clearInterval(heartbeat); reconnect(); };
-    return $conn; }

+ 0 - 75
priv/web/priv/static/n2o/ieee754.js

@@ -1,75 +0,0 @@
-
-function read_Float(buffer, offset, isLE, mLen, nBytes) {
-  var e, m
-  var eLen = (nBytes * 8) - mLen - 1
-  var eMax = (1 << eLen) - 1
-  var eBias = eMax >> 1
-  var nBits = -7
-  var i = isLE ? (nBytes - 1) : 0
-  var d = isLE ? -1 : 1
-  var s = buffer[offset + i]
-  i += d
-  e = s & ((1 << (-nBits)) - 1)
-  s >>= (-nBits)
-  nBits += eLen
-  for (; nBits > 0; e = (e * 256) + buffer[offset + i], i += d, nBits -= 8) {}
-  m = e & ((1 << (-nBits)) - 1)
-  e >>= (-nBits)
-  nBits += mLen
-  for (; nBits > 0; m = (m * 256) + buffer[offset + i], i += d, nBits -= 8) {}
-  if (e === 0) {
-    e = 1 - eBias
-  } else if (e === eMax) {
-    return m ? NaN : ((s ? -1 : 1) * Infinity)
-  } else {
-    m = m + Math.pow(2, mLen)
-    e = e - eBias
-  }
-  return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
-}
-
-function write_Float(buffer, value, offset, isLE, mLen, nBytes) {
-  var e, m, c
-  var eLen = (nBytes * 8) - mLen - 1
-  var eMax = (1 << eLen) - 1
-  var eBias = eMax >> 1
-  var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
-  var i = isLE ? 0 : (nBytes - 1)
-  var d = isLE ? 1 : -1
-  var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
-  value = Math.abs(value)
-  if (isNaN(value) || value === Infinity) {
-    m = isNaN(value) ? 1 : 0
-    e = eMax
-  } else {
-    e = Math.floor(Math.log(value) / Math.LN2)
-    if (value * (c = Math.pow(2, -e)) < 1) {
-      e--
-      c *= 2
-    }
-    if (e + eBias >= 1) {
-      value += rt / c
-    } else {
-      value += rt * Math.pow(2, 1 - eBias)
-    }
-    if (value * c >= 2) {
-      e++
-      c /= 2
-    }
-    if (e + eBias >= eMax) {
-      m = 0
-      e = eMax
-    } else if (e + eBias >= 1) {
-      m = ((value * c) - 1) * Math.pow(2, mLen)
-      e = e + eBias
-    } else {
-      m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
-      e = 0
-    }
-  }
-  for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
-  e = (e << mLen) | m
-  eLen += mLen
-  for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
-  buffer[offset + i - d] |= s * 128
-}

+ 0 - 69
priv/web/priv/static/n2o/n2o.js

@@ -1,69 +0,0 @@
-
-// 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;
-
-function client() { return ''; }
-function token()  { return localStorage.getItem("token")  || ''; };
-function qi(name) { return document.getElementById(name); }
-function qs(name) { return document.querySelector(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; }
-
-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) { ws.send('N2O,'+token()); console.log('WS Connect'); active=true; } };
-    ws.onclose = function() { active = false; console.log('WS Disconnect'); }; next(); }
-
-/// N2O Protocols
-
-var $io = {}; $io.on = function onio(r, cb) {
-    if (is(r, 3, 'io')) {
-        if (r.v[2].v != undefined && r.v[2].v[1] != undefined &&
-            r.v[2].v.length == 2 && (r.v[2].v[0].v == "Token" || r.v[2].v[0].v == "Auth")) {
-            localStorage.setItem("token",utf8_arr(r.v[2].v[1].v));
-        }
-        try { eval(utf8_arr(r.v[1].v));
-              if (typeof cb == 'function') cb(r);
-              return { status: "ok" };
-        } catch (e)  { console.log("Eval error: "+r);
-                       return { status: '' }; }
-    } else return { status: '' };
-}
-
-var $file = {}; $file.on = function onfile(r, cb) {
-    if (is(r, 10, 'ftpack')) {
-        if (typeof cb == 'function') cb(r); return { status: "ok" };
-    } else return { status: '' };
-}
-
-// BERT Formatter
-
-var $bert = {}; $bert.protos = [$io, $file]; $bert.on = function onbert(evt, cb) {
-    if (Blob.prototype.isPrototypeOf(evt.data) &&
-       (evt.data.length > 0 || evt.data.size > 0)) {
-        var r = new FileReader();
-        r.addEventListener("loadend", function () {
-            try {
-                erlang = dec(r.result);
-                if (typeof cb == 'function') cb(erlang);
-                for (var i = 0; i < $bert.protos.length; i++) {
-                    p = $bert.protos[i];
-                    if (p.on(erlang, p.do).status == "ok") return;
-                }
-            } catch (e) { console.log(e); }
-        });
-        r.readAsArrayBuffer(evt.data);
-        return { status: "ok" };
-    } else return { status: "error", desc: "data" };
-}
-
-var protos = [$bert];

+ 0 - 40
priv/web/priv/static/n2o/nitro.js

@@ -1,40 +0,0 @@
-// Nitrogen Compatibility Layer
-
-function validateSources() { return true; }
-
-function querySourceRaw(Id) {
-    var val, el = document.getElementById(Id);
-    if (!el) return "";
-    switch (el.tagName) {
-        case 'FIELDSET': val = document.querySelector('[id="' + Id + '"] :checked');
-            val = val ? val.value : ""; break;
-        case 'INPUT':
-            switch (el.getAttribute("type")) {
-                case 'radio': case 'checkbox': val = el.checked ? el.value : ""; break;
-                case 'date': val = new Date(Date.parse(el.value)) || ""; break;
-                case 'calendar': val = pickers[el.id]._d || ""; break;  //only 4 nitro #calendar{}
-                default: var edit = el.contentEditable;
-                    if (edit && edit === 'true') val = el.innerHTML;
-                    else val = el.value;
-            }
-            break;
-        default: var edit = el.contentEditable;
-            if (edit && edit === 'true') val = el.innerHTML;
-            else val = el.value;
-    }
-    return val;
-}
-
-function querySource(Id) {
-    var qs = querySourceRaw(Id);
-    if (qs instanceof Date) {
-       return tuple(number(qs.getFullYear()),
-                    number(qs.getMonth() + 1),
-                    number(qs.getDate())); }
-    else { return bin(qs); }
-}
-
-(function () {
-    window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
-        window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
-})();

+ 0 - 7
priv/web/priv/static/n2o/utf8.js

@@ -1,7 +0,0 @@
-
-// N2O UTF-8 Support
-
-function utf8_dec(ab) { return (new TextDecoder()).decode(ab); }
-function utf8_enc(ab) { return (new TextEncoder("utf-8")).encode(ab); }
-function utf8_arr(ab) { if (!(ab instanceof ArrayBuffer)) ab = new Uint8Array(utf8_enc(ab)).buffer;
-                        return utf8_dec(ab); }

+ 0 - 1
priv/web/priv/static/synrc.css

@@ -7,7 +7,6 @@
 body {
     font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
     color: #737373;
-//    background: url('back.jpg') center / cover;
     margin: 0;
 }
 

+ 4 - 6
priv/web/src/index.erl

@@ -3,8 +3,6 @@
 -include_lib("kvs/include/entry.hrl").
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/n2o.hrl").
-body() -> [].
-main() -> [].
 event(init) ->
     Room = n2o:session(room),
     io:format("Room: ~p~n",[Room]),
@@ -25,7 +23,7 @@ event(chat) ->
     User    = n2o:user(),
     Room    = n2o:session(room),
     Message = nitro:q(message),
-    n2o:info(?MODULE,"Chat pressed: ~p~n",[{Room,Message,User}]),
+    ?LOG_INFO("Chat pressed: ~p~n",[{Room,Message,User}]),
     kvs:add(#entry{id=kvs:next_id("entry",1),from=n2o:user(),
                    feed_id={room,Room},media=Message}),
     n2o:send({topic,Room},#client{data={User,Message}});
@@ -36,9 +34,9 @@ event(#client{data={User,Message}}) ->
     nitro:insert_top(history, nitro:jse(nitro:render(DTL)));
 event(#ftp{sid=Sid,filename=Filename,status={event,stop}}=Data) ->
     Name = hd(lists:reverse(string:tokens(nitro:to_list(Filename),"/"))),
-    erlang:put(message,nitro:render(#link{href=iolist_to_binary(["/app/",Sid,"/",nitro_conv:url_encode(Name)]),body=Name})),
-    n2o:info(?MODULE,"FTP Delivered ~p~n",[Data]),
+    erlang:put(message,nitro:render(#link{href=iolist_to_binary(["/app/",Sid,"/",Name]),body=Name})),
+    ?LOG_INFO("FTP Delivered ~p~n",[Data]),
     event(chat);
 event(Event) ->
-    n2o:info(?MODULE,"Event: ~p", [Event]),
+    ?LOG_INFO("Event: ~p", [Event]),
     ok.

+ 1 - 3
priv/web/src/login.erl

@@ -4,8 +4,6 @@
 -include_lib("nitro/include/nitro.hrl").
 -include_lib("n2o/include/n2o.hrl").
 
-main() -> [].
-body() -> [].
 event(init) ->
     nitro:update(loginButton,
       #button{id=loginButton,
@@ -15,7 +13,7 @@ event(login) ->
     Room = nitro:to_list(nitro:q(pass)),
     n2o:user(User),
     n2o:session(room,Room),
-    n2o:info(?MODULE,"User: ~p",[User]),
+    ?LOG_INFO("User: ~p",[User]),
     nitro:redirect("/app/index.htm?room="++Room),
     ok;
 event(_) -> [].

+ 2 - 5
priv/web/src/routes.erl

@@ -4,12 +4,9 @@
 
 finish(State, Ctx) -> {ok, State, Ctx}.
 init(State, #cx{req=Req}=Cx) ->
-    Path = case sample:ver() of
-                cow1 -> n2o_cowboy:path(Req); % cowboy 1.0
-                cow2 -> #{path:=P}=Req, P     % cowboy 2.5
-           end,
+    #{path:=Path}=Req,
     Fix  = route_prefix(Path),
-    n2o:info(?MODULE,"Route: ~p~n",[{Fix,Path}]),
+    ?LOG_INFO("Route: ~p~n",[{Fix,Path}]),
     {ok, State, Cx#cx{path=Path,module=Fix}}.
 
 route_prefix(<<"/ws/",P/binary>>) -> route(P);

+ 1 - 1
priv/web/src/sample.app.src

@@ -1,5 +1,5 @@
 {application, sample,
-    [{description, "REVIEW WS Application"},
+    [{description, "sample WebSocket application"},
      {vsn, "5.11"},
      {registered, []},
      {applications, [public_key,asn1,kernel,stdlib,mnesia,

+ 6 - 12
priv/web/src/sample.erl

@@ -5,17 +5,11 @@
 main(A)    -> mad:main(A).
 stop(_)    -> ok.
 start()    -> start(normal,[]).
-start(_,_) -> case ver() of cow1 -> []; _ ->
-                   cowboy:start_clear(http, [{port, port()}],
-                      #{ env => #{dispatch => n2o_cowboy2:points()} })
-              end, supervisor:start_link({local,sample},sample,[]).
-init([])   -> kvs:join(), {ok, {{one_for_one, 5, 10}, ?MODULE:(ver())() }}.
-ver()      -> application:get_env(n2o,cowboy_spec,cow2).
-cow2()     -> [].
-cow1()     -> [spec()].
+start(_,_) -> cowboy:start_tls(http,n2o_cowboy:env(?MODULE),
+                 #{env=>#{dispatch=>n2o_cowboy2:points() }}),
+              supervisor:start_link({local,sample},sample,[]).
+init([])   -> kvs:join(), {ok, {{one_for_one, 5, 10}, [] }}.
 port()     -> application:get_env(n2o,port,8001).
-env()      -> [ { env, [ { dispatch, n2o_cowboy:points() } ] } ].
-spec()     -> ranch:child_spec(http,100,ranch_tcp,[{port,port()}],cowboy_protocol,env()).
 rebar3()   -> {ok,[{_,R,L}]}=file:consult(code:lib_dir(sample)++"/ebin/sample.app"),
-              [ application:ensure_started(X) || X <- proplists:get_value(applications,L,[]) ],
-              application:ensure_started(R).
+              [ application:start(X) || X <- proplists:get_value(applications,L,[]) ],
+              application:start(R).

+ 1 - 1
src/mad.app.src

@@ -1,6 +1,6 @@
 {application, mad,
  [{description, "MAD Manage Dependencies"},
-  {vsn, "5.4"},
+  {vsn, "5.5"},
   {registered, []},
   {applications, [kernel,stdlib,inets]},
   {env, []}]}.