-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathddp.min.js
executable file
·1 lines (1 loc) · 9.36 KB
/
ddp.min.js
1
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.DDP=e()}}(function(){var e;return function t(e,n,r){function o(s,u){if(!n[s]){if(!e[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var a=Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var f=n[s]={exports:{}};e[s][0].call(f.exports,function(t){var n=e[s][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t){t.exports=e("ddp.js").default},{"ddp.js":2}],2:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=function w(e,t,n){null===e&&(e=Function.prototype);var r=Object.getOwnPropertyDescriptor(e,t);if(void 0===r){var o=Object.getPrototypeOf(e);return null===o?void 0:w(o,t,n)}if("value"in r)return r.value;var i=r.get;return void 0===i?void 0:i.call(n)},a=e("wolfy87-eventemitter"),f=r(a),l=e("./queue"),p=r(l),h=e("./socket"),d=r(h),v=e("./utils"),y="1",m=["ready","nosub","added","changed","removed","result","updated","error"],g=1e4,b=function(e){function t(e){o(this,t);var n=i(this,Object.getPrototypeOf(t).call(this));return n.status="disconnected",n.autoConnect=e.autoConnect!==!1,n.autoReconnect=e.autoReconnect!==!1,n.reconnectInterval=e.reconnectInterval||g,n.messageQueue=new p.default(function(e){return"connected"===n.status?(n.socket.send(e),!0):!1}),n.socket=new d.default(e.SocketConstructor,e.endpoint),n.socket.on("open",function(){n.socket.send({msg:"connect",version:y,support:[y]})}),n.socket.on("close",function(){n.status="disconnected",n.messageQueue.empty(),n.emit("disconnected"),n.autoReconnect&&setTimeout(n.socket.open.bind(n.socket),n.reconnectInterval)}),n.socket.on("message:in",function(e){"connected"===e.msg?(n.status="connected",n.messageQueue.process(),n.emit("connected")):"ping"===e.msg?n.socket.send({msg:"pong",id:e.id}):v.contains(m,e.msg)&&n.emit(e.msg,e)}),n.autoConnect&&n.connect(),n}return s(t,e),u(t,[{key:"emit",value:function(){var e;setTimeout((e=c(Object.getPrototypeOf(t.prototype),"emit",this)).bind.apply(e,[this].concat(Array.prototype.slice.call(arguments))),0)}}]),u(t,[{key:"connect",value:function(){this.socket.open()}},{key:"disconnect",value:function(){this.autoReconnect=!1,this.socket.close()}},{key:"method",value:function(e,t){var n=v.uniqueId();return this.messageQueue.push({msg:"method",id:n,method:e,params:t}),n}},{key:"sub",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;return n||(n=v.uniqueId()),this.messageQueue.push({msg:"sub",id:n,name:e,params:t}),n}},{key:"unsub",value:function(e){return this.messageQueue.push({msg:"unsub",id:e}),e}}]),t}(f.default);n.default=b},{"./queue":3,"./socket":4,"./utils":5,"wolfy87-eventemitter":6}],3:[function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(n,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),i=function(){function e(t){r(this,e),this.consumer=t,this.queue=[]}return o(e,[{key:"push",value:function(e){this.queue.push(e),this.process()}},{key:"process",value:function(){if(0!==this.queue.length){var e=this.consumer(this.queue[0]);e&&(this.queue.shift(),this.process())}}},{key:"empty",value:function(){this.queue=[]}}]),e}();n.default=i},{}],4:[function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{"default":e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function s(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(n,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),c=e("wolfy87-eventemitter"),a=r(c),f=function(e){function t(e,n){o(this,t);var r=i(this,Object.getPrototypeOf(t).call(this));return r.SocketConstructor=e,r.endpoint=n,r.rawSocket=null,r}return s(t,e),u(t,[{key:"send",value:function(e){var t=JSON.stringify(e);this.rawSocket.send(t),this.emit("message:out",JSON.parse(t))}},{key:"open",value:function(){var e=this;this.rawSocket||(this.rawSocket=new this.SocketConstructor(this.endpoint),this.rawSocket.onopen=function(){return e.emit("open")},this.rawSocket.onclose=function(){e.rawSocket=null,e.emit("close")},this.rawSocket.onerror=function(){delete e.rawSocket.onclose,e.rawSocket.close(),e.rawSocket=null,e.emit("close")},this.rawSocket.onmessage=function(t){var n;try{n=JSON.parse(t.data)}catch(r){return}e.emit("message:in",n)})}},{key:"close",value:function(){this.rawSocket&&this.rawSocket.close()}}]),t}(a.default);n.default=f},{"wolfy87-eventemitter":6}],5:[function(e,t,n){"use strict";function r(){return""+i++}function o(e,t){return-1!==e.indexOf(t)}Object.defineProperty(n,"__esModule",{value:!0}),n.uniqueId=r,n.contains=o;var i=0},{}],6:[function(t,n){(function(){"use strict";function t(){}function r(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function o(e){return function(){return this[e].apply(this,arguments)}}var i=t.prototype,s=this,u=s.EventEmitter;i.getListeners=function(e){var t,n,r=this._getEvents();if(e instanceof RegExp){t={};for(n in r)r.hasOwnProperty(n)&&e.test(n)&&(t[n]=r[n])}else t=r[e]||(r[e]=[]);return t},i.flattenListeners=function(e){var t,n=[];for(t=0;t<e.length;t+=1)n.push(e[t].listener);return n},i.getListenersAsObject=function(e){var t,n=this.getListeners(e);return n instanceof Array&&(t={},t[e]=n),t||n},i.addListener=function(e,t){var n,o=this.getListenersAsObject(e),i="object"==typeof t;for(n in o)o.hasOwnProperty(n)&&-1===r(o[n],t)&&o[n].push(i?t:{listener:t,once:!1});return this},i.on=o("addListener"),i.addOnceListener=function(e,t){return this.addListener(e,{listener:t,once:!0})},i.once=o("addOnceListener"),i.defineEvent=function(e){return this.getListeners(e),this},i.defineEvents=function(e){for(var t=0;t<e.length;t+=1)this.defineEvent(e[t]);return this},i.removeListener=function(e,t){var n,o,i=this.getListenersAsObject(e);for(o in i)i.hasOwnProperty(o)&&(n=r(i[o],t),-1!==n&&i[o].splice(n,1));return this},i.off=o("removeListener"),i.addListeners=function(e,t){return this.manipulateListeners(!1,e,t)},i.removeListeners=function(e,t){return this.manipulateListeners(!0,e,t)},i.manipulateListeners=function(e,t,n){var r,o,i=e?this.removeListener:this.addListener,s=e?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(r=n.length;r--;)i.call(this,t,n[r]);else for(r in t)t.hasOwnProperty(r)&&(o=t[r])&&("function"==typeof o?i.call(this,r,o):s.call(this,r,o));return this},i.removeEvent=function(e){var t,n=typeof e,r=this._getEvents();if("string"===n)delete r[e];else if(e instanceof RegExp)for(t in r)r.hasOwnProperty(t)&&e.test(t)&&delete r[t];else delete this._events;return this},i.removeAllListeners=o("removeEvent"),i.emitEvent=function(e,t){var n,r,o,i,s,u=this.getListenersAsObject(e);for(i in u)if(u.hasOwnProperty(i))for(n=u[i].slice(0),o=n.length;o--;)r=n[o],r.once===!0&&this.removeListener(e,r.listener),s=r.listener.apply(this,t||[]),s===this._getOnceReturnValue()&&this.removeListener(e,r.listener);return this},i.trigger=o("emitEvent"),i.emit=function(e){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(e,t)},i.setOnceReturnValue=function(e){return this._onceReturnValue=e,this},i._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0},i._getEvents=function(){return this._events||(this._events={})},t.noConflict=function(){return s.EventEmitter=u,t},"function"==typeof e&&e.amd?e(function(){return t}):"object"==typeof n&&n.exports?n.exports=t:s.EventEmitter=t}).call(this)},{}]},{},[1])(1)});