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

angular-websocket

Package Overview
Dependencies
Maintainers
2
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.1.0 to 2.0.0

22

CHANGELOG.md

@@ -0,1 +1,23 @@

## 2.0.0 (2016-5-21)
Features:
- Repackage library
- Package source files no longer duplicated
Bugfixes:
- autoApply is undefined error
- arraybuffer data type
BREAKING CHANGES:
- package source files are not duplicated
- if using files from `/`, use `/dist/` instead
- change `/angular-websocket-mock.js` to `/dist/angular-websocket-mock.js`
- change `/angular-websocket.js` to `/dist/angular-websocket.js`
- change `/angular-websocket-min.js` to `/dist/angular-websocket-min.js`
- change `/angular-websocket-min.js.map` to `/dist/angular-websocket-min.js.map`
## 1.1.0 (2016-4-4)
## 1.0.14 (2015-9-15)
## 1.0.13 (2015-6-2)

@@ -2,0 +24,0 @@ Build:

49

dist/angular-websocket-mock.js

@@ -1,4 +0,24 @@

(function() {
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', 'angular'], factory);
} else if (typeof exports !== "undefined") {
factory(module, require('angular'));
} else {
var mod = {
exports: {}
};
factory(mod, global.angular);
global.angularWebsocketMock = mod.exports;
}
})(this, function (module, _angular) {
'use strict';
var _angular2 = _interopRequireDefault(_angular);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
function $WebSocketBackend() {

@@ -13,7 +33,5 @@ var connectQueue = [];

function $MockWebSocket(url, protocols) {
this.protocols = protocols;
this.ssl = /(wss)/i.test(this.url);
}

@@ -25,3 +43,3 @@

this.mockSend = function() {
this.mockSend = function () {
if (mock) {

@@ -32,3 +50,3 @@ return sendQueue.shift();

this.mock = function() {
this.mock = function () {
mock = true;

@@ -38,7 +56,7 @@ };

this.isMocked = function () {
return mock;
return mock;
};
this.isConnected = function(url) {
return connectQueue.indexOf(url) > -1;
this.isConnected = function (url) {
return connectQueue.indexOf(url) > -1;
};

@@ -82,3 +100,3 @@

var j;
sendQueue.forEach(function(pending, i) {
sendQueue.forEach(function (pending, i) {
if (pending.message === msg.message) {

@@ -119,14 +137,9 @@ j = i;

};
} // end $WebSocketBackend
angular.module('ngWebSocketMock', [])
.service('WebSocketBackend', $WebSocketBackend)
.service('$websocketBackend', $WebSocketBackend);
_angular2.default.module('ngWebSocketMock', []).service('WebSocketBackend', $WebSocketBackend).service('$websocketBackend', $WebSocketBackend);
angular.module('angular-websocket-mock', ['ngWebSocketMock']);
_angular2.default.module('angular-websocket-mock', ['ngWebSocketMock']);
if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocketMock');
}
}());
module.exports = _angular2.default.module('ngWebSocketMock');
});

@@ -1,20 +0,62 @@

(function() {
(function (global, factory) {
if (typeof define === "function" && define.amd) {
define(['module', 'exports', 'angular', 'ws'], factory);
} else if (typeof exports !== "undefined") {
factory(module, exports, require('angular'), require('ws'));
} else {
var mod = {
exports: {}
};
factory(mod, mod.exports, global.angular, global.ws);
global.angularWebsocket = mod.exports;
}
})(this, function (module, exports, _angular, ws) {
'use strict';
var noop = angular.noop;
var objectFreeze = (Object.freeze) ? Object.freeze : noop;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _angular2 = _interopRequireDefault(_angular);
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
var Socket;
if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof require === 'function') {
try {
Socket = ws.Client || ws.client || ws;
} catch (e) {}
}
// Browser
Socket = Socket || window.WebSocket || window.MozWebSocket;
var noop = _angular2.default.noop;
var objectFreeze = Object.freeze ? Object.freeze : noop;
var objectDefineProperty = Object.defineProperty;
var isString = angular.isString;
var isFunction = angular.isFunction;
var isDefined = angular.isDefined;
var isObject = angular.isObject;
var isArray = angular.isArray;
var forEach = angular.forEach;
var isString = _angular2.default.isString;
var isFunction = _angular2.default.isFunction;
var isDefined = _angular2.default.isDefined;
var isObject = _angular2.default.isObject;
var isArray = _angular2.default.isArray;
var forEach = _angular2.default.forEach;
var arraySlice = Array.prototype.slice;
// ie8 wat
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(elt /*, from*/) {
Array.prototype.indexOf = function (elt /*, from*/) {
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
from = from < 0 ? Math.ceil(from) : Math.floor(from);
if (from < 0) {

@@ -25,3 +67,5 @@ from += len;

for (; from < len; from++) {
if (from in this && this[from] === elt) { return from; }
if (from in this && this[from] === elt) {
return from;
}
}

@@ -52,15 +96,16 @@ return -1;

// 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.initialTimeout = options && options.initialTimeout || 500; // 500ms
this.maxTimeout = options && options.maxTimeout || 5 * 60 * 1000; // 5 minutes
this.reconnectIfNotNormalClose = options && options.reconnectIfNotNormalClose || false;
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.binaryType = options && options.binaryType || 'blob';
this._reconnectAttempts = 0;
this.sendQueue = [];
this.onOpenCallbacks = [];
this.sendQueue = [];
this.onOpenCallbacks = [];
this.onMessageCallbacks = [];
this.onErrorCallbacks = [];
this.onCloseCallbacks = [];
this.onErrorCallbacks = [];
this.onCloseCallbacks = [];

@@ -74,6 +119,4 @@ objectFreeze(this._readyStateConstants);

}
}
$WebSocket.prototype._readyStateConstants = {

@@ -89,5 +132,3 @@ 'CONNECTING': 0,

$WebSocket.prototype._reconnectableStatusCodes = [
4000
];
$WebSocket.prototype._reconnectableStatusCodes = [4000];

@@ -105,3 +146,3 @@ $WebSocket.prototype.safeDigest = function safeDigest(autoApply) {

if (this.rootScopeFailover) {
this.scope.$on('$destroy', function() {
this.scope.$on('$destroy', function () {
self.scope = $rootScope;

@@ -117,6 +158,7 @@ });

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

@@ -129,5 +171,3 @@ };

this.socket.send(
isString(data.message) ? data.message : JSON.stringify(data.message)
);
this.socket.send(isString(data.message) || this.binaryType != 'blob' ? data.message : JSON.stringify(data.message));
data.deferred.resolve();

@@ -170,3 +210,2 @@ }

$WebSocket.prototype.onMessage = function onMessage(callback, options) {

@@ -198,3 +237,3 @@ if (!isFunction(callback)) {

if (self.useApplyAsync) {
self.scope.$applyAsync(function() {
self.scope.$applyAsync(function () {
self.notifyCloseCallbacks(event);

@@ -204,5 +243,5 @@ });

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

@@ -215,3 +254,3 @@ }

if (self.useApplyAsync) {
self.scope.$applyAsync(function() {
self.scope.$applyAsync(function () {
self.notifyErrorCallbacks(event);

@@ -221,3 +260,3 @@ });

self.notifyErrorCallbacks(event);
self.safeDigest(autoApply);
self.safeDigest(true);
}

@@ -236,8 +275,6 @@ };

applyAsyncOrDigest(currentCallback.fn, currentCallback.autoApply, message);
}
else if (pattern instanceof RegExp && pattern.exec(message.data)) {
} else if (pattern instanceof RegExp && pattern.exec(message.data)) {
applyAsyncOrDigest(currentCallback.fn, currentCallback.autoApply, message);
}
}
else {
} else {
applyAsyncOrDigest(currentCallback.fn, currentCallback.autoApply, message);

@@ -250,3 +287,3 @@ }

if (self.useApplyAsync) {
self.scope.$applyAsync(function() {
self.scope.$applyAsync(function () {
callback.apply(self, args);

@@ -259,3 +296,2 @@ });

}
};

@@ -277,4 +313,3 @@

deferred.reject('Socket connection has been closed');
}
else {
} else {
self.sendQueue.push({

@@ -291,3 +326,3 @@ message: data,

var then = promise.then;
promise.then = function() {
promise.then = function () {
var newPromise = then.apply(this, arguments);

@@ -305,4 +340,3 @@ return cancelableify(newPromise);

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

@@ -322,3 +356,3 @@ }

$timeout(angular.bind(this, this._connect), backoffDelay);
$timeout(_angular2.default.bind(this, this._connect), backoffDelay);

@@ -350,4 +384,3 @@ return this;

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

@@ -360,6 +393,6 @@ });

objectDefineProperty($WebSocket.prototype, 'readyState', {
get: function() {
get: function get() {
return this._internalConnectionState || this.socket.readyState;
},
set: function() {
set: function set() {
throw new Error('The readyState property is read-only');

@@ -370,3 +403,3 @@ }

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

@@ -376,7 +409,7 @@ };

// $WebSocketBackendProvider.$inject = ['$window', '$log'];
function $WebSocketBackendProvider($window, $log) {
// $WebSocketBackendProvider.$inject = ['$log'];
function $WebSocketBackendProvider($log) {
this.create = function create(url, protocols) {
var match = /wss?:\/\//.exec(url);
var Socket, ws;
if (!match) {

@@ -386,13 +419,2 @@ throw new Error('Invalid url provided');

// CommonJS
if (typeof exports === 'object' && require) {
try {
ws = require('ws');
Socket = (ws.Client || ws.client || ws);
} catch(e) {}
}
// Browser
Socket = Socket || $window.WebSocket || $window.MozWebSocket;
if (protocols) {

@@ -404,2 +426,3 @@ return new Socket(url, protocols);

};
this.createWebSocketBackend = function createWebSocketBackend(url, protocols) {

@@ -411,14 +434,8 @@ $log.warn('Deprecated: Please use .create(url, protocols)');

angular.module('ngWebSocket', [])
.factory('$websocket', ['$rootScope', '$q', '$timeout', '$websocketBackend', $WebSocketProvider])
.factory('WebSocket', ['$rootScope', '$q', '$timeout', 'WebsocketBackend', $WebSocketProvider])
.service('$websocketBackend', ['$window', '$log', $WebSocketBackendProvider])
.service('WebSocketBackend', ['$window', '$log', $WebSocketBackendProvider]);
_angular2.default.module('ngWebSocket', []).factory('$websocket', ['$rootScope', '$q', '$timeout', '$websocketBackend', $WebSocketProvider]).factory('WebSocket', ['$rootScope', '$q', '$timeout', 'WebsocketBackend', $WebSocketProvider]).service('$websocketBackend', ['$log', $WebSocketBackendProvider]).service('WebSocketBackend', ['$log', $WebSocketBackendProvider]);
_angular2.default.module('angular-websocket', ['ngWebSocket']);
angular.module('angular-websocket', ['ngWebSocket']);
if (typeof module === 'object' && typeof define !== 'function') {
module.exports = angular.module('ngWebSocket');
}
}());
exports.default = _angular2.default.module('ngWebSocket');
module.exports = exports['default'];
});

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

!function(){"use strict";function e(e,t,o,h){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=h.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(!a(e))throw new Error("Callback must be a function");if(t&&i(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){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyCloseCallbacks(e)}):(t.notifyCloseCallbacks(e),t.safeDigest(autoApply)),(this.reconnectIfNotNormalClose&&e.code!==this._normalCloseCode||this._reconnectableStatusCodes.indexOf(e.code)>-1)&&this.reconnect()},f.prototype._onErrorHandler=function(e){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyErrorCallbacks(e)}):(t.notifyErrorCallbacks(e),t.safeDigest(autoApply))},f.prototype._onMessageHandler=function(e){function t(e,t,o){o=p.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,a=0;a<s.onMessageCallbacks.length;a++)n=s.onMessageCallbacks[a],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,a=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()),h.isMocked&&h.isMocked()&&h.isConnected(this.url)&&this._onMessageHandler(h.mockSend()),a},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(a){}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,a=angular.isFunction,i=angular.isDefined,c=angular.isObject,l=angular.isArray,u=angular.forEach,p=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"))}();
!function(e,t){if("function"==typeof define&&define.amd)define(["module","exports","angular","ws"],t);else if("undefined"!=typeof exports)t(module,exports,require("angular"),require("ws"));else{var o={exports:{}};t(o,o.exports,e.angular,e.ws),e.angularWebsocket=o.exports}}(this,function(e,t,o,n){"use strict";function s(e){return e&&e.__esModule?e:{"default":e}}function r(e,t,o,n){function s(t,o,n){n||!k(o)||C(o)||(n=o,o=void 0),this.protocols=o,this.url=t||"Missing URL",this.ssl=/(wss)/i.test(this.url),this.scope=n&&n.scope||e,this.rootScopeFailover=n&&n.rootScopeFailover&&!0,this.useApplyAsync=n&&n.useApplyAsync||!1,this.initialTimeout=n&&n.initialTimeout||500,this.maxTimeout=n&&n.maxTimeout||3e5,this.reconnectIfNotNormalClose=n&&n.reconnectIfNotNormalClose||!1,this.binaryType=n&&n.binaryType||"blob",this._reconnectAttempts=0,this.sendQueue=[],this.onOpenCallbacks=[],this.onMessageCallbacks=[],this.onErrorCallbacks=[],this.onCloseCallbacks=[],f(this._readyStateConstants),t?this._connect():this._setInternalState(0)}return s.prototype._readyStateConstants={CONNECTING:0,OPEN:1,CLOSING:2,CLOSED:3,RECONNECT_ABORTED:4},s.prototype._normalCloseCode=1e3,s.prototype._reconnectableStatusCodes=[4e3],s.prototype.safeDigest=function(e){e&&!this.scope.$$phase&&this.scope.$digest()},s.prototype.bindToScope=function(t){var o=this;return t&&(this.scope=t,this.rootScopeFailover&&this.scope.$on("$destroy",function(){o.scope=e})),o},s.prototype._connect=function(e){!e&&this.socket&&this.socket.readyState===this._readyStateConstants.OPEN||(this.socket=n.create(this.url,this.protocols),this.socket.onmessage=c["default"].bind(this,this._onMessageHandler),this.socket.onopen=c["default"].bind(this,this._onOpenHandler),this.socket.onerror=c["default"].bind(this,this._onErrorHandler),this.socket.onclose=c["default"].bind(this,this._onCloseHandler),this.socket.binaryType=this.binaryType)},s.prototype.fireQueue=function(){for(;this.sendQueue.length&&this.socket.readyState===this._readyStateConstants.OPEN;){var e=this.sendQueue.shift();this.socket.send(d(e.message)||"blob"!=this.binaryType?e.message:JSON.stringify(e.message)),e.deferred.resolve()}},s.prototype.notifyOpenCallbacks=function(e){for(var t=0;t<this.onOpenCallbacks.length;t++)this.onOpenCallbacks[t].call(this,e)},s.prototype.notifyCloseCallbacks=function(e){for(var t=0;t<this.onCloseCallbacks.length;t++)this.onCloseCallbacks[t].call(this,e)},s.prototype.notifyErrorCallbacks=function(e){for(var t=0;t<this.onErrorCallbacks.length;t++)this.onErrorCallbacks[t].call(this,e)},s.prototype.onOpen=function(e){return this.onOpenCallbacks.push(e),this},s.prototype.onClose=function(e){return this.onCloseCallbacks.push(e),this},s.prototype.onError=function(e){return this.onErrorCallbacks.push(e),this},s.prototype.onMessage=function(e,t){if(!y(e))throw new Error("Callback must be a function");if(t&&b(t.filter)&&!d(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},s.prototype._onOpenHandler=function(e){this._reconnectAttempts=0,this.notifyOpenCallbacks(e),this.fireQueue()},s.prototype._onCloseHandler=function(e){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyCloseCallbacks(e)}):(t.notifyCloseCallbacks(e),t.safeDigest(!0)),(this.reconnectIfNotNormalClose&&e.code!==this._normalCloseCode||this._reconnectableStatusCodes.indexOf(e.code)>-1)&&this.reconnect()},s.prototype._onErrorHandler=function(e){var t=this;t.useApplyAsync?t.scope.$applyAsync(function(){t.notifyErrorCallbacks(e)}):(t.notifyErrorCallbacks(e),t.safeDigest(!0))},s.prototype._onMessageHandler=function(e){function t(e,t,o){o=m.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,r=0;r<s.onMessageCallbacks.length;r++)n=s.onMessageCallbacks[r],o=n.pattern,o?d(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)},s.prototype.close=function(e){return!e&&this.socket.bufferedAmount||this.socket.close(),this},s.prototype.send=function(e){function o(e){e.cancel=s;var t=e.then;return e.then=function(){var e=t.apply(this,arguments);return o(e)},e}function s(t){return i.sendQueue.splice(i.sendQueue.indexOf(e),1),r.reject(t),i}var r=t.defer(),i=this,a=o(r.promise);return i.readyState===i._readyStateConstants.RECONNECT_ABORTED?r.reject("Socket connection has been closed"):(i.sendQueue.push({message:e,deferred:r}),i.fireQueue()),n.isMocked&&n.isMocked()&&n.isConnected(this.url)&&this._onMessageHandler(n.mockSend()),a},s.prototype.reconnect=function(){this.close();var e=this._getBackoffDelay(++this._reconnectAttempts),t=e/1e3;return console.log("Reconnecting in "+t+" seconds"),o(c["default"].bind(this,this._connect),e),this},s.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))},s.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);h||(this.readyState=e||this.socket.readyState),this._internalConnectionState=e,g(this.sendQueue,function(e){e.deferred.reject("Message cancelled due to closed socket connection")})},h&&h(s.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 s(e,t,o)}}function i(e){this.create=function(e,t){var o=/wss?:\/\//.exec(e);if(!o)throw new Error("Invalid url provided");return t?new a(e,t):new a(e)},this.createWebSocketBackend=function(t,o){return e.warn("Deprecated: Please use .create(url, protocols)"),this.create(t,o)}}Object.defineProperty(t,"__esModule",{value:!0});var a,c=s(o),l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};if("object"===("undefined"==typeof t?"undefined":l(t))&&"function"==typeof require)try{a=n.Client||n.client||n}catch(u){}a=a||window.WebSocket||window.MozWebSocket;var p=c["default"].noop,f=Object.freeze?Object.freeze:p,h=Object.defineProperty,d=c["default"].isString,y=c["default"].isFunction,b=c["default"].isDefined,k=c["default"].isObject,C=c["default"].isArray,g=c["default"].forEach,m=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}),c["default"].module("ngWebSocket",[]).factory("$websocket",["$rootScope","$q","$timeout","$websocketBackend",r]).factory("WebSocket",["$rootScope","$q","$timeout","WebsocketBackend",r]).service("$websocketBackend",["$log",i]).service("WebSocketBackend",["$log",i]),c["default"].module("angular-websocket",["ngWebSocket"]),t["default"]=c["default"].module("ngWebSocket"),e.exports=t["default"]});
//# sourceMappingURL=angular-websocket.min.js.map
{
"name": "angular-websocket",
"version": "1.1.0",
"main": "angular-websocket.min.js",
"version": "2.0.0",
"main": "./dist/angular-websocket.js",
"description": "An Angular WebSocket service for connecting client applications to servers.",

@@ -26,4 +26,8 @@ "homepage": "https://github.com/angular-class/angular-websocket",

"scripts": {
"test": "./test.sh",
"dist": "./dist.sh"
"pretest": "npm run dist",
"test": "karma start karma.conf.js",
"predist": "rimraf dist/ && mkdirp dist/",
"dist": "babel src/ --out-dir dist/",
"postdist": "uglifyjs dist/angular-websocket.js > dist/angular-websocket.min.js --source-map dist/angular-websocket.min.js.map --source-map-url angular-websocket.min.js.map --mangle --compress --stats",
"example": "browserify --debug -t browserify-ngannotate ./example/browserify-example/app/app.js --outfile ./example/browserify-example/bundle.js"
},

@@ -40,6 +44,2 @@ "author": {

"license": "MIT",
"browser": {
"angular-websocket": "./dist/angular-websocket.js",
"angular-websocket-mock": "./dist/angular-websocket-mock.js"
},
"dependencies": {

@@ -51,2 +51,6 @@ "angular": "*",

"angular-animate": "^1.3.13",
"babel-cli": "^6.7.5",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-transform-es2015-modules-umd": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"browserify": "^13.0.0",

@@ -65,2 +69,3 @@ "browserify-ngannotate": "^2.0.0",

"karma-slimerjs-launcher": "^0.2.0",
"mkdirp": "^0.5.1",
"ng-annotate": "^1.0.0",

@@ -70,2 +75,3 @@ "phantomjs": "^2.1.3",

"requirejs": "^2.1.16",
"rimraf": "^2.5.2",
"uglify-js": "^2.4.16",

@@ -72,0 +78,0 @@ "utf-8-validate": "^1.2.1"

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