Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

angular-websocket

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-websocket - npm Package Compare versions

Comparing version 1.0.8 to 1.0.9

3

angular-websocket-mock.js

@@ -104,2 +104,5 @@ (function() {

if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocketMock');
}
}());

@@ -12,2 +12,3 @@ (function() {

var isArray = angular.isArray;
var forEach = angular.forEach;
var arraySlice = Array.prototype.slice;

@@ -324,3 +325,3 @@ // ie8 wat

angular.forEach(this.sendQueue, function(pending) {
forEach(this.sendQueue, function(pending) {
pending.deferred.reject('Message cancelled due to closed socket connection');

@@ -388,2 +389,5 @@ });

if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocket');
}
}());

2

angular-websocket.min.js

@@ -1,2 +0,2 @@

!function(){"use strict";function t(t,e,o,u){function h(e,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=e||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||t,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this._reconnectAttempts=s&&s.reconnectAttempts||0,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),e?this._connect():this._setInternalState(0)}return h.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},h.prototype._reconnectableStatusCodes=[4e3],h.prototype.safeDigest=function(t){t&&!this.scope.$$phase&&this.scope.$digest()},h.prototype.bindToScope=function(e){var o=this;return e&&(this.scope=e,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=t})),o},h.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=u.create(this.url,this.protocols),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},h.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()}},h.prototype.notifyOpenCallbacks=function(t){for(var e=0;e<this.onOpenCallbacks.length;e++)this.onOpenCallbacks[e].call(this,t)},h.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},h.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},h.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},h.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},h.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},h.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},h.prototype._onOpenHandler=function(t){this._reconnectAttempts=0,this.notifyOpenCallbacks(t),this.fireQueue()},h.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},h.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},h.prototype._onMessageHandler=function(t){function e(t,e,o){o=p.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){t.apply(s,o)}):(t.apply(s,o),s.safeDigest(e))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(o)&&t.data===o?e(n.fn,n.autoApply,t):o instanceof RegExp&&o.exec(t.data)&&e(n.fn,n.autoApply,t):e(n.fn,n.autoApply,t)},h.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},h.prototype.send=function(t){function o(t){t.cancel=n;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return o(t)},t}function n(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),r}var s=e.defer(),r=this,i=o(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(r.sendQueue.push({message:t,deferred:s}),r.fireQueue()),i},h.prototype.reconnect=function(){return this.close(),o(this._connect.bind(this),this._getBackoffDelay(++this._reconnectAttempts)),this},h.prototype._getBackoffDelay=function(t){var e=Math.random()+1,o=this.initialTimeout,n=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*o*Math.pow(n,s),r))},h.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(h.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 h(t,e)}}function e(t,e){this.create=function(e,o){var n,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),n=s.Client||s.client||s}catch(i){}return n=n||t.WebSocket||t.MozWebSocket,o?new n(e,o):new n(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}var o=angular.noop,n=Object.freeze?Object.freeze:o,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isObject,l=angular.isArray,p=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=e);e>o;o++)if(o in this&&this[o]===t)return o;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=p.call(arguments,1),o=this,n=function(){},s=function(){return o.apply(this instanceof n&&t?this:t,e.concat(p.call(arguments)))};return n.prototype=this.prototype,s.prototype=new n,s}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",t]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",t]).service("$websocketBackend",["$window","$log",e]).service("WebSocketBackend",["$window","$log",e]),angular.module("angular-websocket",["ngWebSocket"])}();
!function(){"use strict";function t(t,e,o,h){function f(e,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=e||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||t,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this._reconnectAttempts=s&&s.reconnectAttempts||0,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),e?this._connect():this._setInternalState(0)}return f.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},f.prototype._reconnectableStatusCodes=[4e3],f.prototype.safeDigest=function(t){t&&!this.scope.$$phase&&this.scope.$digest()},f.prototype.bindToScope=function(e){var o=this;return e&&(this.scope=e,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=t})),o},f.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=h.create(this.url,this.protocols),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},f.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()}},f.prototype.notifyOpenCallbacks=function(t){for(var e=0;e<this.onOpenCallbacks.length;e++)this.onOpenCallbacks[e].call(this,t)},f.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},f.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},f.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},f.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},f.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},f.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},f.prototype._onOpenHandler=function(t){this._reconnectAttempts=0,this.notifyOpenCallbacks(t),this.fireQueue()},f.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},f.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},f.prototype._onMessageHandler=function(t){function e(t,e,o){o=p.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){t.apply(s,o)}):(t.apply(s,o),s.safeDigest(e))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(o)&&t.data===o?e(n.fn,n.autoApply,t):o instanceof RegExp&&o.exec(t.data)&&e(n.fn,n.autoApply,t):e(n.fn,n.autoApply,t)},f.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},f.prototype.send=function(t){function o(t){t.cancel=n;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return o(t)},t}function n(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),r}var s=e.defer(),r=this,i=o(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(r.sendQueue.push({message:t,deferred:s}),r.fireQueue()),i},f.prototype.reconnect=function(){return this.close(),o(this._connect.bind(this),this._getBackoffDelay(++this._reconnectAttempts)),this},f.prototype._getBackoffDelay=function(t){var e=Math.random()+1,o=this.initialTimeout,n=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*o*Math.pow(n,s),r))},f.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,u(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},s&&s(f.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 f(t,e)}}function e(t,e){this.create=function(e,o){var n,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),n=s.Client||s.client||s}catch(i){}return n=n||t.WebSocket||t.MozWebSocket,o?new n(e,o):new n(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}var o=angular.noop,n=Object.freeze?Object.freeze:o,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isObject,l=angular.isArray,u=angular.forEach,p=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=e);e>o;o++)if(o in this&&this[o]===t)return o;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=p.call(arguments,1),o=this,n=function(){},s=function(){return o.apply(this instanceof n&&t?this:t,e.concat(p.call(arguments)))};return n.prototype=this.prototype,s.prototype=new n,s}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",t]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",t]).service("$websocketBackend",["$window","$log",e]).service("WebSocketBackend",["$window","$log",e]),angular.module("angular-websocket",["ngWebSocket"]),"object"==typeof module&&"function"!=typeof define&&(module.exports=angular.module("ngWebSocket"))}();
//# sourceMappingURL=angular-websocket.min.js.map

