coolify/public/js/echo.js
2023-12-06 10:32:49 +01:00

3 lines
15 KiB
JavaScript

// Source: https://cdnjs.cloudflare.com/ajax/libs/laravel-echo/1.15.3/echo.iife.min.js
var Echo=function(){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function u(e,t,n){t&&i(e.prototype,t),n&&i(e,n),Object.defineProperty(e,"prototype",{writable:!1})}function r(){return(r=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n,i=arguments[t];for(n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e}).apply(this,arguments)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function a(e,t){return(a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function h(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");t=e;if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function l(n){var i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=s(n);return h(this,i?(e=s(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments))}}var f=function(){function e(){o(this,e)}return u(e,[{key:"listenForWhisper",value:function(e,t){return this.listen(".client-"+e,t)}},{key:"notification",value:function(e){return this.listen(".Illuminate\\Notifications\\Events\\BroadcastNotificationCreated",e)}},{key:"stopListeningForWhisper",value:function(e,t){return this.stopListening(".client-"+e,t)}}]),e}(),p=function(){function t(e){o(this,t),this.namespace=e}return u(t,[{key:"format",value:function(e){return"."===e.charAt(0)||"\\"===e.charAt(0)?e.substr(1):(e=this.namespace?this.namespace+"."+e:e).replace(/\./g,"\\")}},{key:"setNamespace",value:function(e){this.namespace=e}}]),t}(),v=function(){c(s,f);var r=l(s);function s(e,t,n){var i;return o(this,s),(i=r.call(this)).name=t,i.pusher=e,i.options=n,i.eventFormatter=new p(i.options.namespace),i.subscribe(),i}return u(s,[{key:"subscribe",value:function(){this.subscription=this.pusher.subscribe(this.name)}},{key:"unsubscribe",value:function(){this.pusher.unsubscribe(this.name)}},{key:"listen",value:function(e,t){return this.on(this.eventFormatter.format(e),t),this}},{key:"listenToAll",value:function(i){var r=this;return this.subscription.bind_global(function(e,t){var n;e.startsWith("pusher:")||(n=r.options.namespace.replace(/\./g,"\\"),n=e.startsWith(n)?e.substring(n.length+1):"."+e,i(n,t))}),this}},{key:"stopListening",value:function(e,t){return t?this.subscription.unbind(this.eventFormatter.format(e),t):this.subscription.unbind(this.eventFormatter.format(e)),this}},{key:"stopListeningToAll",value:function(e){return e?this.subscription.unbind_global(e):this.subscription.unbind_global(),this}},{key:"subscribed",value:function(e){return this.on("pusher:subscription_succeeded",function(){e()}),this}},{key:"error",value:function(t){return this.on("pusher:subscription_error",function(e){t(e)}),this}},{key:"on",value:function(e,t){return this.subscription.bind(e,t),this}}]),s}(),y=function(){c(t,v);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"whisper",value:function(e,t){return this.pusher.channels.channels[this.name].trigger("client-".concat(e),t),this}}]),t}(),k=function(){c(t,v);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"whisper",value:function(e,t){return this.pusher.channels.channels[this.name].trigger("client-".concat(e),t),this}}]),t}(),d=function(){c(t,v);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"here",value:function(e){return this.on("pusher:subscription_succeeded",function(t){e(Object.keys(t.members).map(function(e){return t.members[e]}))}),this}},{key:"joining",value:function(t){return this.on("pusher:member_added",function(e){t(e.info)}),this}},{key:"whisper",value:function(e,t){return this.pusher.channels.channels[this.name].trigger("client-".concat(e),t),this}},{key:"leaving",value:function(t){return this.on("pusher:member_removed",function(e){t(e.info)}),this}}]),t}(),b=function(){c(s,f);var r=l(s);function s(e,t,n){var i;return o(this,s),(i=r.call(this)).events={},i.listeners={},i.name=t,i.socket=e,i.options=n,i.eventFormatter=new p(i.options.namespace),i.subscribe(),i}return u(s,[{key:"subscribe",value:function(){this.socket.emit("subscribe",{channel:this.name,auth:this.options.auth||{}})}},{key:"unsubscribe",value:function(){this.unbind(),this.socket.emit("unsubscribe",{channel:this.name,auth:this.options.auth||{}})}},{key:"listen",value:function(e,t){return this.on(this.eventFormatter.format(e),t),this}},{key:"stopListening",value:function(e,t){return this.unbindEvent(this.eventFormatter.format(e),t),this}},{key:"subscribed",value:function(t){return this.on("connect",function(e){t(e)}),this}},{key:"error",value:function(e){return this}},{key:"on",value:function(n,e){var i=this;return this.listeners[n]=this.listeners[n]||[],this.events[n]||(this.events[n]=function(e,t){i.name===e&&i.listeners[n]&&i.listeners[n].forEach(function(e){return e(t)})},this.socket.on(n,this.events[n])),this.listeners[n].push(e),this}},{key:"unbind",value:function(){var t=this;Object.keys(this.events).forEach(function(e){t.unbindEvent(e)})}},{key:"unbindEvent",value:function(e,t){this.listeners[e]=this.listeners[e]||[],t&&(this.listeners[e]=this.listeners[e].filter(function(e){return e!==t})),t&&0!==this.listeners[e].length||(this.events[e]&&(this.socket.removeListener(e,this.events[e]),delete this.events[e]),delete this.listeners[e])}}]),s}(),m=function(){c(t,b);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"whisper",value:function(e,t){return this.socket.emit("client event",{channel:this.name,event:"client-".concat(e),data:t}),this}}]),t}(),g=function(){c(t,m);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"here",value:function(t){return this.on("presence:subscribed",function(e){t(e.map(function(e){return e.user_info}))}),this}},{key:"joining",value:function(t){return this.on("presence:joining",function(e){return t(e.user_info)}),this}},{key:"whisper",value:function(e,t){return this.socket.emit("client event",{channel:this.name,event:"client-".concat(e),data:t}),this}},{key:"leaving",value:function(t){return this.on("presence:leaving",function(e){return t(e.user_info)}),this}}]),t}(),w=function(){c(t,f);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"subscribe",value:function(){}},{key:"unsubscribe",value:function(){}},{key:"listen",value:function(e,t){return this}},{key:"listenToAll",value:function(e){return this}},{key:"stopListening",value:function(e,t){return this}},{key:"subscribed",value:function(e){return this}},{key:"error",value:function(e){return this}},{key:"on",value:function(e,t){return this}}]),t}(),j=function(){c(t,w);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"whisper",value:function(e,t){return this}}]),t}(),I=function(){c(t,w);var e=l(t);function t(){return o(this,t),e.apply(this,arguments)}return u(t,[{key:"here",value:function(e){return this}},{key:"joining",value:function(e){return this}},{key:"whisper",value:function(e,t){return this}},{key:"leaving",value:function(e){return this}}]),t}(),e=function(){function t(e){o(this,t),this._defaultOptions={auth:{headers:{}},authEndpoint:"/broadcasting/auth",userAuthentication:{endpoint:"/broadcasting/user-auth",headers:{}},broadcaster:"pusher",csrfToken:null,bearerToken:null,host:null,key:null,namespace:"App.Events"},this.setOptions(e),this.connect()}return u(t,[{key:"setOptions",value:function(e){this.options=r(this._defaultOptions,e);var t=this.csrfToken();return t&&(this.options.auth.headers["X-CSRF-TOKEN"]=t,this.options.userAuthentication.headers["X-CSRF-TOKEN"]=t),(t=this.options.bearerToken)&&(this.options.auth.headers.Authorization="Bearer "+t,this.options.userAuthentication.headers.Authorization="Bearer "+t),e}},{key:"csrfToken",value:function(){var e;return"undefined"!=typeof window&&window.Laravel&&window.Laravel.csrfToken?window.Laravel.csrfToken:this.options.csrfToken||("undefined"!=typeof document&&"function"==typeof document.querySelector&&(e=document.querySelector('meta[name="csrf-token"]'))?e.getAttribute("content"):null)}}]),t}(),O=function(){c(n,e);var t=l(n);function n(){var e;return o(this,n),(e=t.apply(this,arguments)).channels={},e}return u(n,[{key:"connect",value:function(){void 0!==this.options.client?this.pusher=this.options.client:this.options.Pusher?this.pusher=new this.options.Pusher(this.options.key,this.options):this.pusher=new Pusher(this.options.key,this.options)}},{key:"signin",value:function(){this.pusher.signin()}},{key:"listen",value:function(e,t,n){return this.channel(e).listen(t,n)}},{key:"channel",value:function(e){return this.channels[e]||(this.channels[e]=new v(this.pusher,e,this.options)),this.channels[e]}},{key:"privateChannel",value:function(e){return this.channels["private-"+e]||(this.channels["private-"+e]=new y(this.pusher,"private-"+e,this.options)),this.channels["private-"+e]}},{key:"encryptedPrivateChannel",value:function(e){return this.channels["private-encrypted-"+e]||(this.channels["private-encrypted-"+e]=new k(this.pusher,"private-encrypted-"+e,this.options)),this.channels["private-encrypted-"+e]}},{key:"presenceChannel",value:function(e){return this.channels["presence-"+e]||(this.channels["presence-"+e]=new d(this.pusher,"presence-"+e,this.options)),this.channels["presence-"+e]}},{key:"leave",value:function(e){var n=this;[e,"private-"+e,"private-encrypted-"+e,"presence-"+e].forEach(function(e,t){n.leaveChannel(e)})}},{key:"leaveChannel",value:function(e){this.channels[e]&&(this.channels[e].unsubscribe(),delete this.channels[e])}},{key:"socketId",value:function(){return this.pusher.connection.socket_id}},{key:"disconnect",value:function(){this.pusher.disconnect()}}]),n}(),C=function(){c(n,e);var t=l(n);function n(){var e;return o(this,n),(e=t.apply(this,arguments)).channels={},e}return u(n,[{key:"connect",value:function(){var e=this,t=this.getSocketIO();return this.socket=t(this.options.host,this.options),this.socket.on("reconnect",function(){Object.values(e.channels).forEach(function(e){e.subscribe()})}),this.socket}},{key:"getSocketIO",value:function(){if(void 0!==this.options.client)return this.options.client;if("undefined"!=typeof io)return io;throw new Error("Socket.io client not found. Should be globally available or passed via options.client")}},{key:"listen",value:function(e,t,n){return this.channel(e).listen(t,n)}},{key:"channel",value:function(e){return this.channels[e]||(this.channels[e]=new b(this.socket,e,this.options)),this.channels[e]}},{key:"privateChannel",value:function(e){return this.channels["private-"+e]||(this.channels["private-"+e]=new m(this.socket,"private-"+e,this.options)),this.channels["private-"+e]}},{key:"presenceChannel",value:function(e){return this.channels["presence-"+e]||(this.channels["presence-"+e]=new g(this.socket,"presence-"+e,this.options)),this.channels["presence-"+e]}},{key:"leave",value:function(e){var t=this;[e,"private-"+e,"presence-"+e].forEach(function(e){t.leaveChannel(e)})}},{key:"leaveChannel",value:function(e){this.channels[e]&&(this.channels[e].unsubscribe(),delete this.channels[e])}},{key:"socketId",value:function(){return this.socket.id}},{key:"disconnect",value:function(){this.socket.disconnect()}}]),n}(),_=function(){c(n,e);var t=l(n);function n(){var e;return o(this,n),(e=t.apply(this,arguments)).channels={},e}return u(n,[{key:"connect",value:function(){}},{key:"listen",value:function(e,t,n){return new w}},{key:"channel",value:function(e){return new w}},{key:"privateChannel",value:function(e){return new j}},{key:"encryptedPrivateChannel",value:function(e){return new j}},{key:"presenceChannel",value:function(e){return new I}},{key:"leave",value:function(e){}},{key:"leaveChannel",value:function(e){}},{key:"socketId",value:function(){return"fake-socket-id"}},{key:"disconnect",value:function(){}}]),n}();return function(){function t(e){o(this,t),this.options=e,this.connect(),this.options.withoutInterceptors||this.registerInterceptors()}return u(t,[{key:"channel",value:function(e){return this.connector.channel(e)}},{key:"connect",value:function(){"pusher"==this.options.broadcaster?this.connector=new O(this.options):"socket.io"==this.options.broadcaster?this.connector=new C(this.options):"null"==this.options.broadcaster?this.connector=new _(this.options):"function"==typeof this.options.broadcaster&&(this.connector=new this.options.broadcaster(this.options))}},{key:"disconnect",value:function(){this.connector.disconnect()}},{key:"join",value:function(e){return this.connector.presenceChannel(e)}},{key:"leave",value:function(e){this.connector.leave(e)}},{key:"leaveChannel",value:function(e){this.connector.leaveChannel(e)}},{key:"leaveAllChannels",value:function(){for(var e in this.connector.channels)this.leaveChannel(e)}},{key:"listen",value:function(e,t,n){return this.connector.listen(e,t,n)}},{key:"private",value:function(e){return this.connector.privateChannel(e)}},{key:"encryptedPrivate",value:function(e){return this.connector.encryptedPrivateChannel(e)}},{key:"socketId",value:function(){return this.connector.socketId()}},{key:"registerInterceptors",value:function(){"function"==typeof Vue&&Vue.http&&this.registerVueRequestInterceptor(),"function"==typeof axios&&this.registerAxiosRequestInterceptor(),"function"==typeof jQuery&&this.registerjQueryAjaxSetup(),"object"===("undefined"==typeof Turbo?"undefined":n(Turbo))&&this.registerTurboRequestInterceptor()}},{key:"registerVueRequestInterceptor",value:function(){var n=this;Vue.http.interceptors.push(function(e,t){n.socketId()&&e.headers.set("X-Socket-ID",n.socketId()),t()})}},{key:"registerAxiosRequestInterceptor",value:function(){var t=this;axios.interceptors.request.use(function(e){return t.socketId()&&(e.headers["X-Socket-Id"]=t.socketId()),e})}},{key:"registerjQueryAjaxSetup",value:function(){var i=this;void 0!==jQuery.ajax&&jQuery.ajaxPrefilter(function(e,t,n){i.socketId()&&n.setRequestHeader("X-Socket-Id",i.socketId())})}},{key:"registerTurboRequestInterceptor",value:function(){var t=this;document.addEventListener("turbo:before-fetch-request",function(e){e.detail.fetchOptions.headers["X-Socket-Id"]=t.socketId()})}}]),t}()}();