iris/_examples/websocket/basic/browserify/bundle.js

1 line
17 KiB
JavaScript
Raw Normal View History

(function(){function b(d,e,g){function a(j,i){if(!e[j]){if(!d[j]){var f="function"==typeof require&&require;if(!i&&f)return f(j,!0);if(h)return h(j,!0);var c=new Error("Cannot find module '"+j+"'");throw c.code="MODULE_NOT_FOUND",c}var k=e[j]={exports:{}};d[j][0].call(k.exports,function(b){var c=d[j][1][b];return a(c||b)},k,k.exports,b,d,e,g)}return e[j].exports}for(var h="function"==typeof require&&require,c=0;c<g.length;c++)a(g[c]);return a}return b})()({1:[function(a){function b(a){i.innerHTML+=a+"\n"}function c(a){console.log(a),window.alert(a)}function d(a){a.emit("chat","Hello from browser(ify) client-side!");const c=document.getElementById("input"),d=document.getElementById("sendBtn");d.disabled=!1,d.onclick=function(){const d=c.value;c.value="",a.emit("chat",d),b("Me: "+d)}}const e=a("neffos.js");var f="https:"==document.location.protocol?"wss":"ws",g=document.location.port?":"+document.location.port:"",h=f+"://"+document.location.hostname+g+"/echo",i=document.getElementById("output");(async function(){try{const a=await e.dial(h,{default:{_OnNamespaceConnected:function(a,c){b("connected to namespace: "+c.Namespace),d(a)},_OnNamespaceDisconnect:function(a,c){b("disconnected from namespace: "+c.Namespace)},chat:function(a,c){b(c.Body)}}});a.connect("default")}catch(a){c(a)}})()},{"neffos.js":2}],2:[function(a,b,c){(function(d,e){function f(a){return!("_OnNamespaceConnect"!==a&&"_OnNamespaceConnected"!==a&&"_OnNamespaceDisconnect"!==a&&"_OnRoomJoin"!==a&&"_OnRoomJoined"!==a&&"_OnRoomLeave"!==a&&"_OnRoomLeft"!==a)}function g(a){return!(void 0!==a)||!(null!==a)||(""==a||"string"==typeof a||a instanceof String?0===a.length||""===a:!!(a instanceof Error)&&g(a.message))}function h(a){return JSON.stringify(a)}function i(a){return g(a)?"":a.replace(G,"@%!semicolon@%!")}function j(a){return g(a)?"":a.replace(H,";")}function k(a){if(a.IsNative&&g(a.wait))return a.Body;var b="0",c="0",d=a.Body||"";return a.isError&&(d=a.Err,b="1"),a.isNoOp&&(c="1"),[a.wait||"",i(a.Namespace),i(a.Room),i(a.Event),b,c,d].join(";")}function l(a,b,c){if(0==c)return[a];var d=a.split(b,c);if(d.length==c){var e=d.join(b)+b;return d.push(a.substr(e.length)),d}return[a]}function m(a,b){var c=new F;if(0==a.length)return c.isInvalid=!0,c;var d=l(a,";",6);if(7!=d.length)return b?(c.Event="_OnNativeMessage",c.Body=a):c.isInvalid=!0,c;c.wait=d[0],c.Namespace=j(d[1]),c.Room=j(d[2]),c.Event=j(d[3]),c.isError="1"==d[4]||!1,c.isNoOp="1"==d[5]||!1;var e=d[6];return g(e)?c.Body="":c.isError?c.Err=e:c.Body=e,c.isInvalid=!1,c.IsForced=!1,c.IsLocal=!1,c.IsNative=b&&"_OnNativeMessage"==c.Event||!1,c}function n(){if(!x){var a=d.hrtime();return"$"+1e9*a[0]+a[1]}var b=window.performance.now();return"$"+b.toString()}function o(a){return a+";".repeat(6)}function p(a,b){return a.events.has(b.Event)?a.events.get(b.Event)(a,b):a.events.has("_OnAnyEvent")?a.events.get("_OnAnyEvent")(a,b):null}function q(a){return null===a||a===void 0||"undefined"==typeof a}function r(a,b){if(q(a))return q(b)||b("connHandler is empty."),null;var c=new Map,d=new Map,e=0;if(Object.keys(a).forEach(function(b){e++;var f=a[b];if(f instanceof Function)d.set(b,f);else if(f instanceof Map)c.set(b,f);else{var g=new Map;Object.keys(f).forEach(function(a){g.set(a,f[a])}),c.set(b,g)}}),0<d.size){if(e!=d.size)return q(b)||b("all keys of connHandler should be events, mix of namespaces and event callbacks is not supported "+d.size+" vs total "+e),null;c.set("",d)}return c}function s(a,b){return a.has(b)?a.get(b):null}function t(a,b){if(q(a))return b;for(var c in a)if(a.hasOwnProperty(c)){var d=a[c];c=encodeURIComponent("X-Websocket-Header-"+c),d=encodeURIComponent(d);var e=c+"="+d;b=-1==b.indexOf("?")?-1==b.indexOf("#")?b+"?"+e:b.split("#")[0]+"?"+e+"#"+b.split("#")[1]:b.split("?")[0]+"?"+e+"&"+b.split("?")[1]}return b}function u(a,b,c){return-1==a.indexOf("ws")&&(a="ws://"+a),new Promise(function(d,e){WebSocket||e("WebSocket is not accessible through this browser.");var f=r(b,e);if(!q(f)){var h;x&&!q(c)&&c.headers&&(console.log(c),a=t(c.headers,a),c=c.protocols?c.protocols:void 0),h=new WebSocket(a,c);var