@@ -0,1 +1,9 @@

## 1.0.9 (2015-2-22)
Features:
- Export module for better browserify support
Bugfixes:
- Missing `ws` dependency for browserify
## 1.0.8 (2015-1-29)

@@ -2,0 +10,0 @@

@@ -104,2 +104,5 @@ (function() {

if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocketMock');
}
}());

@@ -12,2 +12,3 @@ (function() {

var isArray = angular.isArray;
var forEach = angular.forEach;
var arraySlice = Array.prototype.slice;

@@ -324,3 +325,3 @@ // ie8 wat

angular.forEach(this.sendQueue, function(pending) {
forEach(this.sendQueue, function(pending) {
pending.deferred.reject('Message cancelled due to closed socket connection');

@@ -388,2 +389,5 @@ });

if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocket');
}
}());

@@ -1,2 +0,2 @@

!function(){"use strict";function t(t,e,o,u){function h(e,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=e||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||t,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this._reconnectAttempts=s&&s.reconnectAttempts||0,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),e?this._connect():this._setInternalState(0)}return h.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},h.prototype._reconnectableStatusCodes=[4e3],h.prototype.safeDigest=function(t){t&&!this.scope.$$phase&&this.scope.$digest()},h.prototype.bindToScope=function(e){var o=this;return e&&(this.scope=e,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=t})),o},h.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=u.create(this.url,this.protocols),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},h.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()}},h.prototype.notifyOpenCallbacks=function(t){for(var e=0;e<this.onOpenCallbacks.length;e++)this.onOpenCallbacks[e].call(this,t)},h.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},h.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},h.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},h.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},h.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},h.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},h.prototype._onOpenHandler=function(t){this._reconnectAttempts=0,this.notifyOpenCallbacks(t),this.fireQueue()},h.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},h.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},h.prototype._onMessageHandler=function(t){function e(t,e,o){o=p.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){t.apply(s,o)}):(t.apply(s,o),s.safeDigest(e))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(o)&&t.data===o?e(n.fn,n.autoApply,t):o instanceof RegExp&&o.exec(t.data)&&e(n.fn,n.autoApply,t):e(n.fn,n.autoApply,t)},h.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},h.prototype.send=function(t){function o(t){t.cancel=n;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return o(t)},t}function n(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),r}var s=e.defer(),r=this,i=o(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(r.sendQueue.push({message:t,deferred:s}),r.fireQueue()),i},h.prototype.reconnect=function(){return this.close(),o(this._connect.bind(this),this._getBackoffDelay(++this._reconnectAttempts)),this},h.prototype._getBackoffDelay=function(t){var e=Math.random()+1,o=this.initialTimeout,n=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*o*Math.pow(n,s),r))},h.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(h.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 h(t,e)}}function e(t,e){this.create=function(e,o){var n,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),n=s.Client||s.client||s}catch(i){}return n=n||t.WebSocket||t.MozWebSocket,o?new n(e,o):new n(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}var o=angular.noop,n=Object.freeze?Object.freeze:o,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isObject,l=angular.isArray,p=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=e);e>o;o++)if(o in this&&this[o]===t)return o;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=p.call(arguments,1),o=this,n=function(){},s=function(){return o.apply(this instanceof n&&t?this:t,e.concat(p.call(arguments)))};return n.prototype=this.prototype,s.prototype=new n,s}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",t]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",t]).service("$websocketBackend",["$window","$log",e]).service("WebSocketBackend",["$window","$log",e]),angular.module("angular-websocket",["ngWebSocket"])}();
!function(){"use strict";function t(t,e,o,h){function f(e,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=e||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||t,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this._reconnectAttempts=s&&s.reconnectAttempts||0,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),e?this._connect():this._setInternalState(0)}return f.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},f.prototype._reconnectableStatusCodes=[4e3],f.prototype.safeDigest=function(t){t&&!this.scope.$$phase&&this.scope.$digest()},f.prototype.bindToScope=function(e){var o=this;return e&&(this.scope=e,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=t})),o},f.prototype._connect=function(t){(t||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=h.create(this.url,this.protocols),this.socket.onmessage=this._onMessageHandler.bind(this),this.socket.onopen=this._onOpenHandler.bind(this),this.socket.onerror=this._onErrorHandler.bind(this),this.socket.onclose=this._onCloseHandler.bind(this))},f.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()}},f.prototype.notifyOpenCallbacks=function(t){for(var e=0;e<this.onOpenCallbacks.length;e++)this.onOpenCallbacks[e].call(this,t)},f.prototype.notifyCloseCallbacks=function(t){for(var e=0;e<this.onCloseCallbacks.length;e++)this.onCloseCallbacks[e].call(this,t)},f.prototype.notifyErrorCallbacks=function(t){for(var e=0;e<this.onErrorCallbacks.length;e++)this.onErrorCallbacks[e].call(this,t)},f.prototype.onOpen=function(t){return this.onOpenCallbacks.push(t),this},f.prototype.onClose=function(t){return this.onCloseCallbacks.push(t),this},f.prototype.onError=function(t){return this.onErrorCallbacks.push(t),this},f.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},f.prototype._onOpenHandler=function(t){this._reconnectAttempts=0,this.notifyOpenCallbacks(t),this.fireQueue()},f.prototype._onCloseHandler=function(t){this.notifyCloseCallbacks(t),this._reconnectableStatusCodes.indexOf(t.code)>-1&&this.reconnect()},f.prototype._onErrorHandler=function(t){this.notifyErrorCallbacks(t)},f.prototype._onMessageHandler=function(t){function e(t,e,o){o=p.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){t.apply(s,o)}):(t.apply(s,o),s.safeDigest(e))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(o)&&t.data===o?e(n.fn,n.autoApply,t):o instanceof RegExp&&o.exec(t.data)&&e(n.fn,n.autoApply,t):e(n.fn,n.autoApply,t)},f.prototype.close=function(t){return(t||!this.socket.bufferedAmount)&&this.socket.close(),this},f.prototype.send=function(t){function o(t){t.cancel=n;var e=t.then;return t.then=function(){var t=e.apply(this,arguments);return o(t)},t}function n(e){return r.sendQueue.splice(r.sendQueue.indexOf(t),1),s.reject(e),r}var s=e.defer(),r=this,i=o(s.promise);return r.readyState===r._readyStateConstants.RECONNECT_ABORTED?s.reject("Socket connection has been closed"):(r.sendQueue.push({message:t,deferred:s}),r.fireQueue()),i},f.prototype.reconnect=function(){return this.close(),o(this._connect.bind(this),this._getBackoffDelay(++this._reconnectAttempts)),this},f.prototype._getBackoffDelay=function(t){var e=Math.random()+1,o=this.initialTimeout,n=2,s=t,r=this.maxTimeout;return Math.floor(Math.min(e*o*Math.pow(n,s),r))},f.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,u(this.sendQueue,function(t){t.deferred.reject("Message cancelled due to closed socket connection")})},s&&s(f.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 f(t,e)}}function e(t,e){this.create=function(e,o){var n,s,r=/wss?:\/\//.exec(e);if(!r)throw new Error("Invalid url provided");if("object"==typeof exports&&require)try{s=require("ws"),n=s.Client||s.client||s}catch(i){}return n=n||t.WebSocket||t.MozWebSocket,o?new n(e,o):new n(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}var o=angular.noop,n=Object.freeze?Object.freeze:o,s=Object.defineProperty,r=angular.isString,i=angular.isFunction,a=angular.isDefined,c=angular.isObject,l=angular.isArray,u=angular.forEach,p=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(t){var e=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=e);e>o;o++)if(o in this&&this[o]===t)return o;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=p.call(arguments,1),o=this,n=function(){},s=function(){return o.apply(this instanceof n&&t?this:t,e.concat(p.call(arguments)))};return n.prototype=this.prototype,s.prototype=new n,s}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",t]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",t]).service("$websocketBackend",["$window","$log",e]).service("WebSocketBackend",["$window","$log",e]),angular.module("angular-websocket",["ngWebSocket"]),"object"==typeof module&&"function"!=typeof define&&(module.exports=angular.module("ngWebSocket"))}();
//# sourceMappingURL=angular-websocket.min.js.map
{
"name": "angular-websocket",
"version": "1.0.8",
"version": "1.0.9",
"main": "angular-websocket.min.js",

@@ -29,3 +29,3 @@ "description": "An AngularJS 1.x WebSocket service for connecting client applications to servers.",

"name": "Patrick Stapleton",
"email": "patrick@gdi2290.com",
"email": "github@gdi2290.com",
"url": "www.gdi2290.com"

@@ -42,10 +42,18 @@ },

],
"browser": {
"angular-websocket": "./dist/angular-websocket.js",
"angular-websocket-mock": "./dist/angular-websocket-mock.js"
},
"dependencies": {
"angular": "*"
"angular": "*",
"ws": "^0.7.1"
},
"devDependencies": {
"karma": "^0.12.28",
"angular-animate": "^1.3.13",
"browserify": "^9.0.3",
"browserify-ngannotate": "^0.7.1",
"karma": "^0.12.31",
"karma-chrome-launcher": "~0.1.7",
"karma-firefox-launcher": "~0.1.3",
"karma-jasmine": "^0.3.3",
"karma-firefox-launcher": "^0.1.4",
"karma-jasmine": "^0.3.5",
"karma-phantomjs-launcher": "~0.1.4",

@@ -56,5 +64,6 @@ "karma-requirejs": "~0.2.1",

"karma-slimerjs-launcher": "^0.1.2",
"requirejs": "~2.1.10",
"ng-annotate": "^0.15.4",
"requirejs": "^2.1.16",
"uglify-js": "^2.4.16"
}
}

@@ -20,2 +20,4 @@ # angular-websocket

* Downloading it manually by clicking [here to download development unminified version](https://raw.github.com/gdi2290/angular-websocket/master/angular-websocket.js)
* CDN for development `https://rawgit.com/gdi2290/angular-websocket/v1.0.8/angular-websocket.js`
* CDN for production `https://cdn.rawgit.com/gdi2290/angular-websocket/v1.0.8/angular-websocket.min.js`

@@ -156,2 +158,3 @@ ## Usage

* Allow for optional configuration object in $websocket constructor
* Add W3C Websocket support
* Add socket.io support

@@ -158,0 +161,0 @@ * Add SockJS support

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc