angular-websocket
Advanced tools
Comparing version 1.0.13 to 1.0.14
!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 | ||
//# sourceMappingURL=angular-websocket.min.js.map |
!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 | ||
//# sourceMappingURL=angular-websocket.min.js.map |
{ | ||
"name": "angular-websocket", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"main": "angular-websocket.min.js", | ||
"description": "An AngularJS 1.x WebSocket service for connecting client applications to servers.", | ||
"homepage": "https://github.com/gdi2290/angular-websocket", | ||
"bugs": "https://github.com/gdi2290/angular-websocket/issues", | ||
"description": "An Angular WebSocket service for connecting client applications to servers.", | ||
"homepage": "https://github.com/angular-class/angular-websocket", | ||
"bugs": "https://github.com/angular-class/angular-websocket/issues", | ||
"keywords": [ | ||
@@ -20,2 +20,4 @@ "angular", | ||
"ngWebSockets", | ||
"angular-class", | ||
"AngularClass", | ||
"gdi2290", | ||
@@ -35,9 +37,5 @@ "PatrickJS" | ||
"type": "git", | ||
"url": "git@github.com:gdi2290/angular-websocket.git" | ||
"url": "git@github.com:angular-class/angular-websocket.git" | ||
}, | ||
"licenses": [ | ||
{ | ||
"type": "MIT" | ||
} | ||
], | ||
"license": "Apache-2.0", | ||
"browser": { | ||
@@ -44,0 +42,0 @@ "angular-websocket": "./dist/angular-websocket.js", |
@@ -180,4 +180,15 @@ # 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) | ||
* Add PubNub support | ||
___ | ||
enjoy — **AngularClass** | ||
<br><br> | ||
[![AngularClass](https://cloud.githubusercontent.com/assets/1016365/9863770/cb0620fc-5af7-11e5-89df-d4b0b2cdfc43.png "Angular Class")](https://angularclass.com) | ||
##[AngularClass](https://angularclass.com) | ||
> Learn AngularJS, Angular 2, and Modern Web Development form the best. | ||
> Looking for corporate Angular training, want to host us, or Angular consulting? patrick@angularclass.com | ||
## License | ||
[MIT](https://github.com/gdi2290/angular-websocket/blob/master/LICENSE) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
85656
888
194