@schoolbelle/common
Version:
Demo library to showcase Angular packaging format
2 lines • 2.75 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("@schoolbelle/common/tokens"),require("rxjs"),require("socket.io-client")):"function"==typeof define&&define.amd?define("@schoolbelle/common/services/socket",["exports","@angular/core","@schoolbelle/common/tokens","rxjs","socket.io-client"],t):t((e.schoolbelle=e.schoolbelle||{},e.schoolbelle.common=e.schoolbelle.common||{},e.schoolbelle.common.services=e.schoolbelle.common.services||{},e.schoolbelle.common.services.socket={}),e.ng.core,e.schoolbelle.common.tokens,e.rxjs,null)}(this,function(e,t,o,n,c){"use strict";c=c&&c.hasOwnProperty("default")?c["default"]:c;var s=function(){function e(e,t){var o=this;this.ngZone=e,this.socketHost=t,this.listeners=new Map,this.subject=new n.Subject,this.socket=c(this.socketHost,{autoConnect:!1}),this.socket.on("connect",function(){console.log("connected as "+o.socket.id),o.listeners.forEach(function(e){o.listen(e.event,e.timeout)})})}return e.prototype.connect=function(o){var n=this;return void 0===o&&(o=!1),console.log("socket will connect."),new Promise(function(e,t){n.ngZone.runOutsideAngular(function(){n.socket.connected&&!0===o&&n.socket.close(),n.socket.connected?e(!0):(n.socket.open(),n.socket.once("connect",function(){return e(!0)}))})})},e.prototype.timeout=function(e,t){var o=this;if(void 0===t&&(t=undefined),"number"==typeof t)return setTimeout(function(){o.unlisten(e)},t)},e.prototype.listen=function(t,o){var n,c=this;(void 0===o&&(o=undefined),this.listeners.get(t))||("number"==typeof this.timeout&&(n=this.timeout(t,o)),this.connect().then(function(){c.socket.on(t,function(e){n&&clearTimeout(n),n=c.timeout(t,o),c.subject.next({event:t,data:e})}),c.listeners.set(t,{event:t,timeout:o})}))},e.prototype.unlisten=function(e){this.listeners.get(e)&&(this.listeners["delete"](e),this.socket.off(e))},e.prototype.join=function(e){var t=this;this.ngZone.runOutsideAngular(function(){t.connect().then(function(){t.socket.emit("subscribe",e)})})},e.prototype.leave=function(e){var t=this;this.ngZone.runOutsideAngular(function(){t.connect().then(function(){t.socket.emit("unsubscribe",e)})})},e.prototype.getObservable=function(t){return this.subject.asObservable().filter(function(e){return e.event===t})},e.decorators=[{type:t.Injectable}],e.ctorParameters=function(){return[{type:t.NgZone},{type:undefined,decorators:[{type:t.Inject,args:[o.SOCKET_SERVER_HOST]}]}]},e}(),i=function(){function e(){}return e.forRoot=function(){return{ngModule:e,providers:[s]}},e.decorators=[{type:t.NgModule,args:[{}]}],e}();e.SocketServiceModule=i,e.SocketService=s,Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=schoolbelle-common-services-socket.umd.min.js.map