New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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.9 to 1.0.12

19

angular-websocket-mock.js

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

var pendingSends = [];
var mock = false;

@@ -24,2 +25,20 @@

this.mockSend = function() {
if (mock) {
return sendQueue.shift();
}
};
this.mock = function() {
mock = true;
};
this.isMocked = function () {
return mock;
};
this.isConnected = function(url) {
return connectQueue.indexOf(url) > -1;
};
$MockWebSocket.prototype.close = function () {

@@ -26,0 +45,0 @@ pendingCloses.push(true);

64

angular-websocket.js

@@ -30,25 +30,3 @@ (function() {

}
// 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'];

@@ -74,9 +52,10 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) {

// TODO: refactor options to use isDefined
this.scope = options && options.scope || $rootScope;
this.rootScopeFailover = options && options.rootScopeFailover && true;
this.useApplyAsync = options && options.useApplyAsync || false;
this._reconnectAttempts = options && options.reconnectAttempts || 0;
this.initialTimeout = options && options.initialTimeout || 500; // 500ms
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
this.scope = options && options.scope || $rootScope;
this.rootScopeFailover = options && options.rootScopeFailover && true;
this.useApplyAsync = options && options.useApplyAsync || false;
this.initialTimeout = options && options.initialTimeout || 500; // 500ms
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false;
this._reconnectAttempts = 0;
this.sendQueue = [];

@@ -98,2 +77,3 @@ this.onOpenCallbacks = [];

$WebSocket.prototype._readyStateConstants = {

@@ -107,2 +87,4 @@ 'CONNECTING': 0,

$WebSocket.prototype._normalCloseCode = 1000;
$WebSocket.prototype._reconnectableStatusCodes = [

@@ -134,6 +116,6 @@ 4000

this.socket = $websocketBackend.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);
this.socket.onmessage = angular.bind(this, this._onMessageHandler);
this.socket.onopen = angular.bind(this, this._onOpenHandler);
this.socket.onerror = angular.bind(this, this._onErrorHandler);
this.socket.onclose = angular.bind(this, this._onCloseHandler);
}

@@ -212,3 +194,3 @@ };

this.notifyCloseCallbacks(event);
if (this._reconnectableStatusCodes.indexOf(event.code) > -1) {
if ((this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1) {
this.reconnect();

@@ -296,2 +278,7 @@ }

if ($websocketBackend.isMocked && $websocketBackend.isMocked() &&
$websocketBackend.isConnected(this.url)) {
this._onMessageHandler($websocketBackend.mockSend());
}
return promise;

@@ -303,4 +290,9 @@ };

$timeout(this._connect.bind(this), this._getBackoffDelay(++this._reconnectAttempts));
var backoffDelay = this._getBackoffDelay(++this._reconnectAttempts);
var backoffDelaySeconds = backoffDelay / 1000;
console.log('Reconnecting in ' + backoffDelaySeconds + ' seconds');
$timeout(angular.bind(this, this._connect), backoffDelay);
return this;

@@ -349,4 +341,4 @@ };

return function(url, protocols) {
return new $WebSocket(url, protocols);
return function(url, protocols, options) {
return new $WebSocket(url, protocols, options);
};

@@ -353,0 +345,0 @@ }

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

!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"))}();
!function(){"use strict";function e(e,t,o,p){function f(t,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||e,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.reconnectIfNotNormalClose=s&&s.reconnectIfNotNormalClose||!1,this._reconnectAttempts=0,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return f.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},f.prototype._normalCloseCode=1e3,f.prototype._reconnectableStatusCodes=[4e3],f.prototype.safeDigest=function(e){e&&!this.scope.$$phase&&this.scope.$digest()},f.prototype.bindToScope=function(t){var o=this;return t&&(this.scope=t,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=e})),o},f.prototype._connect=function(e){(e||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=p.create(this.url,this.protocols),this.socket.onmessage=angular.bind(this,this._onMessageHandler),this.socket.onopen=angular.bind(this,this._onOpenHandler),this.socket.onerror=angular.bind(this,this._onErrorHandler),this.socket.onclose=angular.bind(this,this._onCloseHandler))},f.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var e=this.sendQueue.shift();this.socket.send(r(e.message)?e.message:JSON.stringify(e.message)),e.deferred.resolve()}},f.prototype.notifyOpenCallbacks=function(e){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this,e)},f.prototype.notifyCloseCallbacks=function(e){for(var t=0;t<this.onCloseCallbacks.length;t++)this.onCloseCallbacks[t].call(this,e)},f.prototype.notifyErrorCallbacks=function(e){for(var t=0;t<this.onErrorCallbacks.length;t++)this.onErrorCallbacks[t].call(this,e)},f.prototype.onOpen=function(e){return this.onOpenCallbacks.push(e),this},f.prototype.onClose=function(e){return this.onCloseCallbacks.push(e),this},f.prototype.onError=function(e){return this.onErrorCallbacks.push(e),this},f.prototype.onMessage=function(e,t){if(!i(e))throw new Error("Callback must be a function");if(t&&a(t.filter)&&!r(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:!0}),this},f.prototype._onOpenHandler=function(e){this._reconnectAttempts=0,this.notifyOpenCallbacks(e),this.fireQueue()},f.prototype._onCloseHandler=function(e){this.notifyCloseCallbacks(e),(this.reconnectIfNotNormalClose&&e.code!==this._normalCloseCode||this._reconnectableStatusCodes.indexOf(e.code)>-1)&&this.reconnect()},f.prototype._onErrorHandler=function(e){this.notifyErrorCallbacks(e)},f.prototype._onMessageHandler=function(e){function t(e,t,o){o=h.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){e.apply(s,o)}):(e.apply(s,o),s.safeDigest(t))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(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)},f.prototype.close=function(e){return(e||!this.socket.bufferedAmount)&&this.socket.close(),this},f.prototype.send=function(e){function o(e){e.cancel=n;var t=e.then;return e.then=function(){var e=t.apply(this,arguments);return o(e)},e}function n(t){return r.sendQueue.splice(r.sendQueue.indexOf(e),1),s.reject(t),r}var s=t.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:e,deferred:s}),r.fireQueue()),p.isMocked&&p.isMocked()&&p.isConnected(this.url)&&this._onMessageHandler(p.mockSend()),i},f.prototype.reconnect=function(){this.close();var e=this._getBackoffDelay(++this._reconnectAttempts),t=e/1e3;return console.log("Reconnecting in "+t+" seconds"),o(angular.bind(this,this._connect),e),this},f.prototype._getBackoffDelay=function(e){var t=Math.random()+1,o=this.initialTimeout,n=2,s=e,r=this.maxTimeout;return Math.floor(Math.min(t*o*Math.pow(n,s),r))},f.prototype._setInternalState=function(e){if(Math.floor(e)!==e||0>e||e>4)throw new Error("state must be an integer between 0 and 4, got: "+e);s||(this.readyState=e||this.socket.readyState),this._internalConnectionState=e,u(this.sendQueue,function(e){e.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(e,t,o){return new f(e,t,o)}}function t(e,t){this.create=function(t,o){var n,s,r=/wss?:\/\//.exec(t);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||e.WebSocket||e.MozWebSocket,o?new n(t,o):new n(t)},this.createWebSocketBackend=function(e,o){return t.warn("Deprecated: Please use .create(url, protocols)"),this.create(e,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,h=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=t);t>o;o++)if(o in this&&this[o]===e)return o;return-1}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",e]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",e]).service("$websocketBackend",["$window","$log",t]).service("WebSocketBackend",["$window","$log",t]),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,14 @@

## 1.0.12 (2015-6-2)
Features:
- Update to angular 1.3.15
- Added an alwaysReconnect option
- Can mock a websocket server for testing purpose.
- Use Angular's `bind` polyfill
Bugfixes:
- Pass options to the $websocket constructor
- Fix MockWebsocket readyState and flush
## 1.0.9 (2015-2-22)

@@ -2,0 +15,0 @@

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

var pendingSends = [];
var mock = false;

@@ -24,2 +25,20 @@

this.mockSend = function() {
if (mock) {
return sendQueue.shift();
}
};
this.mock = function() {
mock = true;
};
this.isMocked = function () {
return mock;
};
this.isConnected = function(url) {
return connectQueue.indexOf(url) > -1;
};
$MockWebSocket.prototype.close = function () {

@@ -26,0 +45,0 @@ pendingCloses.push(true);

@@ -30,25 +30,3 @@ (function() {

}
// 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'];

@@ -74,9 +52,10 @@ function $WebSocketProvider($rootScope, $q, $timeout, $websocketBackend) {

// TODO: refactor options to use isDefined
this.scope = options && options.scope || $rootScope;
this.rootScopeFailover = options && options.rootScopeFailover && true;
this.useApplyAsync = options && options.useApplyAsync || false;
this._reconnectAttempts = options && options.reconnectAttempts || 0;
this.initialTimeout = options && options.initialTimeout || 500; // 500ms
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
this.scope = options && options.scope || $rootScope;
this.rootScopeFailover = options && options.rootScopeFailover && true;
this.useApplyAsync = options && options.useApplyAsync || false;
this.initialTimeout = options && options.initialTimeout || 500; // 500ms
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false;
this._reconnectAttempts = 0;
this.sendQueue = [];

@@ -98,2 +77,3 @@ this.onOpenCallbacks = [];

$WebSocket.prototype._readyStateConstants = {

@@ -107,2 +87,4 @@ 'CONNECTING': 0,

$WebSocket.prototype._normalCloseCode = 1000;
$WebSocket.prototype._reconnectableStatusCodes = [

@@ -134,6 +116,6 @@ 4000

this.socket = $websocketBackend.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);
this.socket.onmessage = angular.bind(this, this._onMessageHandler);
this.socket.onopen = angular.bind(this, this._onOpenHandler);
this.socket.onerror = angular.bind(this, this._onErrorHandler);
this.socket.onclose = angular.bind(this, this._onCloseHandler);
}

@@ -212,3 +194,3 @@ };

this.notifyCloseCallbacks(event);
if (this._reconnectableStatusCodes.indexOf(event.code) > -1) {
if ((this.reconnectIfNotNormalClose && event.code !== this._normalCloseCode) || this._reconnectableStatusCodes.indexOf(event.code) > -1) {
this.reconnect();

@@ -296,2 +278,7 @@ }

if ($websocketBackend.isMocked && $websocketBackend.isMocked() &&
$websocketBackend.isConnected(this.url)) {
this._onMessageHandler($websocketBackend.mockSend());
}
return promise;

@@ -303,4 +290,9 @@ };

$timeout(this._connect.bind(this), this._getBackoffDelay(++this._reconnectAttempts));
var backoffDelay = this._getBackoffDelay(++this._reconnectAttempts);
var backoffDelaySeconds = backoffDelay / 1000;
console.log('Reconnecting in ' + backoffDelaySeconds + ' seconds');
$timeout(angular.bind(this, this._connect), backoffDelay);
return this;

@@ -349,4 +341,4 @@ };

return function(url, protocols) {
return new $WebSocket(url, protocols);
return function(url, protocols, options) {
return new $WebSocket(url, protocols, options);
};

@@ -353,0 +345,0 @@ }

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

!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"))}();
!function(){"use strict";function e(e,t,o,p){function f(t,o,s){s||!c(o)||l(o)||(s=o,o=void 0),this.protocols=o,this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=s&&s.scope||e,this.rootScopeFailover=s&&s.rootScopeFailover&&!0,this.useApplyAsync=s&&s.useApplyAsync||!1,this.initialTimeout=s&&s.initialTimeout||500,this.maxTimeout=s&&s.maxTimeout||3e5,this.reconnectIfNotNormalClose=s&&s.reconnectIfNotNormalClose||!1,this._reconnectAttempts=0,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],n(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return f.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},f.prototype._normalCloseCode=1e3,f.prototype._reconnectableStatusCodes=[4e3],f.prototype.safeDigest=function(e){e&&!this.scope.$$phase&&this.scope.$digest()},f.prototype.bindToScope=function(t){var o=this;return t&&(this.scope=t,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=e})),o},f.prototype._connect=function(e){(e||!this.socket||this.socket.readyState!==this._readyStateConstants.OPEN)&&(this.socket=p.create(this.url,this.protocols),this.socket.onmessage=angular.bind(this,this._onMessageHandler),this.socket.onopen=angular.bind(this,this._onOpenHandler),this.socket.onerror=angular.bind(this,this._onErrorHandler),this.socket.onclose=angular.bind(this,this._onCloseHandler))},f.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var e=this.sendQueue.shift();this.socket.send(r(e.message)?e.message:JSON.stringify(e.message)),e.deferred.resolve()}},f.prototype.notifyOpenCallbacks=function(e){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this,e)},f.prototype.notifyCloseCallbacks=function(e){for(var t=0;t<this.onCloseCallbacks.length;t++)this.onCloseCallbacks[t].call(this,e)},f.prototype.notifyErrorCallbacks=function(e){for(var t=0;t<this.onErrorCallbacks.length;t++)this.onErrorCallbacks[t].call(this,e)},f.prototype.onOpen=function(e){return this.onOpenCallbacks.push(e),this},f.prototype.onClose=function(e){return this.onCloseCallbacks.push(e),this},f.prototype.onError=function(e){return this.onErrorCallbacks.push(e),this},f.prototype.onMessage=function(e,t){if(!i(e))throw new Error("Callback must be a function");if(t&&a(t.filter)&&!r(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:!0}),this},f.prototype._onOpenHandler=function(e){this._reconnectAttempts=0,this.notifyOpenCallbacks(e),this.fireQueue()},f.prototype._onCloseHandler=function(e){this.notifyCloseCallbacks(e),(this.reconnectIfNotNormalClose&&e.code!==this._normalCloseCode||this._reconnectableStatusCodes.indexOf(e.code)>-1)&&this.reconnect()},f.prototype._onErrorHandler=function(e){this.notifyErrorCallbacks(e)},f.prototype._onMessageHandler=function(e){function t(e,t,o){o=h.call(arguments,2),s.useApplyAsync?s.scope.$applyAsync(function(){e.apply(s,o)}):(e.apply(s,o),s.safeDigest(t))}for(var o,n,s=this,i=0;i<s.onMessageCallbacks.length;i++)n=s.onMessageCallbacks[i],o=n.pattern,o?r(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)},f.prototype.close=function(e){return(e||!this.socket.bufferedAmount)&&this.socket.close(),this},f.prototype.send=function(e){function o(e){e.cancel=n;var t=e.then;return e.then=function(){var e=t.apply(this,arguments);return o(e)},e}function n(t){return r.sendQueue.splice(r.sendQueue.indexOf(e),1),s.reject(t),r}var s=t.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:e,deferred:s}),r.fireQueue()),p.isMocked&&p.isMocked()&&p.isConnected(this.url)&&this._onMessageHandler(p.mockSend()),i},f.prototype.reconnect=function(){this.close();var e=this._getBackoffDelay(++this._reconnectAttempts),t=e/1e3;return console.log("Reconnecting in "+t+" seconds"),o(angular.bind(this,this._connect),e),this},f.prototype._getBackoffDelay=function(e){var t=Math.random()+1,o=this.initialTimeout,n=2,s=e,r=this.maxTimeout;return Math.floor(Math.min(t*o*Math.pow(n,s),r))},f.prototype._setInternalState=function(e){if(Math.floor(e)!==e||0>e||e>4)throw new Error("state must be an integer between 0 and 4, got: "+e);s||(this.readyState=e||this.socket.readyState),this._internalConnectionState=e,u(this.sendQueue,function(e){e.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(e,t,o){return new f(e,t,o)}}function t(e,t){this.create=function(t,o){var n,s,r=/wss?:\/\//.exec(t);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||e.WebSocket||e.MozWebSocket,o?new n(t,o):new n(t)},this.createWebSocketBackend=function(e,o){return t.warn("Deprecated: Please use .create(url, protocols)"),this.create(e,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,h=Array.prototype.slice;Array.prototype.indexOf||(Array.prototype.indexOf=function(e){var t=this.length>>>0,o=Number(arguments[1])||0;for(o=0>o?Math.ceil(o):Math.floor(o),0>o&&(o+=t);t>o;o++)if(o in this&&this[o]===e)return o;return-1}),angular.module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",e]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",e]).service("$websocketBackend",["$window","$log",t]).service("WebSocketBackend",["$window","$log",t]),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.9",
"version": "1.0.12",
"main": "angular-websocket.min.js",

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

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

# angular-websocket
# angular-websocket [![Join the chat at https://gitter.im/gdi2290/angular-websocket](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/gdi2290/angular-websocket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![gdi2290/angular-websocket API Documentation](https://www.omniref.com/github/gdi2290/angular-websocket.png)](https://www.omniref.com/github/gdi2290/angular-websocket)
[![Travis](https://img.shields.io/travis/gdi2290/angular-websocket.svg?style=flat)](https://travis-ci.org/gdi2290/angular-websocket)

@@ -20,4 +21,4 @@ [![Bower](https://img.shields.io/bower/v/angular-websocket.svg?style=flat)](https://github.com/gdi2290/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`
* CDN for development `https://rawgit.com/gdi2290/angular-websocket/v1.0.9/angular-websocket.js`
* CDN for production `https://cdn.rawgit.com/gdi2290/angular-websocket/v1.0.9/angular-websocket.min.js`

@@ -27,3 +28,3 @@ ## Usage

```html
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<script src="bower_components/angular-websocket/angular-websocket.js"></script>

@@ -61,4 +62,3 @@ <section ng-controller="SomeController">

})
.controller('SomeController', function (MyData) {
.controller('SomeController', function ($scope, MyData) {
$scope.MyData = MyData;

@@ -114,4 +114,20 @@ });

Similar to [`httpBackend`](https://ng-click.com/$httpBackend) mock in AngularJS's `ngMock` module
Similar to [`httpBackend`](https://ng-click.com/$httpBackend) mock in
AngularJS's `ngMock` module. You can use `ngWebSocketMock` to mock a websocket
server in order to test your applications:
```javascript
var $websocketBackend;
beforeEach(angular.mock.module('ngWebSocket', 'ngWebSocketMock');
beforeEach(inject(function (_$websocketBackend_) {
$websocketBackend = _$websocketBackend_;
$websocketBackend.mock();
$websocketBackend.expectConnect('ws://localhost:8080/api');
$websocketBackend.expectSend({data: JSON.stringify({test: true})});
}));
```
### Methods

@@ -148,3 +164,3 @@

In the project root directory open `index.html` in the example folder
In the project root directory open `index.html` in the example folder or browserify example

@@ -154,2 +170,4 @@ ### Distribute

### Support
You can contact me either by: [submitting](https://github.com/gdi2290/angular-websocket/issues/new) an issue, [tweeting me](https://twitter.com/share?url=''&text=@gdi2290+I+need+help+with+…) on twitter [@gdi2290](https://twitter.com/gdi2290), or chat me on [gitter](https://gitter.im/gdi2290/angular-websocket?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

@@ -171,2 +189,1 @@ ## TODO

[MIT](https://github.com/gdi2290/angular-websocket/blob/master/LICENSE)

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