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

1 line
18 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){j.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)}}async function e(){try{const a=await f.dial(i,{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)}}const f=a("neffos.js");var g="https:"==document.location.protocol?"wss":"ws",h=document.location.port?":"+document.location.port:"",i=g+"://"+document.location.hostname+h+"/echo";{i+="?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjozMjEzMjF9.8waEX7-vPKACa-Soi1pQvW3Rl8QY-SUFcHKTLZI4mvU"}var j=document.getElementById("output");e()},{"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(K,"@%!semicolon@%!")}function j(a){return g(a)?"":a.replace(L,";")}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 J;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(!A){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 v(a,b,0,c)}function v(a,b,c,d){return-1==a.indexOf("ws")&&(a="ws://"+a),new Promise(function(e,f){W