text: "use strict";function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function $WebSocketProvider(e,t,o,n){function r(t,o,n){n||!isObject(o)||isArray(o)||(n=o,o=void 0),this.protocols=o,this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=n&&n.scope||e,this.rootScopeFailover=n&&n.rootScopeFailover&&!0,this.useApplyAsync=n&&n.useApplyAsync||!1,this.initialTimeout=n&&n.initialTimeout||500,this.maxTimeout=n&&n.maxTimeout||3e5,this.reconnectIfNotNormalClose=n&&n.reconnectIfNotNormalClose||!1,this.binaryType=n&&n.binaryType||"blob",this._reconnectAttempts=0,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],objectFreeze(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return r.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},r.prototype._normalCloseCode=1e3,r.prototype._reconnectableStatusCodes=[4e3],r.prototype.safeDigest=function(e){e&&!this.scope.$$phase&&this.scope.$digest()},r.prototype.bindToScope=function(t){var o=this;return t&&(this.scope=t,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=e})),o},r.prototype._connect=function(e){!e&&this.socket&&this.socket.readyState===this._readyStateConstants.OPEN||(this.socket=n.create(this.url,this.protocols),this.socket.onmessage=_angular2.default.bind(this,this._onMessageHandler),this.socket.onopen=_angular2.default.bind(this,this._onOpenHandler),this.socket.onerror=_angular2.default.bind(this,this._onErrorHandler),this.socket.onclose=_angular2.default.bind(this,this._onCloseHandler),this.socket.binaryType=this.binaryType)},r.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var e=this.sendQueue.shift();this.socket.send(isString(e.message)||"blob"!=this.binaryType?e.message:JSON.stringify(e.message)),e.deferred.resolve()}},r.prototype.notifyOpenCallbacks=function(e){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this,e)},r.prototype.notifyCloseCallbacks=function(e){for(var t=0;t<this.onCloseCallbacks.length;t++)this.onCloseCallbacks[t].call(this,e)},r.prototype.notifyErrorCallbacks=function(e){for(var t=0;t<this.onErrorCallbacks.length;t++)this.onErrorCallbacks[t].call(this,e)},r.prototype.onOpen=function(e){return this.onOpenCallbacks.push(e),this},r.prototype.onClose=function(e){return this.onCloseCallbacks.push(e),this},r.prototype.onError=function(e){return this.onErrorCallbacks.push(e),this},r.prototype.onMessage=function(e,t){if(!isFunction(e))throw new Error("Callback must be a function");if(t&&isDefined(t.filter)&&!isString(t.filter)&&!(t.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:e,pattern:t?t.filter:void 0,autoApply:!t||t.autoApply}),this},r.prototype._onOpenHandler=function(e){this._reconnectAttempts=0,this.notifyOpenCallbacks(e),this.fireQueue()},r.prototype._onCloseHandler=function(e){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyCloseCallbacks(e)}):(t.notifyCloseCallbacks(e),t.safeDigest(!0)),(this.reconnectIfNotNormalClose&&e.code!==this._normalCloseCode||this._reconnectableStatusCodes.indexOf(e.code)>-1)&&this.reconnect()},r.prototype._onErrorHandler=function(e){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyErrorCallbacks(e)}):(t.notifyErrorCallbacks(e),t.safeDigest(!0))},r.prototype._onMessageHandler=function(e){function t(e,t,o){o=arraySlice.call(arguments,2),r.useApplyAsync?r.scope.$applyAsync(function(){e.apply(r,o)}):(e.apply(r,o),r.safeDigest(t))}for(var o,n,r=this,s=0;s<r.onMessageCallbacks.length;s++)n=r.onMessageCallbacks[s],o=n.pattern,o?isString(o)&&e.data===o?t(n.fn,n.autoApply,e):o instanceof RegExp&&o.exec(e.data)&&t(n.fn,n.autoApply,e):t(n.fn,n.autoApply,e)},r.prototype.close=function(e){return!e&&this.socket.bufferedAmount||this.socket.close(),this},r.prototype.send=function(e){function o(e){e.cancel=r;var t=e.then;return e.then=function(){return o(t.apply(this,arguments))},e}function r(t){return a.sendQueue.splice(a.sendQueue.indexOf(e),1),s.reject(t),a}var s=t.defer(),a=this,i=o(s.promise);return a.readyState===a._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(a.sendQueue.push({message:e,deferred:s}),a.fireQueue()),n.isMocked&&n.isMocked()&&n.isConnected(this.url)&&this._onMessageHandler(n.mockSend()),i},r.prototype.reconnect=function(){this.close();var e=this._getBackoffDelay(++this._reconnectAttempts),t=e/1e3;return console.log("Reconnecting in "+t+" seconds"),o(_angular2.default.bind(this,this._connect),e),this},r.prototype._getBackoffDelay=function(e){var t=Math.random()+1,o=this.initialTimeout,n=e,r=this.maxTimeout;return Math.floor(Math.min(t*o*Math.pow(2,n),r))},r.prototype._setInternalState=function(e){if(Math.floor(e)!==e||e<0||e>4)throw new Error("state must be an integer between 0 and 4, got: "+e);objectDefineProperty||(this.readyState=e||this.socket.readyState),this._internalConnectionState=e,forEach(this.sendQueue,function(e){e.deferred.reject("Message cancelled due to closed socket connection")})},objectDefineProperty&&objectDefineProperty(r.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(e,t,o){return new r(e,t,o)}}function $WebSocketBackendProvider(e){this.create=function(e,t){if(!/wss?:\/\//.exec(e))throw new Error("Invalid url provided");return t?new Socket(e,t):new Socket(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}Object.defineProperty(exports,"__esModule",{value:!0});var _angular=require("angular"),_angular2=_interopRequireDefault(_angular),Socket=window.WebSocket||window.MozWebSocket,noop=_angular2.default.noop,objectFreeze=Object.freeze?Object.freeze:noop,objectDefineProperty=Object.defineProperty,isString=_angular2.default.isString,isFunction=_angular2.default.isFunction,isDefined=_angular2.default.isDefined,isObject=_angular2.default.isObject,isArray=_angular2.default.isArray,forEach=_angular2.default.forEach,arraySlice=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t=this.length>>>0,o=Number(arguments[1])||0;for(o=o<0?Math.ceil(o):Math.floor(o),o<0&&(o+=t);o<t;o++)if(o in this&&this[o]===e)return o;return-1}),_angular2.default.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",$WebSocketProvider]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",$WebSocketProvider]).service("$websocketBackend",["$log",$WebSocketBackendProvider]).service("WebSocketBackend",["$log",$WebSocketBackendProvider]),_angular2.default.module("angular-websocket",["ngWebSocket"]),exports.default=_angular2.default.module("ngWebSocket");
  //# sourceMappingURL=angular-websocket.min.js.map
  