From a265da66e9fd37d8844016bad20f8902b08e00f5 Mon Sep 17 00:00:00 2001 From: Viktor Date: Mon, 25 Jul 2022 18:52:03 +0300 Subject: [PATCH] build 2.1.0 --- dist/build.js | 2 +- dist/build.js.map | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/build.js b/dist/build.js index 0e25462..11a2f0d 100755 --- a/dist/build.js +++ b/dist/build.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueNativeSock=e():t.VueNativeSock=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function o(t,e){for(var o=0;oc});const n=new(function(){function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.listeners=new Map}var e,n,r;return e=t,n=[{key:"addListener",value:function(t,e,o){return"function"==typeof e&&(this.listeners.has(t)||this.listeners.set(t,[]),this.listeners.get(t).push({callback:e,vm:o}),!0)}},{key:"removeListener",value:function(t,e,o){var n,r=this.listeners.get(t);return!!(r&&r.length&&(n=r.reduce((function(t,n,r){return"function"==typeof n.callback&&n.callback===e&&n.vm===o&&(t=r),t}),-1))>-1)&&(r.splice(n,1),this.listeners.set(t,r),!0)}},{key:"emit",value:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),n=1;n1&&void 0!==arguments[1]?arguments[1]:{};if(r(this,t),this.format=o.format&&o.format.toLowerCase(),e.startsWith("//")){var n="https:"===window.location.protocol?"wss":"ws";e="".concat(n,":").concat(e)}this.connectionUrl=e,this.opts=o,this.reconnection=this.opts.reconnection||!1,this.reconnectionAttempts=this.opts.reconnectionAttempts||1/0,this.reconnectionDelay=this.opts.reconnectionDelay||1e3,this.reconnectTimeoutId=0,this.reconnectionCount=0,this.passToStoreHandler=this.opts.passToStoreHandler||!1,this.connect(e,o),o.store&&(this.store=o.store),o.mutations&&(this.mutations=o.mutations),this.onEvent()}var e,o,s;return e=t,o=[{key:"connect",value:function(t){var e=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=o.protocol||"";return this.WebSocket=o.WebSocket||(""===n?new WebSocket(t):new WebSocket(t,n)),"json"===this.format&&("sendObj"in this.WebSocket||(this.WebSocket.sendObj=function(t){return e.WebSocket.send(JSON.stringify(t))})),this.WebSocket}},{key:"reconnect",value:function(){var t=this;this.reconnectionCount<=this.reconnectionAttempts?(this.reconnectionCount++,clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=setTimeout((function(){t.store&&t.passToStore("SOCKET_RECONNECT",t.reconnectionCount),t.connect(t.connectionUrl,t.opts),t.onEvent()}),this.reconnectionDelay)):this.store&&this.passToStore("SOCKET_RECONNECT_ERROR",!0)}},{key:"onEvent",value:function(){var t=this;["onmessage","onclose","onerror","onopen"].forEach((function(e){t.WebSocket[e]=function(o){n.emit(e,o),t.store&&t.passToStore("SOCKET_"+e,o),t.reconnection&&"onopen"===e&&(t.opts.$setInstance(o.currentTarget),t.reconnectionCount=0),t.reconnection&&"onclose"===e&&t.reconnect()}}))}},{key:"passToStore",value:function(t,e){this.passToStoreHandler?this.passToStoreHandler(t,e,this.defaultPassToStore.bind(this)):this.defaultPassToStore(t,e)}},{key:"defaultPassToStore",value:function(t,e){if(t.startsWith("SOCKET_")){var o="commit",n=t.toUpperCase(),r=e;"json"===this.format&&e.data&&((r=JSON.parse(e.data)).mutation?n=[r.namespace||"",r.mutation].filter((function(t){return!!t})).join("/"):r.action&&(o="dispatch",n=[r.namespace||"",r.action].filter((function(t){return!!t})).join("/"))),this.mutations&&(n=this.mutations[n]||n),this.store[o](n,r)}}}],o&&i(e.prototype,o),s&&i(e,s),Object.defineProperty(e,"prototype",{writable:!1}),t}();const c={install:function(t,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e&&!o.connectManually)throw new Error("[vue-native-socket] cannot locate connection");var r=null;o.$setInstance=function(e){t.prototype.$socket=e},o.connectManually?(t.prototype.$connect=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o;i.$setInstance=o.$setInstance,r=new s(n,i),t.prototype.$socket=r.WebSocket},t.prototype.$disconnect=function(){r&&r.reconnection&&(r.reconnection=!1),t.prototype.$socket&&(t.prototype.$socket.close(),delete t.prototype.$socket)}):(r=new s(e,o),t.prototype.$socket=r.WebSocket);var i="undefined"!=typeof Proxy&&"function"==typeof Proxy&&/native code/.test(Proxy.toString());t.mixin({created:function(){var t=this,e=this,o=this.$options.sockets;i?(this.$options.sockets=new Proxy({},{set:function(t,o,r){return n.addListener(o,r,e),t[o]=r,!0},deleteProperty:function(t,o){return n.removeListener(o,e.$options.sockets[o],e),delete t.key,!0}}),o&&Object.keys(o).forEach((function(e){t.$options.sockets[e]=o[e]}))):(Object.seal(this.$options.sockets),o&&Object.keys(o).forEach((function(t){n.addListener(t,o[t],e)})))},beforeDestroy:function(){var t=this;if(i){var e=this.$options.sockets;e&&Object.keys(e).forEach((function(e){delete t.$options.sockets[e]}))}}})}};return e})())); +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.VueNativeSock=e():t.VueNativeSock=e()}(self,(()=>(()=>{"use strict";var t={d:(e,o)=>{for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var o=0;oc});const i=new(function(){function t(){o(this,t),this.listeners=new Map}return s(t,[{key:"addListener",value:function(t,e,o){return"function"==typeof e&&(this.listeners.has(t)||this.listeners.set(t,[]),this.listeners.get(t).push({callback:e,vm:o}),!0)}},{key:"removeListener",value:function(t,e,o){var n,s=this.listeners.get(t);return!!(s&&s.length&&(n=s.reduce((function(t,n,s){return"function"==typeof n.callback&&n.callback===e&&n.vm===o&&(t=s),t}),-1))>-1)&&(s.splice(n,1),this.listeners.set(t,s),!0)}},{key:"emit",value:function(t){for(var e=arguments.length,o=new Array(e>1?e-1:0),n=1;n1&&void 0!==arguments[1]?arguments[1]:{};if(o(this,t),this.format=n.format&&n.format.toLowerCase(),e.startsWith("//")){var s="https:"===window.location.protocol?"wss":"ws";e="".concat(s,":").concat(e)}this.connectionUrl=e,this.opts=n,this.reconnection=this.opts.reconnection||!1,this.reconnectionAttempts=this.opts.reconnectionAttempts||1/0,this.reconnectionDelay=this.opts.reconnectionDelay||1e3,this.reconnectTimeoutId=0,this.reconnectionCount=0,this.passToStoreHandler=this.opts.passToStoreHandler||!1,this.connect(e,n),n.store&&(this.store=n.store),n.mutations&&(this.mutations=n.mutations),this.onEvent()}return s(t,[{key:"connect",value:function(t){var e=this,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=o.protocol||"";return this.WebSocket=o.WebSocket||(""===n?new WebSocket(t):new WebSocket(t,n)),"json"===this.format&&("sendObj"in this.WebSocket||(this.WebSocket.sendObj=function(t){return e.WebSocket.send(JSON.stringify(t))})),this.WebSocket}},{key:"reconnect",value:function(){var t=this;this.reconnectionCount<=this.reconnectionAttempts?(this.reconnectionCount++,clearTimeout(this.reconnectTimeoutId),this.reconnectTimeoutId=setTimeout((function(){t.store&&t.passToStore("SOCKET_RECONNECT",t.reconnectionCount),t.connect(t.connectionUrl,t.opts),t.onEvent()}),this.reconnectionDelay)):this.store&&this.passToStore("SOCKET_RECONNECT_ERROR",!0)}},{key:"onEvent",value:function(){var t=this;["onmessage","onclose","onerror","onopen"].forEach((function(e){t.WebSocket[e]=function(o){i.emit(e,o),t.store&&t.passToStore("SOCKET_"+e,o),t.reconnection&&"onopen"===e&&(t.opts.$setInstance(o.currentTarget),t.reconnectionCount=0),t.reconnection&&"onclose"===e&&t.reconnect()}}))}},{key:"passToStore",value:function(t,e){this.passToStoreHandler?this.passToStoreHandler(t,e,this.defaultPassToStore.bind(this)):this.defaultPassToStore(t,e)}},{key:"defaultPassToStore",value:function(t,e){if(t.startsWith("SOCKET_")){var o="commit",n=t.toUpperCase(),s=e;"json"===this.format&&e.data&&((s=JSON.parse(e.data)).mutation?n=[s.namespace||"",s.mutation].filter((function(t){return!!t})).join("/"):s.action&&(o="dispatch",n=[s.namespace||"",s.action].filter((function(t){return!!t})).join("/"))),this.mutations&&(n=this.mutations[n]||n),this.store[o](n,s)}}}]),t}();const c={install:function(t,e){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if(!e&&!o.connectManually)throw new Error("[vue-native-socket] cannot locate connection");var n=null;o.$setInstance=function(e){t.prototype.$socket=e},o.connectManually?(t.prototype.$connect=function(){var s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o;i.$setInstance=o.$setInstance,n=new r(s,i),t.prototype.$socket=n.WebSocket},t.prototype.$disconnect=function(){n&&n.reconnection&&(n.reconnection=!1,clearTimeout(n.reconnectTimeoutId)),t.prototype.$socket&&(t.prototype.$socket.close(),delete t.prototype.$socket)}):(n=new r(e,o),t.prototype.$socket=n.WebSocket);var s="undefined"!=typeof Proxy&&"function"==typeof Proxy&&/native code/.test(Proxy.toString());t.mixin({created:function(){var t=this,e=this,o=this.$options.sockets;s?(this.$options.sockets=new Proxy({},{set:function(t,o,n){return i.addListener(o,n,e),t[o]=n,!0},deleteProperty:function(t,o){return i.removeListener(o,e.$options.sockets[o],e),delete t.key,!0}}),o&&Object.keys(o).forEach((function(e){t.$options.sockets[e]=o[e]}))):(Object.seal(this.$options.sockets),o&&Object.keys(o).forEach((function(t){i.addListener(t,o[t],e)})))},beforeDestroy:function(){var t=this;if(s){var e=this.$options.sockets;e&&Object.keys(e).forEach((function(e){delete t.$options.sockets[e]}))}}})}};return e})())); //# sourceMappingURL=build.js.map \ No newline at end of file diff --git a/dist/build.js.map b/dist/build.js.map index 99541e2..4b7e83a 100755 --- a/dist/build.js.map +++ b/dist/build.js.map @@ -1 +1 @@ -{"version":3,"file":"build.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,yMC2C9D,YAhDMC,WACJ,c,4FAAe,SACbC,KAAKC,UAAY,IAAIC,GACtB,C,iDAED,SAAaC,EAAOC,EAAUC,GAC5B,MAAwB,mBAAbD,IACTJ,KAAKC,UAAUK,IAAIH,IAAUH,KAAKC,UAAUM,IAAIJ,EAAO,IACvDH,KAAKC,UAAUX,IAAIa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gD,EAAIzE,UAAU+E,QAAUF,EAASjC,WAEnC,IAAMyC,EAA4B,oBAAVC,OAA0C,mBAAVA,OAAwB,cAAcC,KAAKD,MAAME,YAEzGf,EAAIgB,MAAM,CACRC,QADQ,WACG,WACH9E,EAAKL,KACLoF,EAAUpF,KAAKqF,SAASD,QAE1BN,GACF9E,KAAKqF,SAASD,QAAU,IAAIL,MAAM,CAAC,EAAG,CACpCxE,IADoC,SAC/B+C,EAAQrE,EAAKa,GAGhB,OAFAC,EAAAA,YAAoBd,EAAKa,EAAOO,GAChCiD,EAAOrE,GAAOa,GACP,CACR,EACDwF,eANoC,SAMpBhC,EAAQrE,GAGtB,OAFAc,EAAAA,eAAuBd,EAAKoB,EAAGgF,SAASD,QAAQnG,GAAMoB,UAC/CiD,EAAOrE,KACP,CACR,IAECmG,GACFjG,OAAOoG,KAAKH,GAASpE,SAAQ,SAAC/B,GAC5B,EAAKoG,SAASD,QAAQnG,GAAOmG,EAAQnG,EACtC,MAGHE,OAAOqG,KAAKxF,KAAKqF,SAASD,SAGtBA,GACFjG,OAAOoG,KAAKH,GAASpE,SAAQ,SAAA/B,GAC3Bc,EAAAA,YAAoBd,EAAKmG,EAAQnG,GAAMoB,EACxC,IAGN,EACDoF,cAlCQ,WAkCS,WACf,GAAIX,EAAU,CACZ,IAAMM,EAAUpF,KAAKqF,SAASD,QAE1BA,GACFjG,OAAOoG,KAAKH,GAASpE,SAAQ,SAAC/B,UACrB,EAAKoG,SAASD,QAAQnG,EAC9B,GAEJ,CACF,GAEJ,G","sources":["webpack://VueNativeSock/webpack/universalModuleDefinition","webpack://VueNativeSock/webpack/bootstrap","webpack://VueNativeSock/webpack/runtime/define property getters","webpack://VueNativeSock/webpack/runtime/hasOwnProperty shorthand","webpack://VueNativeSock/webpack/runtime/make namespace object","webpack://VueNativeSock/./src/Emitter.js","webpack://VueNativeSock/./src/Observer.js","webpack://VueNativeSock/./src/Main.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VueNativeSock\"] = factory();\n\telse\n\t\troot[\"VueNativeSock\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","class Emitter {\n constructor () {\n this.listeners = new Map()\n }\n\n addListener (label, callback, vm) {\n if (typeof callback === 'function') {\n this.listeners.has(label) || this.listeners.set(label, [])\n this.listeners.get(label).push({ callback, vm })\n return true\n }\n return false\n }\n\n removeListener (label, callback, vm) {\n const listeners = this.listeners.get(label)\n let index\n\n if (listeners && listeners.length) {\n index = listeners.reduce((i, listener, index) => {\n if (typeof listener.callback === 'function' && listener.callback === callback && listener.vm === vm) {\n i = index\n }\n return i\n }, -1)\n\n if (index > -1) {\n listeners.splice(index, 1)\n this.listeners.set(label, listeners)\n return true\n }\n }\n return false\n }\n\n emit (label, ...args) {\n const listeners = this.listeners.get(label)\n\n if (listeners && listeners.length) {\n listeners.forEach((listener) => {\n listener.callback.call(listener.vm, ...args)\n })\n return true\n }\n return false\n }\n}\n\nexport default new Emitter()\n","import Emitter from './Emitter'\n\nexport default class {\n constructor (connectionUrl, opts = {}) {\n this.format = opts.format && opts.format.toLowerCase()\n\n if (connectionUrl.startsWith('//')) {\n const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws'\n connectionUrl = `${scheme}:${connectionUrl}`\n }\n\n this.connectionUrl = connectionUrl\n this.opts = opts\n\n this.reconnection = this.opts.reconnection || false\n this.reconnectionAttempts = this.opts.reconnectionAttempts || Infinity\n this.reconnectionDelay = this.opts.reconnectionDelay || 1000\n this.reconnectTimeoutId = 0\n this.reconnectionCount = 0\n\n this.passToStoreHandler = this.opts.passToStoreHandler || false\n\n this.connect(connectionUrl, opts)\n\n if (opts.store) { this.store = opts.store }\n if (opts.mutations) { this.mutations = opts.mutations }\n this.onEvent()\n }\n\n connect (connectionUrl, opts = {}) {\n const protocol = opts.protocol || ''\n this.WebSocket = opts.WebSocket || (protocol === '' ? new WebSocket(connectionUrl) : new WebSocket(connectionUrl, protocol))\n if (this.format === 'json') {\n if (!('sendObj' in this.WebSocket)) {\n this.WebSocket.sendObj = (obj) => this.WebSocket.send(JSON.stringify(obj))\n }\n }\n\n return this.WebSocket\n }\n\n reconnect () {\n if (this.reconnectionCount <= this.reconnectionAttempts) {\n this.reconnectionCount++\n clearTimeout(this.reconnectTimeoutId)\n\n this.reconnectTimeoutId = setTimeout(() => {\n if (this.store) { this.passToStore('SOCKET_RECONNECT', this.reconnectionCount) }\n\n this.connect(this.connectionUrl, this.opts)\n this.onEvent()\n }, this.reconnectionDelay)\n } else {\n if (this.store) { this.passToStore('SOCKET_RECONNECT_ERROR', true) }\n }\n }\n\n onEvent () {\n ['onmessage', 'onclose', 'onerror', 'onopen'].forEach((eventType) => {\n this.WebSocket[eventType] = (event) => {\n Emitter.emit(eventType, event)\n\n if (this.store) { this.passToStore('SOCKET_' + eventType, event) }\n\n if (this.reconnection && eventType === 'onopen') {\n this.opts.$setInstance(event.currentTarget)\n this.reconnectionCount = 0\n }\n\n if (this.reconnection && eventType === 'onclose') { this.reconnect() }\n }\n })\n }\n\n passToStore (eventName, event) {\n if (this.passToStoreHandler) {\n this.passToStoreHandler(eventName, event, this.defaultPassToStore.bind(this))\n } else {\n this.defaultPassToStore(eventName, event)\n }\n }\n\n defaultPassToStore (eventName, event) {\n if (!eventName.startsWith('SOCKET_')) { return }\n let method = 'commit'\n let target = eventName.toUpperCase()\n let msg = event\n if (this.format === 'json' && event.data) {\n msg = JSON.parse(event.data)\n if (msg.mutation) {\n target = [msg.namespace || '', msg.mutation].filter((e) => !!e).join('/')\n } else if (msg.action) {\n method = 'dispatch'\n target = [msg.namespace || '', msg.action].filter((e) => !!e).join('/')\n }\n }\n if (this.mutations) {\n target = this.mutations[target] || target\n }\n this.store[method](target, msg)\n }\n}\n","import Observer from './Observer'\nimport Emitter from './Emitter'\n\nexport default {\n\n install (Vue, connection, opts = {}) {\n if (!connection && !opts.connectManually) { throw new Error('[vue-native-socket] cannot locate connection') }\n\n let observer = null\n\n opts.$setInstance = (wsInstance) => {\n Vue.prototype.$socket = wsInstance\n }\n\n if (opts.connectManually) {\n Vue.prototype.$connect = (connectionUrl = connection, connectionOpts = opts) => {\n connectionOpts.$setInstance = opts.$setInstance\n observer = new Observer(connectionUrl, connectionOpts)\n Vue.prototype.$socket = observer.WebSocket\n }\n\n Vue.prototype.$disconnect = () => {\n if (observer && observer.reconnection) { observer.reconnection = false }\n if (Vue.prototype.$socket) {\n Vue.prototype.$socket.close()\n delete Vue.prototype.$socket\n }\n }\n } else {\n observer = new Observer(connection, opts)\n Vue.prototype.$socket = observer.WebSocket\n }\n const hasProxy = typeof Proxy !== 'undefined' && typeof Proxy === 'function' && /native code/.test(Proxy.toString())\n\n Vue.mixin({\n created () {\n const vm = this\n const sockets = this.$options.sockets\n\n if (hasProxy) {\n this.$options.sockets = new Proxy({}, {\n set (target, key, value) {\n Emitter.addListener(key, value, vm)\n target[key] = value\n return true\n },\n deleteProperty (target, key) {\n Emitter.removeListener(key, vm.$options.sockets[key], vm)\n delete target.key\n return true\n }\n })\n if (sockets) {\n Object.keys(sockets).forEach((key) => {\n this.$options.sockets[key] = sockets[key]\n })\n }\n } else {\n Object.seal(this.$options.sockets)\n\n // if !hasProxy need addListener\n if (sockets) {\n Object.keys(sockets).forEach(key => {\n Emitter.addListener(key, sockets[key], vm)\n })\n }\n }\n },\n beforeDestroy () {\n if (hasProxy) {\n const sockets = this.$options.sockets\n\n if (sockets) {\n Object.keys(sockets).forEach((key) => {\n delete this.$options.sockets[key]\n })\n }\n }\n }\n })\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","Emitter","this","listeners","Map","label","callback","vm","has","set","push","index","length","reduce","i","listener","splice","args","forEach","connectionUrl","opts","format","toLowerCase","startsWith","scheme","window","location","protocol","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectTimeoutId","reconnectionCount","passToStoreHandler","connect","store","mutations","onEvent","WebSocket","sendObj","send","JSON","stringify","clearTimeout","setTimeout","passToStore","eventType","event","$setInstance","currentTarget","reconnect","eventName","defaultPassToStore","bind","method","target","toUpperCase","msg","data","parse","mutation","namespace","filter","e","join","action","install","Vue","connection","connectManually","Error","observer","wsInstance","$socket","$connect","connectionOpts","Observer","$disconnect","close","hasProxy","Proxy","test","toString","mixin","created","sockets","$options","deleteProperty","keys","seal","beforeDestroy"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"build.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAuB,cAAID,IAE3BD,EAAoB,cAAIC,GACzB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAA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,QAAU,IAAIL,MAAM,CAAC,EAAG,CACpCrE,IADoC,SAC/BlB,EAAQnB,EAAKa,GAGhB,OAFAgB,EAAAA,YAAoB7B,EAAKa,EAAOsB,GAChChB,EAAOnB,GAAOa,GACP,CACR,EACDoG,eANoC,SAMpB9F,EAAQnB,GAGtB,OAFA6B,EAAAA,eAAuB7B,EAAKmC,EAAG6E,SAASD,QAAQ/G,GAAMmC,UAC/ChB,EAAOnB,KACP,CACR,IAEC+G,GACF7G,OAAOgH,KAAKH,GAASnE,SAAQ,SAAC5C,GAC5B,EAAKgH,SAASD,QAAQ/G,GAAO+G,EAAQ/G,EACtC,MAGHE,OAAOiH,KAAKrF,KAAKkF,SAASD,SAGtBA,GACF7G,OAAOgH,KAAKH,GAASnE,SAAQ,SAAA5C,GAC3B6B,EAAAA,YAAoB7B,EAAK+G,EAAQ/G,GAAMmC,EACxC,IAGN,EACDiF,cAlCQ,WAkCS,WACf,GAAIX,EAAU,CACZ,IAAMM,EAAUjF,KAAKkF,SAASD,QAE1BA,GACF7G,OAAOgH,KAAKH,GAASnE,SAAQ,SAAC5C,UACrB,EAAKgH,SAASD,QAAQ/G,EAC9B,GAEJ,CACF,GAEJ,G","sources":["webpack://VueNativeSock/webpack/universalModuleDefinition","webpack://VueNativeSock/webpack/bootstrap","webpack://VueNativeSock/webpack/runtime/define property getters","webpack://VueNativeSock/webpack/runtime/hasOwnProperty shorthand","webpack://VueNativeSock/webpack/runtime/make namespace object","webpack://VueNativeSock/./node_modules/@babel/runtime/helpers/esm/classCallCheck.js","webpack://VueNativeSock/./node_modules/@babel/runtime/helpers/esm/createClass.js","webpack://VueNativeSock/./src/Emitter.js","webpack://VueNativeSock/./src/Observer.js","webpack://VueNativeSock/./src/Main.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VueNativeSock\"] = factory();\n\telse\n\t\troot[\"VueNativeSock\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export default function _classCallCheck(instance, Constructor) {\n if (!(instance instanceof Constructor)) {\n throw new TypeError(\"Cannot call a class as a function\");\n }\n}","function _defineProperties(target, props) {\n for (var i = 0; i < props.length; i++) {\n var descriptor = props[i];\n descriptor.enumerable = descriptor.enumerable || false;\n descriptor.configurable = true;\n if (\"value\" in descriptor) descriptor.writable = true;\n Object.defineProperty(target, descriptor.key, descriptor);\n }\n}\n\nexport default function _createClass(Constructor, protoProps, staticProps) {\n if (protoProps) _defineProperties(Constructor.prototype, protoProps);\n if (staticProps) _defineProperties(Constructor, staticProps);\n Object.defineProperty(Constructor, \"prototype\", {\n writable: false\n });\n return Constructor;\n}","class Emitter {\n constructor () {\n this.listeners = new Map()\n }\n\n addListener (label, callback, vm) {\n if (typeof callback === 'function') {\n this.listeners.has(label) || this.listeners.set(label, [])\n this.listeners.get(label).push({ callback, vm })\n return true\n }\n return false\n }\n\n removeListener (label, callback, vm) {\n const listeners = this.listeners.get(label)\n let index\n\n if (listeners && listeners.length) {\n index = listeners.reduce((i, listener, index) => {\n if (typeof listener.callback === 'function' && listener.callback === callback && listener.vm === vm) {\n i = index\n }\n return i\n }, -1)\n\n if (index > -1) {\n listeners.splice(index, 1)\n this.listeners.set(label, listeners)\n return true\n }\n }\n return false\n }\n\n emit (label, ...args) {\n const listeners = this.listeners.get(label)\n\n if (listeners && listeners.length) {\n listeners.forEach((listener) => {\n listener.callback.call(listener.vm, ...args)\n })\n return true\n }\n return false\n }\n}\n\nexport default new Emitter()\n","import Emitter from './Emitter'\n\nexport default class {\n constructor (connectionUrl, opts = {}) {\n this.format = opts.format && opts.format.toLowerCase()\n\n if (connectionUrl.startsWith('//')) {\n const scheme = window.location.protocol === 'https:' ? 'wss' : 'ws'\n connectionUrl = `${scheme}:${connectionUrl}`\n }\n\n this.connectionUrl = connectionUrl\n this.opts = opts\n\n this.reconnection = this.opts.reconnection || false\n this.reconnectionAttempts = this.opts.reconnectionAttempts || Infinity\n this.reconnectionDelay = this.opts.reconnectionDelay || 1000\n this.reconnectTimeoutId = 0\n this.reconnectionCount = 0\n\n this.passToStoreHandler = this.opts.passToStoreHandler || false\n\n this.connect(connectionUrl, opts)\n\n if (opts.store) { this.store = opts.store }\n if (opts.mutations) { this.mutations = opts.mutations }\n this.onEvent()\n }\n\n connect (connectionUrl, opts = {}) {\n const protocol = opts.protocol || ''\n this.WebSocket = opts.WebSocket || (protocol === '' ? new WebSocket(connectionUrl) : new WebSocket(connectionUrl, protocol))\n if (this.format === 'json') {\n if (!('sendObj' in this.WebSocket)) {\n this.WebSocket.sendObj = (obj) => this.WebSocket.send(JSON.stringify(obj))\n }\n }\n\n return this.WebSocket\n }\n\n reconnect () {\n if (this.reconnectionCount <= this.reconnectionAttempts) {\n this.reconnectionCount++\n clearTimeout(this.reconnectTimeoutId)\n\n this.reconnectTimeoutId = setTimeout(() => {\n if (this.store) { this.passToStore('SOCKET_RECONNECT', this.reconnectionCount) }\n\n this.connect(this.connectionUrl, this.opts)\n this.onEvent()\n }, this.reconnectionDelay)\n } else {\n if (this.store) { this.passToStore('SOCKET_RECONNECT_ERROR', true) }\n }\n }\n\n onEvent () {\n ['onmessage', 'onclose', 'onerror', 'onopen'].forEach((eventType) => {\n this.WebSocket[eventType] = (event) => {\n Emitter.emit(eventType, event)\n\n if (this.store) { this.passToStore('SOCKET_' + eventType, event) }\n\n if (this.reconnection && eventType === 'onopen') {\n this.opts.$setInstance(event.currentTarget)\n this.reconnectionCount = 0\n }\n\n if (this.reconnection && eventType === 'onclose') { this.reconnect() }\n }\n })\n }\n\n passToStore (eventName, event) {\n if (this.passToStoreHandler) {\n this.passToStoreHandler(eventName, event, this.defaultPassToStore.bind(this))\n } else {\n this.defaultPassToStore(eventName, event)\n }\n }\n\n defaultPassToStore (eventName, event) {\n if (!eventName.startsWith('SOCKET_')) { return }\n let method = 'commit'\n let target = eventName.toUpperCase()\n let msg = event\n if (this.format === 'json' && event.data) {\n msg = JSON.parse(event.data)\n if (msg.mutation) {\n target = [msg.namespace || '', msg.mutation].filter((e) => !!e).join('/')\n } else if (msg.action) {\n method = 'dispatch'\n target = [msg.namespace || '', msg.action].filter((e) => !!e).join('/')\n }\n }\n if (this.mutations) {\n target = this.mutations[target] || target\n }\n this.store[method](target, msg)\n }\n}\n","import Observer from './Observer'\nimport Emitter from './Emitter'\n\nexport default {\n\n install (Vue, connection, opts = {}) {\n if (!connection && !opts.connectManually) { throw new Error('[vue-native-socket] cannot locate connection') }\n\n let observer = null\n\n opts.$setInstance = (wsInstance) => {\n Vue.prototype.$socket = wsInstance\n }\n\n if (opts.connectManually) {\n Vue.prototype.$connect = (connectionUrl = connection, connectionOpts = opts) => {\n connectionOpts.$setInstance = opts.$setInstance\n observer = new Observer(connectionUrl, connectionOpts)\n Vue.prototype.$socket = observer.WebSocket\n }\n\n Vue.prototype.$disconnect = () => {\n if (observer && observer.reconnection) {\n observer.reconnection = false\n clearTimeout(observer.reconnectTimeoutId)\n }\n if (Vue.prototype.$socket) {\n Vue.prototype.$socket.close()\n delete Vue.prototype.$socket\n }\n }\n } else {\n observer = new Observer(connection, opts)\n Vue.prototype.$socket = observer.WebSocket\n }\n const hasProxy = typeof Proxy !== 'undefined' && typeof Proxy === 'function' && /native code/.test(Proxy.toString())\n\n Vue.mixin({\n created () {\n const vm = this\n const sockets = this.$options.sockets\n\n if (hasProxy) {\n this.$options.sockets = new Proxy({}, {\n set (target, key, value) {\n Emitter.addListener(key, value, vm)\n target[key] = value\n return true\n },\n deleteProperty (target, key) {\n Emitter.removeListener(key, vm.$options.sockets[key], vm)\n delete target.key\n return true\n }\n })\n if (sockets) {\n Object.keys(sockets).forEach((key) => {\n this.$options.sockets[key] = sockets[key]\n })\n }\n } else {\n Object.seal(this.$options.sockets)\n\n // if !hasProxy need addListener\n if (sockets) {\n Object.keys(sockets).forEach(key => {\n Emitter.addListener(key, sockets[key], vm)\n })\n }\n }\n },\n beforeDestroy () {\n if (hasProxy) {\n const sockets = this.$options.sockets\n\n if (sockets) {\n Object.keys(sockets).forEach((key) => {\n delete this.$options.sockets[key]\n })\n }\n }\n }\n })\n }\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","_classCallCheck","instance","Constructor","TypeError","_defineProperties","target","props","i","length","descriptor","configurable","writable","_createClass","protoProps","staticProps","Emitter","this","listeners","Map","label","callback","vm","has","set","push","index","reduce","listener","splice","args","forEach","connectionUrl","opts","format","toLowerCase","startsWith","scheme","window","location","protocol","reconnection","reconnectionAttempts","Infinity","reconnectionDelay","reconnectTimeoutId","reconnectionCount","passToStoreHandler","connect","store","mutations","onEvent","WebSocket","sendObj","send","JSON","stringify","clearTimeout","setTimeout","passToStore","eventType","event","$setInstance","currentTarget","reconnect","eventName","defaultPassToStore","bind","method","toUpperCase","msg","data","parse","mutation","namespace","filter","e","join","action","install","Vue","connection","connectManually","Error","observer","wsInstance","$socket","$connect","connectionOpts","Observer","$disconnect","close","hasProxy","Proxy","test","toString","mixin","created","sockets","$options","deleteProperty","keys","seal","beforeDestroy"],"sourceRoot":""} \ No newline at end of file