angular-websocket
Advanced tools
Comparing version 1.0.5 to 1.0.6
(function() { | ||
'use strict'; | ||
@@ -9,2 +10,3 @@ var noop = function() {}; | ||
var isDefined = angular.isDefined; | ||
var arraySlice = Array.prototype.slice; | ||
var isArray = angular.isArray; | ||
@@ -27,3 +29,28 @@ // ie8 wat | ||
} | ||
// ie8 wat | ||
if (!Function.prototype.bind) { | ||
Function.prototype.bind = function(oThis) { | ||
if (typeof this !== 'function') { | ||
// closest thing possible to the ECMAScript 5 | ||
// internal IsCallable function | ||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); | ||
} | ||
var aArgs = arraySlice.call(arguments, 1), | ||
fToBind = this, | ||
fNOP = function() {}, | ||
fBound = function() { | ||
return fToBind.apply(this instanceof fNOP && oThis | ||
? this | ||
: oThis, | ||
aArgs.concat(arraySlice.call(arguments))); | ||
}; | ||
fNOP.prototype = this.prototype; | ||
fBound.prototype = new fNOP(); | ||
return fBound; | ||
}; | ||
} | ||
$WebSocketProvider.$inject = ['$rootScope', '$q', '$timeout', '$websocketBackend']; | ||
@@ -95,3 +122,3 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) { | ||
if (force || !this.socket || this.socket.readyState !== this._readyStateConstants.OPEN) { | ||
this.socket = $websocketBackend.createWebSocketBackend(this.url, this.protocol); | ||
this.socket = $websocketBackend.createWebSocketBackend(this.url, this.protocols); | ||
this.socket.onopen = this._onOpenHandler.bind(this); | ||
@@ -98,0 +125,0 @@ this.socket.onmessage = this._onMessageHandler.bind(this); |
@@ -1,2 +0,2 @@ | ||
!function(){function t(t,e,n,l){function h(e){e&&!t.$$phase&&t.$apply()}function u(t,e){var n=e&&e.protocols;(r(e)||c(e))&&(n=e),this.protocols=n||"Sec-WebSocket-Protocol",this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this._reconnectAttempts=0,this.initialTimeout=500,this.maxTimeout=3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],o(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return u.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},u.prototype._reconnectableStatusCodes=[4e3],u.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},u.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=l.createWebSocketBackend(this.url,this.protocol),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},u.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var t=this.sendQueue.shift();this.socket.send(r(t.message)?t.message:JSON.stringify(t.message)),t.deferred.resolve()}},u.prototype.notifyOpenCallbacks=function(){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this)},u.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},u.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},u.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},u.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},u.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},u.prototype.onMessage=function(t,e){if(!i(t))throw new Error("Callback must be a function");if(e&&a(e.filter)&&!r(e.filter)&&!(e.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:t,pattern:e?e.filter:void 0,autoApply:e?e.autoApply:!0}),this},u.prototype._onOpenHandler=function(){this._reconnectAttempts=0,this.notifyOpenCallbacks(),this.fireQueue()},u.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},u.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},u.prototype._onMessageHandler=function(t){for(var e,n,o=this,s=0;s<o.onMessageCallbacks.length;s++)n=o.onMessageCallbacks[s],e=n.pattern,e?r(e)&&t.data===e?(n.fn.call(this,t),h(n.autoApply)):e instanceof RegExp&&e.exec(t.data)&&(n.fn.call(this,t),h(n.autoApply)):(n.fn.call(this,t),h(n.autoApply))},u.prototype.send=function(t){function n(t){t.cancel=o;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return n(t)},t}function o(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),this}var s=e.defer(),r=this,i=n(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(this.sendQueue.push({message:t,deferred:s}),this.fireQueue()),i},u.prototype.reconnect=function(){return this.close(),n(angular.bind(this,function(){this._connect()}),this._getBackoffDelay(++this._reconnectAttempts),!0),this},u.prototype._getBackoffDelay=function(t){var e=Math.random()+1,n=this.initialTimeout,o=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*n*Math.pow(o,s),r))},u.prototype._setInternalState=function(t){if(Math.floor(t)!==t||0>t||t>4)throw new Error("state must be an integer between 0 and 4, got: "+t);s||(this.readyState=t||this.socket.readyState),this._internalConnectionState=t,angular.forEach(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},s&&s(u.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(t,e){return new u(t,e)}}function e(t){this.createWebSocketBackend=function(e,n){var o,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),o=s.Client||s.client||s}catch(i){}return o=o||t.WebSocket||t.MozWebSocket,n?new o(e,n):new o(e)}}var n=function(){},o=Object.freeze?Object.freeze:n,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isArray;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,n=Number(arguments[1])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=e);e>n;n++)if(n in this&&this[n]===t)return n;return-1}),t.$inject=["$rootScope","$q","$timeout","$websocketBackend"],e.$inject=["$window"],angular.module("ngWebSocket",[]).factory("$websocket",t).factory("WebSocket",t).service("$websocketBackend",e).service("WebSocketBackend",e),angular.module("angular-websocket",["ngWebSocket"])}(); | ||
!function(){"use strict";function t(t,e,n,c){function h(e){e&&!t.$$phase&&t.$apply()}function u(t,e){var n=e&&e.protocols;(s(e)||l(e))&&(n=e),this.protocols=n||"Sec-WebSocket-Protocol",this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this._reconnectAttempts=0,this.initialTimeout=500,this.maxTimeout=3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],o(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return u.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},u.prototype._reconnectableStatusCodes=[4e3],u.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},u.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=c.createWebSocketBackend(this.url,this.protocols),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},u.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var t=this.sendQueue.shift();this.socket.send(s(t.message)?t.message:JSON.stringify(t.message)),t.deferred.resolve()}},u.prototype.notifyOpenCallbacks=function(){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this)},u.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},u.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},u.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},u.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},u.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},u.prototype.onMessage=function(t,e){if(!i(t))throw new Error("Callback must be a function");if(e&&a(e.filter)&&!s(e.filter)&&!(e.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:t,pattern:e?e.filter:void 0,autoApply:e?e.autoApply:!0}),this},u.prototype._onOpenHandler=function(){this._reconnectAttempts=0,this.notifyOpenCallbacks(),this.fireQueue()},u.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},u.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},u.prototype._onMessageHandler=function(t){for(var e,n,o=this,r=0;r<o.onMessageCallbacks.length;r++)n=o.onMessageCallbacks[r],e=n.pattern,e?s(e)&&t.data===e?(n.fn.call(this,t),h(n.autoApply)):e instanceof RegExp&&e.exec(t.data)&&(n.fn.call(this,t),h(n.autoApply)):(n.fn.call(this,t),h(n.autoApply))},u.prototype.send=function(t){function n(t){t.cancel=o;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return n(t)},t}function o(e){return s.sendQueue.splice(s.sendQueue.indexOf(t),1),r.reject(e),this}var r=e.defer(),s=this,i=n(r.promise);return s.readyState===s._readyStateConstants.RECONNECT_ABORTED?r.reject("Socket connection has been closed"):(this.sendQueue.push({message:t,deferred:r}),this.fireQueue()),i},u.prototype.reconnect=function(){return this.close(),n(angular.bind(this,function(){this._connect()}),this._getBackoffDelay(++this._reconnectAttempts),!0),this},u.prototype._getBackoffDelay=function(t){var e=Math.random()+1,n=this.initialTimeout,o=2,r=t,s=this.maxTimeout;return Math.floor(Math.min(e*n*Math.pow(o,r),s))},u.prototype._setInternalState=function(t){if(Math.floor(t)!==t||0>t||t>4)throw new Error("state must be an integer between 0 and 4, got: "+t);r||(this.readyState=t||this.socket.readyState),this._internalConnectionState=t,angular.forEach(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},r&&r(u.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(t,e){return new u(t,e)}}function e(t){this.createWebSocketBackend=function(e,n){var o,r,s=/wss?:\/\//.exec(e);if(!s)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{r=require("ws"),o=r.Client||r.client||r}catch(i){}return o=o||t.WebSocket||t.MozWebSocket,n?new o(e,n):new o(e)}}var n=function(){},o=Object.freeze?Object.freeze:n,r=Object.defineProperty,s=angular.isString,i=angular.isFunction,a=angular.isDefined,c=Array.prototype.slice,l=angular.isArray;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,n=Number(arguments[1])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=e);e>n;n++)if(n in this&&this[n]===t)return n;return-1}),Function.prototype.bind||(Function.prototype.bind=function(t){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=c.call(arguments,1),n=this,o=function(){},r=function(){return n.apply(this instanceof o&&t?this:t,e.concat(c.call(arguments)))};return o.prototype=this.prototype,r.prototype=new o,r}),t.$inject=["$rootScope","$q","$timeout","$websocketBackend"],e.$inject=["$window"],angular.module("ngWebSocket",[]).factory("$websocket",t).factory("WebSocket",t).service("$websocketBackend",e).service("WebSocketBackend",e),angular.module("angular-websocket",["ngWebSocket"])}(); | ||
//# sourceMappingURL=angular-websocket.min.js.map |
@@ -0,1 +1,10 @@ | ||
## 1.0.6 (2015-1-7) | ||
Features: | ||
- Include onErrorCallbacks docs | ||
- Include onCloseCallbacks docs | ||
Bugfixes: | ||
- Typo in _connect() | ||
## 1.0.5 (2014-12-29) | ||
@@ -2,0 +11,0 @@ |
(function() { | ||
'use strict'; | ||
@@ -9,2 +10,3 @@ var noop = function() {}; | ||
var isDefined = angular.isDefined; | ||
var arraySlice = Array.prototype.slice; | ||
var isArray = angular.isArray; | ||
@@ -27,3 +29,28 @@ // ie8 wat | ||
} | ||
// ie8 wat | ||
if (!Function.prototype.bind) { | ||
Function.prototype.bind = function(oThis) { | ||
if (typeof this !== 'function') { | ||
// closest thing possible to the ECMAScript 5 | ||
// internal IsCallable function | ||
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable'); | ||
} | ||
var aArgs = arraySlice.call(arguments, 1), | ||
fToBind = this, | ||
fNOP = function() {}, | ||
fBound = function() { | ||
return fToBind.apply(this instanceof fNOP && oThis | ||
? this | ||
: oThis, | ||
aArgs.concat(arraySlice.call(arguments))); | ||
}; | ||
fNOP.prototype = this.prototype; | ||
fBound.prototype = new fNOP(); | ||
return fBound; | ||
}; | ||
} | ||
$WebSocketProvider.$inject = ['$rootScope', '$q', '$timeout', '$websocketBackend']; | ||
@@ -95,3 +122,3 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) { | ||
if (force || !this.socket || this.socket.readyState !== this._readyStateConstants.OPEN) { | ||
this.socket = $websocketBackend.createWebSocketBackend(this.url, this.protocol); | ||
this.socket = $websocketBackend.createWebSocketBackend(this.url, this.protocols); | ||
this.socket.onopen = this._onOpenHandler.bind(this); | ||
@@ -98,0 +125,0 @@ this.socket.onmessage = this._onMessageHandler.bind(this); |
@@ -1,2 +0,2 @@ | ||
!function(){function t(t,e,n,l){function h(e){e&&!t.$$phase&&t.$apply()}function u(t,e){var n=e&&e.protocols;(r(e)||c(e))&&(n=e),this.protocols=n||"Sec-WebSocket-Protocol",this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this._reconnectAttempts=0,this.initialTimeout=500,this.maxTimeout=3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],o(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return u.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},u.prototype._reconnectableStatusCodes=[4e3],u.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},u.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=l.createWebSocketBackend(this.url,this.protocol),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},u.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var t=this.sendQueue.shift();this.socket.send(r(t.message)?t.message:JSON.stringify(t.message)),t.deferred.resolve()}},u.prototype.notifyOpenCallbacks=function(){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this)},u.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},u.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},u.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},u.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},u.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},u.prototype.onMessage=function(t,e){if(!i(t))throw new Error("Callback must be a function");if(e&&a(e.filter)&&!r(e.filter)&&!(e.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:t,pattern:e?e.filter:void 0,autoApply:e?e.autoApply:!0}),this},u.prototype._onOpenHandler=function(){this._reconnectAttempts=0,this.notifyOpenCallbacks(),this.fireQueue()},u.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},u.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},u.prototype._onMessageHandler=function(t){for(var e,n,o=this,s=0;s<o.onMessageCallbacks.length;s++)n=o.onMessageCallbacks[s],e=n.pattern,e?r(e)&&t.data===e?(n.fn.call(this,t),h(n.autoApply)):e instanceof RegExp&&e.exec(t.data)&&(n.fn.call(this,t),h(n.autoApply)):(n.fn.call(this,t),h(n.autoApply))},u.prototype.send=function(t){function n(t){t.cancel=o;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return n(t)},t}function o(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),this}var s=e.defer(),r=this,i=n(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(this.sendQueue.push({message:t,deferred:s}),this.fireQueue()),i},u.prototype.reconnect=function(){return this.close(),n(angular.bind(this,function(){this._connect()}),this._getBackoffDelay(++this._reconnectAttempts),!0),this},u.prototype._getBackoffDelay=function(t){var e=Math.random()+1,n=this.initialTimeout,o=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*n*Math.pow(o,s),r))},u.prototype._setInternalState=function(t){if(Math.floor(t)!==t||0>t||t>4)throw new Error("state must be an integer between 0 and 4, got: "+t);s||(this.readyState=t||this.socket.readyState),this._internalConnectionState=t,angular.forEach(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},s&&s(u.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(t,e){return new u(t,e)}}function e(t){this.createWebSocketBackend=function(e,n){var o,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),o=s.Client||s.client||s}catch(i){}return o=o||t.WebSocket||t.MozWebSocket,n?new o(e,n):new o(e)}}var n=function(){},o=Object.freeze?Object.freeze:n,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isArray;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,n=Number(arguments[1])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=e);e>n;n++)if(n in this&&this[n]===t)return n;return-1}),t.$inject=["$rootScope","$q","$timeout","$websocketBackend"],e.$inject=["$window"],angular.module("ngWebSocket",[]).factory("$websocket",t).factory("WebSocket",t).service("$websocketBackend",e).service("WebSocketBackend",e),angular.module("angular-websocket",["ngWebSocket"])}(); | ||
!function(){"use strict";function t(t,e,n,c){function h(e){e&&!t.$$phase&&t.$apply()}function u(t,e){var n=e&&e.protocols;(s(e)||l(e))&&(n=e),this.protocols=n||"Sec-WebSocket-Protocol",this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this._reconnectAttempts=0,this.initialTimeout=500,this.maxTimeout=3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],o(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return u.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},u.prototype._reconnectableStatusCodes=[4e3],u.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},u.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=c.createWebSocketBackend(this.url,this.protocols),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},u.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var t=this.sendQueue.shift();this.socket.send(s(t.message)?t.message:JSON.stringify(t.message)),t.deferred.resolve()}},u.prototype.notifyOpenCallbacks=function(){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this)},u.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},u.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},u.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},u.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},u.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},u.prototype.onMessage=function(t,e){if(!i(t))throw new Error("Callback must be a function");if(e&&a(e.filter)&&!s(e.filter)&&!(e.filter instanceof RegExp))throw new Error("Pattern must be a string or regular expression");return this.onMessageCallbacks.push({fn:t,pattern:e?e.filter:void 0,autoApply:e?e.autoApply:!0}),this},u.prototype._onOpenHandler=function(){this._reconnectAttempts=0,this.notifyOpenCallbacks(),this.fireQueue()},u.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},u.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},u.prototype._onMessageHandler=function(t){for(var e,n,o=this,r=0;r<o.onMessageCallbacks.length;r++)n=o.onMessageCallbacks[r],e=n.pattern,e?s(e)&&t.data===e?(n.fn.call(this,t),h(n.autoApply)):e instanceof RegExp&&e.exec(t.data)&&(n.fn.call(this,t),h(n.autoApply)):(n.fn.call(this,t),h(n.autoApply))},u.prototype.send=function(t){function n(t){t.cancel=o;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return n(t)},t}function o(e){return s.sendQueue.splice(s.sendQueue.indexOf(t),1),r.reject(e),this}var r=e.defer(),s=this,i=n(r.promise);return s.readyState===s._readyStateConstants.RECONNECT_ABORTED?r.reject("Socket connection has been closed"):(this.sendQueue.push({message:t,deferred:r}),this.fireQueue()),i},u.prototype.reconnect=function(){return this.close(),n(angular.bind(this,function(){this._connect()}),this._getBackoffDelay(++this._reconnectAttempts),!0),this},u.prototype._getBackoffDelay=function(t){var e=Math.random()+1,n=this.initialTimeout,o=2,r=t,s=this.maxTimeout;return Math.floor(Math.min(e*n*Math.pow(o,r),s))},u.prototype._setInternalState=function(t){if(Math.floor(t)!==t||0>t||t>4)throw new Error("state must be an integer between 0 and 4, got: "+t);r||(this.readyState=t||this.socket.readyState),this._internalConnectionState=t,angular.forEach(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},r&&r(u.prototype,"readyState",{get:function(){return this._internalConnectionState||this.socket.readyState},set:function(){throw new Error("The readyState property is read-only")}}),function(t,e){return new u(t,e)}}function e(t){this.createWebSocketBackend=function(e,n){var o,r,s=/wss?:\/\//.exec(e);if(!s)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{r=require("ws"),o=r.Client||r.client||r}catch(i){}return o=o||t.WebSocket||t.MozWebSocket,n?new o(e,n):new o(e)}}var n=function(){},o=Object.freeze?Object.freeze:n,r=Object.defineProperty,s=angular.isString,i=angular.isFunction,a=angular.isDefined,c=Array.prototype.slice,l=angular.isArray;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,n=Number(arguments[1])||0;for(n=0>n?Math.ceil(n):Math.floor(n),0>n&&(n+=e);e>n;n++)if(n in this&&this[n]===t)return n;return-1}),Function.prototype.bind||(Function.prototype.bind=function(t){if("function"!=typeof this)throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");var e=c.call(arguments,1),n=this,o=function(){},r=function(){return n.apply(this instanceof o&&t?this:t,e.concat(c.call(arguments)))};return o.prototype=this.prototype,r.prototype=new o,r}),t.$inject=["$rootScope","$q","$timeout","$websocketBackend"],e.$inject=["$window"],angular.module("ngWebSocket",[]).factory("$websocket",t).factory("WebSocket",t).service("$websocketBackend",e).service("WebSocketBackend",e),angular.module("angular-websocket",["ngWebSocket"])}(); | ||
//# sourceMappingURL=angular-websocket.min.js.map |
{ | ||
"name": "angular-websocket", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"main": "angular-websocket.min.js", | ||
@@ -5,0 +5,0 @@ "description": "An AngularJS 1.x WebSocket service for connecting client applications to servers.", |
@@ -7,3 +7,3 @@ # angular-websocket | ||
[![devDependency Status](https://david-dm.org/gdi2290/angular-websocket/dev-status.svg)](https://david-dm.org/gdi2290/angular-websocket#info=devDependencies) | ||
[![NPM](https://nodei.co/npm-dl/angular-websocket.png)](https://nodei.co/npm/angular-websocket/) | ||
[![NPM](https://nodei.co/npm/angular-websocket.svg?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/angular-websocket/) | ||
@@ -55,3 +55,3 @@ ### Status: Looking for feedback about new API changes | ||
}; | ||
return methods; | ||
@@ -91,2 +91,4 @@ }) | ||
onMessageCallbacks | Array<function> | List of callbacks to be executed when a message is received from the socket. Callbacks should be added via the `onMessage` method. | ||
onErrorCallbacks | Array<function> | List of callbacks to be executed when an error is received from the socket. Callbacks should be added via the `onError` method. | ||
onCloseCallbacks | Array<function> | List of callbacks to be executed when the socket is closed. Callbacks should be added via the `onClose` method. | ||
readyState | Number:readonly | Returns either the readyState value from the underlying WebSocket instance, or a proprietary value representing the internal state of the lib, e.g. if the lib is in a state of re-connecting. | ||
@@ -152,2 +154,10 @@ initialTimeout | Number | The initial timeout, should be set at the outer limits of expected response time for the service. For example, if your service responds in 1ms on average but in 10ms for 99% of requests, then set to 10ms. | ||
* Allow more control over $digest cycle per WebSocket instance | ||
* Add socket.io support | ||
* Add SockJS support | ||
* Add Faye support | ||
* Add PubNub support | ||
* Add .bindToScope method | ||
* Add .on(event) | ||
* Include more examples of patterns for realtime Angular apps | ||
* Allow for optional configuration object in $websocket constructor | ||
@@ -154,0 +164,0 @@ ## License |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64237
800
163