@chatie/angular
Advanced tools
Comparing version 0.5.5 to 0.6.1
@@ -224,3 +224,3 @@ (function (global, factory) { | ||
*/ | ||
var VERSION = '0.5.5'; | ||
var VERSION = '0.6.1'; | ||
@@ -227,0 +227,0 @@ var ReadyState; |
@@ -15,3 +15,3 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("brolog"),require("state-switch")):"function"==typeof define&&define.amd?define("@chatie/angular",["exports","@angular/core","rxjs","rxjs/operators","brolog","state-switch"],t):t(((e=e||self).chatie=e.chatie||{},e.chatie.angular={}),e.ng.core,e.rxjs,e.rxjs.operators,e.brolog,e.stateSwitch)}(this,(function(e,t,o,n,i,r){"use strict"; | ||
and limitations under the License. | ||
***************************************************************************** */function s(e,t,o,n){var i,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(r<3?i(s):r>3?i(t,o,s):i(t,o))||s);return r>3&&s&&Object.defineProperty(t,o,s),s}function a(e,t,o,n){return new(o||(o=Promise))((function(i,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function c(e,t){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=t.call(e,s)}catch(e){r=[6,e],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}var h;!function(e){e[e.CLOSED=WebSocket.CLOSED]="CLOSED",e[e.CLOSING=WebSocket.CLOSING]="CLOSING",e[e.CONNECTING=WebSocket.CONNECTING]="CONNECTING",e[e.OPEN=WebSocket.OPEN]="OPEN"}(h||(h={}));var u=function(){function e(){this.autoReconnect=!0,this.log=i.Brolog.instance(),this.CONNECT_TIMEOUT=1e4,this.ENDPOINT="wss://api.chatie.io/v0/websocket/token/",this.PROTOCOL="web|0.0.1",this.sendBuffer=[],this.log.verbose("IoService","constructor()")}return Object.defineProperty(e.prototype,"readyState",{get:function(){return this._readyState.asObservable()},enumerable:!0,configurable:!0}),e.prototype.init=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(n){switch(n.label){case 0:if(this.log.verbose("IoService","init()"),this.state)throw new Error("re-init");this.snapshot={readyState:h.CLOSED,event:null},this._readyState=new o.BehaviorSubject(h.CLOSED),this.state=new r.StateSwitch("IoService",this.log),this.state.setLog(this.log),n.label=1;case 1:return n.trys.push([1,4,,5]),[4,this.initStateDealer()];case 2:return n.sent(),[4,this.initRxSocket()];case 3:return n.sent(),[3,5];case 4:throw e=n.sent(),this.log.silly("IoService","init() exception: %s",e.message),e;case 5:return this.readyState.subscribe((function(e){t.log.silly("IoService","init() readyState.subscribe(%s)",h[e]),t.snapshot.readyState=e})),this.event.subscribe((function(e){t.log.silly("IoService","init() event.subscribe({name:%s})",e.name),t.snapshot.event=e})),[2]}}))}))},e.prototype.token=function(e){if(this.log.silly("IoService","token(%s)",e),!e)return this._token;this._token=e},e.prototype.start=function(){return a(this,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:if(this.log.verbose("IoService","start() with token:%s",this._token),!this._token)throw new Error("start() without token");if(this.state.on())throw new Error("state is already ON");if(this.state.pending())throw new Error("state is pending");this.state.on("pending"),this.autoReconnect=!0,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.connectRxSocket()];case 2:return t.sent(),this.state.on(!0),[3,4];case 3:return e=t.sent(),this.log.warn("IoService","start() failed:%s",e.message),this.state.off(!0),[3,4];case 4:return[2]}}))}))},e.prototype.stop=function(){return a(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:if(this.log.verbose("IoService","stop()"),this.state.off()){if(this.log.warn("IoService","stop() state is already off"),this.state.pending())throw new Error("state pending() is true");return[2]}if(this.state.off("pending"),this.autoReconnect=!1,!this._websocket)throw new Error("no websocket");return[4,this.socketClose(1e3,"IoService.stop()")];case 1:return e.sent(),this.state.off(!0),[2]}}))}))},e.prototype.restart=function(){return a(this,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:this.log.verbose("IoService","restart()"),t.label=1;case 1:return t.trys.push([1,4,,5]),[4,this.stop()];case 2:return t.sent(),[4,this.start()];case 3:return t.sent(),[3,5];case 4:throw e=t.sent(),this.log.error("IoService","restart() error:%s",e.message),e;case 5:return[2]}}))}))},e.prototype.initStateDealer=function(){var e=this;this.log.verbose("IoService","initStateDealer()"),this.readyState.pipe(n.filter((function(e){return e===h.OPEN}))).subscribe((function(t){return e.stateOnOpen()}))},e.prototype.initRxSocket=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(i){if(this.log.verbose("IoService","initRxSocket()"),this.event)throw new Error("re-init is not permitted");return this.moObserver={next:this.socketSend.bind(this),error:this.socketClose.bind(this),complete:this.socketClose.bind(this)},e=o.Observable.create((function(e){return t.log.verbose("IoService","initRxSocket() Observable.create()"),t.mtObserver=e,t.socketClose.bind(t)})),this.event=o.Subject.create(this.moObserver,e.pipe(n.share())),[2]}))}))},e.prototype.connectRxSocket=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(o){if(this.log.verbose("IoService","connectRxSocket()"),this._websocket)throw new Error("already has a websocket");if(this.state.off())throw new Error("switch state is off");if(!this.state.pending())throw new Error("switch state is already ON");return this._websocket=new WebSocket(this.endPoint(),this.PROTOCOL),this.socketUpdateState(),e=new Promise((function(e,o){t.log.verbose("IoService","connectRxSocket() Promise()");var n=setTimeout((function(){t._websocket=null;var e=new Error("rxSocket connect timeout after "+Math.round(t.CONNECT_TIMEOUT/1e3));o(e)}),t.CONNECT_TIMEOUT);t._websocket.onopen=function(o){t.log.verbose("IoService","connectRxSocket() Promise() WebSocket.onOpen() resolve()"),t.socketUpdateState(),clearTimeout(n),e()}})),this._websocket.onmessage=this.socketOnMessage.bind(this),this._websocket.onerror=this.socketOnError.bind(this),this._websocket.onclose=this.socketOnClose.bind(this),[2,e]}))}))},e.prototype.endPoint=function(){var e=this.ENDPOINT+this._token;return this.log.verbose("IoService","endPoint() => %s",e),e},e.prototype.stateOnOpen=function(){this.log.verbose("IoService","stateOnOpen()"),this.socketSendBuffer(),this.rpcUpdate("from stateOnOpen()")},e.prototype.rpcDing=function(e){return a(this,void 0,void 0,(function(){var t;return c(this,(function(o){return this.log.verbose("IoService","ding(%s)",e),t={name:"ding",payload:e},this.event.next(t),[2]}))}))},e.prototype.rpcUpdate=function(e){return a(this,void 0,void 0,(function(){return c(this,(function(t){return this.event.next({name:"update",payload:e}),[2]}))}))},e.prototype.socketClose=function(e,t){return a(this,void 0,void 0,(function(){var o=this;return c(this,(function(i){switch(i.label){case 0:if(this.log.verbose("IoService","socketClose()"),!this._websocket)throw new Error("no websocket");return this._websocket.close(e,t),this.socketUpdateState(),[4,new Promise((function(e){o.readyState.pipe(n.filter((function(e){return e===h.CLOSED}))).subscribe(e)}))];case 1:return i.sent(),[2]}}))}))},e.prototype.socketSend=function(e){this.log.silly("IoService","socketSend({name:%s, payload:%s})",e.name,e.payload),this._websocket||this.log.silly("IoService","socketSend() no _websocket");var t=JSON.stringify(e);this.sendBuffer.push(t),this.socketSendBuffer()},e.prototype.socketSendBuffer=function(){if(this.log.silly("IoService","socketSendBuffer() length:%s",this.sendBuffer.length),!this._websocket)throw new Error("socketSendBuffer(): no _websocket");if(this._websocket.readyState===WebSocket.OPEN)for(;this.sendBuffer.length;){var e=this.sendBuffer.shift();this.log.silly("IoService","socketSendBuffer() sending(%s)",e),this._websocket.send(e)}else this.log.warn("IoService","socketSendBuffer() readyState is not OPEN, send job delayed.")},e.prototype.socketUpdateState=function(){this.log.verbose("IoService","socketUpdateState() is %s",h[this._websocket.readyState]),this._websocket?this._readyState.next(this._websocket.readyState):this.log.error("IoService","socketUpdateState() no _websocket")},e.prototype.socketOnMessage=function(e){this.log.verbose("IoService","onMessage({data: %s})",e.data);var t=e.data,o={name:"raw",payload:t};try{var n=JSON.parse(t);o.name=n.name,o.payload=n.payload}catch(e){this.log.warn("IoService","onMessage parse message fail. save as RAW")}this.mtObserver.next(o)},e.prototype.socketOnError=function(e){this.log.silly("IoService","socketOnError(%s)",e)},e.prototype.socketOnClose=function(e){var t=this;this.log.verbose("IoService","socketOnClose({code:%s, reason:%s, returnValue:%s})",e.code,e.reason,e.returnValue),this.socketUpdateState(),this.autoReconnect?(this.state.on("pending"),setTimeout((function(){return a(t,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.connectRxSocket()];case 1:return t.sent(),this.state.on(!0),[3,3];case 2:return e=t.sent(),this.log.warn("IoService","socketOnClose() autoReconnect() exception: %s",e),this.state.off(!0),[3,3];case 3:return[2]}}))}))}),1e3)):this.state.off(!0),this._websocket=null,e.wasClean||this.log.warn("IoService","socketOnClose() event.wasClean FALSE")},e}(),l=function(){function e(e,o){this.log=e,this.ngZone=o,this.message=new t.EventEmitter,this.scan=new t.EventEmitter,this.login=new t.EventEmitter,this.logout=new t.EventEmitter,this.error=new t.EventEmitter,this.heartbeat=new t.EventEmitter,this.timerSub=null,this.counter=0,this.timestamp=new Date,this.log.verbose("WechatyComponent","constructor() v%s","0.5.5")}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},set:function(e){this.log.verbose("WechatyComponent","set token(%s)",e);var t=(e||"").trim();if(this._token!==t){if(this._token=t,!this.ioService)return this.log.silly("WechatyComponent","set token() skip token init value"),void this.log.silly("WechatyComponent","set token() because ioService will do it inside ngOnInit()");this.log.silly("WechatyComponent","set token(%s) reloading ioService now...",t),this.ioService.token(this.token),this.ioService.restart()}else this.log.silly("WechatyComponent","set token(%s) not new",t)},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){return a(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return this.log.verbose("WechatyComponent","ngOninit() with token: "+this.token),this.ioService=new u,[4,this.ioService.init()];case 1:return e.sent(),this.ioService.event.subscribe(this.onIo.bind(this)),this.log.silly("WechatyComponent","ngOninit() ioService.event.subscribe()-ed"),this.token?(this.ioService.token(this.token),[4,this.ioService.start()]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},e.prototype.ngOnDestroy=function(){this.log.verbose("WechatyComponent","ngOnDestroy()"),this.endTimer(),this.ioService&&this.ioService.stop()},e.prototype.onIo=function(e){switch(this.log.silly("WechatyComponent","onIo#%d(%s)",this.counter++,e.name),this.timestamp=new Date,e.name){case"scan":this.scan.emit(e.payload);break;case"login":this.login.emit(e.payload);break;case"logout":this.logout.emit(e.payload);break;case"message":this.message.emit(e.payload);break;case"error":this.error.emit(e.payload);break;case"ding":case"dong":case"raw":this.heartbeat.emit(e.name+"["+e.payload+"]");break;case"heartbeat":this.heartbeat.emit(e.payload);break;case"sys":this.log.silly("WechatyComponent","onIo(%s): %s",e.name,e.payload);break;default:this.log.warn("WechatyComponent","onIo() unknown event name: %s[%s]",e.name,e.payload)}},e.prototype.reset=function(e){this.log.verbose("WechatyComponent","reset(%s)",e);var t={name:"reset",payload:e};if(!this.ioService)throw new Error("no ioService");this.ioService.event.next(t)},e.prototype.shutdown=function(e){this.log.verbose("WechatyComponent","shutdown(%s)",e);var t={name:"shutdown",payload:e};if(!this.ioService)throw new Error("no ioService");this.ioService.event.next(t)},e.prototype.startTimer=function(){var e=this;this.log.verbose("WechatyComponent","startTimer()"),this.ender=new o.Subject,this.ngZone.runOutsideAngular((function(){e.timer=o.interval(3e3).pipe(n.tap((function(t){e.log.verbose("do"," %d",t)})),n.takeUntil(e.ender),n.share())})),this.timerSub=this.timer.subscribe((function(t){if(e.counter=t,!e.ioService)throw new Error("no ioService");e.ioService.rpcDing(e.counter)}))},e.prototype.endTimer=function(){this.log.verbose("WechatyComponent","endTimer()"),this.timerSub&&(this.timerSub.unsubscribe(),this.timerSub=null),this.ender&&this.ender.next(null)},e.prototype.logoff=function(e){this.log.silly("WechatyComponent","logoff(%s)",e);var t={name:"logout",payload:e};this.ioService.event.next(t)},Object.defineProperty(e.prototype,"readyState",{get:function(){return this.ioService.readyState},enumerable:!0,configurable:!0}),e.ctorParameters=function(){return[{type:i.Brolog},{type:t.NgZone}]},s([t.Output()],e.prototype,"message",void 0),s([t.Output()],e.prototype,"scan",void 0),s([t.Output()],e.prototype,"login",void 0),s([t.Output()],e.prototype,"logout",void 0),s([t.Output()],e.prototype,"error",void 0),s([t.Output()],e.prototype,"heartbeat",void 0),s([t.Input()],e.prototype,"token",null),e=s([t.Component({selector:"wechaty",template:"<ng-content></ng-content>"})],e)}(),p=function(){function e(){}return e=s([t.NgModule({id:"wechaty",declarations:[l],exports:[l]})],e)}();e.VERSION="0.5.5",e.WechatyComponent=l,e.WechatyModule=p,e.ɵa=l,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
***************************************************************************** */function s(e,t,o,n){var i,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,o):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,o,n);else for(var a=e.length-1;a>=0;a--)(i=e[a])&&(s=(r<3?i(s):r>3?i(t,o,s):i(t,o))||s);return r>3&&s&&Object.defineProperty(t,o,s),s}function a(e,t,o,n){return new(o||(o=Promise))((function(i,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))}function c(e,t){var o,n,i,r,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return r={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function a(r){return function(a){return function(r){if(o)throw new TypeError("Generator is already executing.");for(;s;)try{if(o=1,n&&(i=2&r[0]?n.return:r[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,r[1])).done)return i;switch(n=0,i&&(r=[2&r[0],i.value]),r[0]){case 0:case 1:i=r;break;case 4:return s.label++,{value:r[1],done:!1};case 5:s.label++,n=r[1],r=[0];continue;case 7:r=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===r[0]||2===r[0])){s=0;continue}if(3===r[0]&&(!i||r[1]>i[0]&&r[1]<i[3])){s.label=r[1];break}if(6===r[0]&&s.label<i[1]){s.label=i[1],i=r;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(r);break}i[2]&&s.ops.pop(),s.trys.pop();continue}r=t.call(e,s)}catch(e){r=[6,e],n=0}finally{o=i=0}if(5&r[0])throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}([r,a])}}}var h;!function(e){e[e.CLOSED=WebSocket.CLOSED]="CLOSED",e[e.CLOSING=WebSocket.CLOSING]="CLOSING",e[e.CONNECTING=WebSocket.CONNECTING]="CONNECTING",e[e.OPEN=WebSocket.OPEN]="OPEN"}(h||(h={}));var u=function(){function e(){this.autoReconnect=!0,this.log=i.Brolog.instance(),this.CONNECT_TIMEOUT=1e4,this.ENDPOINT="wss://api.chatie.io/v0/websocket/token/",this.PROTOCOL="web|0.0.1",this.sendBuffer=[],this.log.verbose("IoService","constructor()")}return Object.defineProperty(e.prototype,"readyState",{get:function(){return this._readyState.asObservable()},enumerable:!0,configurable:!0}),e.prototype.init=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(n){switch(n.label){case 0:if(this.log.verbose("IoService","init()"),this.state)throw new Error("re-init");this.snapshot={readyState:h.CLOSED,event:null},this._readyState=new o.BehaviorSubject(h.CLOSED),this.state=new r.StateSwitch("IoService",this.log),this.state.setLog(this.log),n.label=1;case 1:return n.trys.push([1,4,,5]),[4,this.initStateDealer()];case 2:return n.sent(),[4,this.initRxSocket()];case 3:return n.sent(),[3,5];case 4:throw e=n.sent(),this.log.silly("IoService","init() exception: %s",e.message),e;case 5:return this.readyState.subscribe((function(e){t.log.silly("IoService","init() readyState.subscribe(%s)",h[e]),t.snapshot.readyState=e})),this.event.subscribe((function(e){t.log.silly("IoService","init() event.subscribe({name:%s})",e.name),t.snapshot.event=e})),[2]}}))}))},e.prototype.token=function(e){if(this.log.silly("IoService","token(%s)",e),!e)return this._token;this._token=e},e.prototype.start=function(){return a(this,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:if(this.log.verbose("IoService","start() with token:%s",this._token),!this._token)throw new Error("start() without token");if(this.state.on())throw new Error("state is already ON");if(this.state.pending())throw new Error("state is pending");this.state.on("pending"),this.autoReconnect=!0,t.label=1;case 1:return t.trys.push([1,3,,4]),[4,this.connectRxSocket()];case 2:return t.sent(),this.state.on(!0),[3,4];case 3:return e=t.sent(),this.log.warn("IoService","start() failed:%s",e.message),this.state.off(!0),[3,4];case 4:return[2]}}))}))},e.prototype.stop=function(){return a(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:if(this.log.verbose("IoService","stop()"),this.state.off()){if(this.log.warn("IoService","stop() state is already off"),this.state.pending())throw new Error("state pending() is true");return[2]}if(this.state.off("pending"),this.autoReconnect=!1,!this._websocket)throw new Error("no websocket");return[4,this.socketClose(1e3,"IoService.stop()")];case 1:return e.sent(),this.state.off(!0),[2]}}))}))},e.prototype.restart=function(){return a(this,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:this.log.verbose("IoService","restart()"),t.label=1;case 1:return t.trys.push([1,4,,5]),[4,this.stop()];case 2:return t.sent(),[4,this.start()];case 3:return t.sent(),[3,5];case 4:throw e=t.sent(),this.log.error("IoService","restart() error:%s",e.message),e;case 5:return[2]}}))}))},e.prototype.initStateDealer=function(){var e=this;this.log.verbose("IoService","initStateDealer()"),this.readyState.pipe(n.filter((function(e){return e===h.OPEN}))).subscribe((function(t){return e.stateOnOpen()}))},e.prototype.initRxSocket=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(i){if(this.log.verbose("IoService","initRxSocket()"),this.event)throw new Error("re-init is not permitted");return this.moObserver={next:this.socketSend.bind(this),error:this.socketClose.bind(this),complete:this.socketClose.bind(this)},e=o.Observable.create((function(e){return t.log.verbose("IoService","initRxSocket() Observable.create()"),t.mtObserver=e,t.socketClose.bind(t)})),this.event=o.Subject.create(this.moObserver,e.pipe(n.share())),[2]}))}))},e.prototype.connectRxSocket=function(){return a(this,void 0,void 0,(function(){var e,t=this;return c(this,(function(o){if(this.log.verbose("IoService","connectRxSocket()"),this._websocket)throw new Error("already has a websocket");if(this.state.off())throw new Error("switch state is off");if(!this.state.pending())throw new Error("switch state is already ON");return this._websocket=new WebSocket(this.endPoint(),this.PROTOCOL),this.socketUpdateState(),e=new Promise((function(e,o){t.log.verbose("IoService","connectRxSocket() Promise()");var n=setTimeout((function(){t._websocket=null;var e=new Error("rxSocket connect timeout after "+Math.round(t.CONNECT_TIMEOUT/1e3));o(e)}),t.CONNECT_TIMEOUT);t._websocket.onopen=function(o){t.log.verbose("IoService","connectRxSocket() Promise() WebSocket.onOpen() resolve()"),t.socketUpdateState(),clearTimeout(n),e()}})),this._websocket.onmessage=this.socketOnMessage.bind(this),this._websocket.onerror=this.socketOnError.bind(this),this._websocket.onclose=this.socketOnClose.bind(this),[2,e]}))}))},e.prototype.endPoint=function(){var e=this.ENDPOINT+this._token;return this.log.verbose("IoService","endPoint() => %s",e),e},e.prototype.stateOnOpen=function(){this.log.verbose("IoService","stateOnOpen()"),this.socketSendBuffer(),this.rpcUpdate("from stateOnOpen()")},e.prototype.rpcDing=function(e){return a(this,void 0,void 0,(function(){var t;return c(this,(function(o){return this.log.verbose("IoService","ding(%s)",e),t={name:"ding",payload:e},this.event.next(t),[2]}))}))},e.prototype.rpcUpdate=function(e){return a(this,void 0,void 0,(function(){return c(this,(function(t){return this.event.next({name:"update",payload:e}),[2]}))}))},e.prototype.socketClose=function(e,t){return a(this,void 0,void 0,(function(){var o=this;return c(this,(function(i){switch(i.label){case 0:if(this.log.verbose("IoService","socketClose()"),!this._websocket)throw new Error("no websocket");return this._websocket.close(e,t),this.socketUpdateState(),[4,new Promise((function(e){o.readyState.pipe(n.filter((function(e){return e===h.CLOSED}))).subscribe(e)}))];case 1:return i.sent(),[2]}}))}))},e.prototype.socketSend=function(e){this.log.silly("IoService","socketSend({name:%s, payload:%s})",e.name,e.payload),this._websocket||this.log.silly("IoService","socketSend() no _websocket");var t=JSON.stringify(e);this.sendBuffer.push(t),this.socketSendBuffer()},e.prototype.socketSendBuffer=function(){if(this.log.silly("IoService","socketSendBuffer() length:%s",this.sendBuffer.length),!this._websocket)throw new Error("socketSendBuffer(): no _websocket");if(this._websocket.readyState===WebSocket.OPEN)for(;this.sendBuffer.length;){var e=this.sendBuffer.shift();this.log.silly("IoService","socketSendBuffer() sending(%s)",e),this._websocket.send(e)}else this.log.warn("IoService","socketSendBuffer() readyState is not OPEN, send job delayed.")},e.prototype.socketUpdateState=function(){this.log.verbose("IoService","socketUpdateState() is %s",h[this._websocket.readyState]),this._websocket?this._readyState.next(this._websocket.readyState):this.log.error("IoService","socketUpdateState() no _websocket")},e.prototype.socketOnMessage=function(e){this.log.verbose("IoService","onMessage({data: %s})",e.data);var t=e.data,o={name:"raw",payload:t};try{var n=JSON.parse(t);o.name=n.name,o.payload=n.payload}catch(e){this.log.warn("IoService","onMessage parse message fail. save as RAW")}this.mtObserver.next(o)},e.prototype.socketOnError=function(e){this.log.silly("IoService","socketOnError(%s)",e)},e.prototype.socketOnClose=function(e){var t=this;this.log.verbose("IoService","socketOnClose({code:%s, reason:%s, returnValue:%s})",e.code,e.reason,e.returnValue),this.socketUpdateState(),this.autoReconnect?(this.state.on("pending"),setTimeout((function(){return a(t,void 0,void 0,(function(){var e;return c(this,(function(t){switch(t.label){case 0:return t.trys.push([0,2,,3]),[4,this.connectRxSocket()];case 1:return t.sent(),this.state.on(!0),[3,3];case 2:return e=t.sent(),this.log.warn("IoService","socketOnClose() autoReconnect() exception: %s",e),this.state.off(!0),[3,3];case 3:return[2]}}))}))}),1e3)):this.state.off(!0),this._websocket=null,e.wasClean||this.log.warn("IoService","socketOnClose() event.wasClean FALSE")},e}(),l=function(){function e(e,o){this.log=e,this.ngZone=o,this.message=new t.EventEmitter,this.scan=new t.EventEmitter,this.login=new t.EventEmitter,this.logout=new t.EventEmitter,this.error=new t.EventEmitter,this.heartbeat=new t.EventEmitter,this.timerSub=null,this.counter=0,this.timestamp=new Date,this.log.verbose("WechatyComponent","constructor() v%s","0.6.1")}return Object.defineProperty(e.prototype,"token",{get:function(){return this._token},set:function(e){this.log.verbose("WechatyComponent","set token(%s)",e);var t=(e||"").trim();if(this._token!==t){if(this._token=t,!this.ioService)return this.log.silly("WechatyComponent","set token() skip token init value"),void this.log.silly("WechatyComponent","set token() because ioService will do it inside ngOnInit()");this.log.silly("WechatyComponent","set token(%s) reloading ioService now...",t),this.ioService.token(this.token),this.ioService.restart()}else this.log.silly("WechatyComponent","set token(%s) not new",t)},enumerable:!0,configurable:!0}),e.prototype.ngOnInit=function(){return a(this,void 0,void 0,(function(){return c(this,(function(e){switch(e.label){case 0:return this.log.verbose("WechatyComponent","ngOninit() with token: "+this.token),this.ioService=new u,[4,this.ioService.init()];case 1:return e.sent(),this.ioService.event.subscribe(this.onIo.bind(this)),this.log.silly("WechatyComponent","ngOninit() ioService.event.subscribe()-ed"),this.token?(this.ioService.token(this.token),[4,this.ioService.start()]):[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},e.prototype.ngOnDestroy=function(){this.log.verbose("WechatyComponent","ngOnDestroy()"),this.endTimer(),this.ioService&&this.ioService.stop()},e.prototype.onIo=function(e){switch(this.log.silly("WechatyComponent","onIo#%d(%s)",this.counter++,e.name),this.timestamp=new Date,e.name){case"scan":this.scan.emit(e.payload);break;case"login":this.login.emit(e.payload);break;case"logout":this.logout.emit(e.payload);break;case"message":this.message.emit(e.payload);break;case"error":this.error.emit(e.payload);break;case"ding":case"dong":case"raw":this.heartbeat.emit(e.name+"["+e.payload+"]");break;case"heartbeat":this.heartbeat.emit(e.payload);break;case"sys":this.log.silly("WechatyComponent","onIo(%s): %s",e.name,e.payload);break;default:this.log.warn("WechatyComponent","onIo() unknown event name: %s[%s]",e.name,e.payload)}},e.prototype.reset=function(e){this.log.verbose("WechatyComponent","reset(%s)",e);var t={name:"reset",payload:e};if(!this.ioService)throw new Error("no ioService");this.ioService.event.next(t)},e.prototype.shutdown=function(e){this.log.verbose("WechatyComponent","shutdown(%s)",e);var t={name:"shutdown",payload:e};if(!this.ioService)throw new Error("no ioService");this.ioService.event.next(t)},e.prototype.startTimer=function(){var e=this;this.log.verbose("WechatyComponent","startTimer()"),this.ender=new o.Subject,this.ngZone.runOutsideAngular((function(){e.timer=o.interval(3e3).pipe(n.tap((function(t){e.log.verbose("do"," %d",t)})),n.takeUntil(e.ender),n.share())})),this.timerSub=this.timer.subscribe((function(t){if(e.counter=t,!e.ioService)throw new Error("no ioService");e.ioService.rpcDing(e.counter)}))},e.prototype.endTimer=function(){this.log.verbose("WechatyComponent","endTimer()"),this.timerSub&&(this.timerSub.unsubscribe(),this.timerSub=null),this.ender&&this.ender.next(null)},e.prototype.logoff=function(e){this.log.silly("WechatyComponent","logoff(%s)",e);var t={name:"logout",payload:e};this.ioService.event.next(t)},Object.defineProperty(e.prototype,"readyState",{get:function(){return this.ioService.readyState},enumerable:!0,configurable:!0}),e.ctorParameters=function(){return[{type:i.Brolog},{type:t.NgZone}]},s([t.Output()],e.prototype,"message",void 0),s([t.Output()],e.prototype,"scan",void 0),s([t.Output()],e.prototype,"login",void 0),s([t.Output()],e.prototype,"logout",void 0),s([t.Output()],e.prototype,"error",void 0),s([t.Output()],e.prototype,"heartbeat",void 0),s([t.Input()],e.prototype,"token",null),e=s([t.Component({selector:"wechaty",template:"<ng-content></ng-content>"})],e)}(),p=function(){function e(){}return e=s([t.NgModule({id:"wechaty",declarations:[l],exports:[l]})],e)}();e.VERSION="0.6.1",e.WechatyComponent=l,e.WechatyModule=p,e.ɵa=l,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=chatie-angular.umd.min.js.map |
@@ -1,1 +0,1 @@ | ||
{"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"reference","name":"WechatyComponent"},"ScanInfo":{"__symbolic":"interface"},"UserInfo":{"__symbolic":"interface"},"WechatyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":47,"character":1},"arguments":[{"selector":"wechaty","template":"<ng-content></ng-content>"}]}],"members":{"message":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":66,"character":3}}]}],"scan":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":67,"character":3}}]}],"login":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":68,"character":3}}]}],"logout":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":69,"character":3}}]}],"error":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":70,"character":3}}]}],"heartbeat":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":71,"character":3}}]}],"token":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":75,"character":3}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"brolog","name":"Brolog","line":108,"character":20},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":109,"character":20}]}],"ngOnInit":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}],"onIo":[{"__symbolic":"method"}],"reset":[{"__symbolic":"method"}],"shutdown":[{"__symbolic":"method"}],"startTimer":[{"__symbolic":"method"}],"endTimer":[{"__symbolic":"method"}],"logoff":[{"__symbolic":"method"}]}},"WechatyModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":4,"character":1},"arguments":[{"id":"wechaty","declarations":[{"__symbolic":"reference","name":"ɵa"}],"exports":[{"__symbolic":"reference","name":"ɵa"}]}]}],"members":{}},"VERSION":"0.5.5"},"origins":{"ɵa":"./src/wechaty/wechaty.component","ScanInfo":"./src/wechaty/wechaty.component","UserInfo":"./src/wechaty/wechaty.component","WechatyComponent":"./src/wechaty/wechaty.component","WechatyModule":"./src/wechaty/wechaty.module","VERSION":"./src/version"},"importAs":"@chatie/angular"} | ||
{"__symbolic":"module","version":4,"metadata":{"ɵa":{"__symbolic":"reference","name":"WechatyComponent"},"ScanInfo":{"__symbolic":"interface"},"UserInfo":{"__symbolic":"interface"},"WechatyComponent":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component","line":47,"character":1},"arguments":[{"selector":"wechaty","template":"<ng-content></ng-content>"}]}],"members":{"message":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":66,"character":3}}]}],"scan":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":67,"character":3}}]}],"login":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":68,"character":3}}]}],"logout":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":69,"character":3}}]}],"error":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":70,"character":3}}]}],"heartbeat":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Output","line":71,"character":3}}]}],"token":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input","line":75,"character":3}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"brolog","name":"Brolog","line":108,"character":20},{"__symbolic":"reference","module":"@angular/core","name":"NgZone","line":109,"character":20}]}],"ngOnInit":[{"__symbolic":"method"}],"ngOnDestroy":[{"__symbolic":"method"}],"onIo":[{"__symbolic":"method"}],"reset":[{"__symbolic":"method"}],"shutdown":[{"__symbolic":"method"}],"startTimer":[{"__symbolic":"method"}],"endTimer":[{"__symbolic":"method"}],"logoff":[{"__symbolic":"method"}]}},"WechatyModule":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule","line":4,"character":1},"arguments":[{"id":"wechaty","declarations":[{"__symbolic":"reference","name":"ɵa"}],"exports":[{"__symbolic":"reference","name":"ɵa"}]}]}],"members":{}},"VERSION":"0.6.1"},"origins":{"ɵa":"./src/wechaty/wechaty.component","ScanInfo":"./src/wechaty/wechaty.component","UserInfo":"./src/wechaty/wechaty.component","WechatyComponent":"./src/wechaty/wechaty.component","WechatyModule":"./src/wechaty/wechaty.module","VERSION":"./src/version"},"importAs":"@chatie/angular"} |
/** | ||
* This file was auto generated from scripts/generate-version.sh | ||
*/ | ||
export const VERSION = '0.5.5'; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BjaGF0aWUvYW5ndWxhci8iLCJzb3VyY2VzIjpbInNyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sT0FBTyxHQUFXLE9BQU8sQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogVGhpcyBmaWxlIHdhcyBhdXRvIGdlbmVyYXRlZCBmcm9tIHNjcmlwdHMvZ2VuZXJhdGUtdmVyc2lvbi5zaFxuICovXG5leHBvcnQgY29uc3QgVkVSU0lPTjogc3RyaW5nID0gJzAuNS41J1xuIl19 | ||
export const VERSION = '0.6.1'; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BjaGF0aWUvYW5ndWxhci8iLCJzb3VyY2VzIjpbInNyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sT0FBTyxHQUFXLE9BQU8sQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogVGhpcyBmaWxlIHdhcyBhdXRvIGdlbmVyYXRlZCBmcm9tIHNjcmlwdHMvZ2VuZXJhdGUtdmVyc2lvbi5zaFxuICovXG5leHBvcnQgY29uc3QgVkVSU0lPTjogc3RyaW5nID0gJzAuNi4xJ1xuIl19 |
/** | ||
* This file was auto generated from scripts/generate-version.sh | ||
*/ | ||
export var VERSION = '0.5.5'; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BjaGF0aWUvYW5ndWxhci8iLCJzb3VyY2VzIjpbInNyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLElBQU0sT0FBTyxHQUFXLE9BQU8sQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogVGhpcyBmaWxlIHdhcyBhdXRvIGdlbmVyYXRlZCBmcm9tIHNjcmlwdHMvZ2VuZXJhdGUtdmVyc2lvbi5zaFxuICovXG5leHBvcnQgY29uc3QgVkVSU0lPTjogc3RyaW5nID0gJzAuNS41J1xuIl19 | ||
export var VERSION = '0.6.1'; | ||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmVyc2lvbi5qcyIsInNvdXJjZVJvb3QiOiJuZzovL0BjaGF0aWUvYW5ndWxhci8iLCJzb3VyY2VzIjpbInNyYy92ZXJzaW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLElBQU0sT0FBTyxHQUFXLE9BQU8sQ0FBQSIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogVGhpcyBmaWxlIHdhcyBhdXRvIGdlbmVyYXRlZCBmcm9tIHNjcmlwdHMvZ2VuZXJhdGUtdmVyc2lvbi5zaFxuICovXG5leHBvcnQgY29uc3QgVkVSU0lPTjogc3RyaW5nID0gJzAuNi4xJ1xuIl19 |
@@ -11,3 +11,3 @@ import { __awaiter, __decorate } from 'tslib'; | ||
*/ | ||
const VERSION = '0.5.5'; | ||
const VERSION = '0.6.1'; | ||
@@ -14,0 +14,0 @@ var ReadyState; |
@@ -11,3 +11,3 @@ import { __awaiter, __generator, __decorate } from 'tslib'; | ||
*/ | ||
var VERSION = '0.5.5'; | ||
var VERSION = '0.6.1'; | ||
@@ -14,0 +14,0 @@ var ReadyState; |
{ | ||
"$schema": "./node_modules/ng-packagr/package.schema.json", | ||
"name": "@chatie/angular", | ||
"version": "0.5.5", | ||
"version": "0.6.1", | ||
"description": "Wechaty Component NgModule", | ||
@@ -33,3 +33,3 @@ "license": "Apache-2.0", | ||
"access": "public", | ||
"tag": "next" | ||
"tag": "latest" | ||
}, | ||
@@ -36,0 +36,0 @@ "git": { |
@@ -74,5 +74,7 @@ # Wechaty Web Component ![wechaty](https://img.shields.io/badge/HTML5-%3Cwechaty%20%2F%3E-brightgreen) | ||
### v0.5 master (Mar 23, 2020) | ||
### v0.6 master (Mar 23, 2020) | ||
1. Upgrade Angular version from 6 to 9 | ||
1. Enable GitHub Actions | ||
1. Demo on <StackBlitz.com> | ||
@@ -79,0 +81,0 @@ ### v0.4 (May 28th, 2018) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
461562
120