ngx-zalo
Version:
Use Zalo SDK with Angular5~ (https://developers.zalo.me/docs/sdk/javascript-sdk/tai-lieu)
3 lines (2 loc) • 4.19 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("rxjs/Observable"),require("@angular/common")):"function"==typeof define&&define.amd?define("ngx-zalo",["exports","@angular/core","rxjs/Observable","@angular/common"],e):e(t["ngx-zalo"]={},t.ng.core,t.Rx,t.ng.common)}(this,function(t,e,i,n){"use strict";var o=function(){function t(){this.SCRIPT_URL="https://zjs.zdn.vn/zalo/sdk.js",this.STATUS_NOT_INIT=0,this.STATUS_INITIALIZING=1,this.STATUS_INIT_FAILURE=2,this.STATUS_INIT_SUCCESSFULLY=3,this._initStatus=this.STATUS_NOT_INIT,this._isLogin=!1}return Object.defineProperty(t.prototype,"isLogin",{get:function(){return this._isLogin},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"accessToken",{get:function(){return this.isInitSuccessfully?Zalo.getAccessToken():null},enumerable:!0,configurable:!0}),t.prototype.init=function(t){var e=this;this._initStatus=this.STATUS_INITIALIZING,this.initZaloScript(function(){Zalo.init(t),e.getLoginStatus(function(){e._initStatus=e.STATUS_INIT_SUCCESSFULLY})},function(){e._initStatus=e.STATUS_INIT_FAILURE})},t.prototype.login=function(){this.isInitSuccessfully&&Zalo.login()},t.prototype.logout=function(){var e=this;return new i.Observable(function(t){e.isInitSuccessfully&&Zalo.logout(),e._isLogin=!1,e.breakObservable(t)})},t.prototype.updateLoginInfo=function(){var n=this;return new i.Observable(function(e){if(n.isNotInit)return n._isLogin=!1,void n.breakObservable(e,!1);n.pendingInit().subscribe(function(){Zalo.getLoginStatus(function(t){n._isLogin="connected"===t.status,n.breakObservable(e,n._isLogin)})})})},t.prototype.getMyProfile=function(t){var n=this;return void 0===t&&(t="id, name, birthday, picture, gender"),new i.Observable(function(e){n._initStatus?n.pendingInit().subscribe(function(){Zalo.api("/me","GET",{fields:t},function(t){n.breakObservable(e,t)})}):n.breakObservable(e)})},Object.defineProperty(t.prototype,"isNotInit",{get:function(){return this.STATUS_NOT_INIT===this._initStatus},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isInitializing",{get:function(){return this.STATUS_INITIALIZING===this._initStatus},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isInitSuccessfully",{get:function(){return this.STATUS_INIT_SUCCESSFULLY===this._initStatus},enumerable:!0,configurable:!0}),t.prototype.pendingInit=function(){var n=this;return new i.Observable(function(t){if(n.isInitializing)var e=setInterval(function(){n.isInitializing||(clearInterval(e),n.breakObservable(t))},500);else n.breakObservable(t)})},t.prototype.initZaloScript=function(t,e){if("undefined"!=typeof window){var n=document.createElement("script");n.src=this.SCRIPT_URL,n.onload=function(){t&&t()},n.onerror=function(){e&&e()},document.head.appendChild(n)}},t.prototype.getLoginStatus=function(e){var n=this;Zalo.getLoginStatus(function(t){"connected"===t.status&&(n._isLogin=!0),e&&e(t)})},t.prototype.breakObservable=function(t,e){void 0===e&&(e=null),t.next(e),t.complete()},t}();o.decorators=[{type:e.Injectable}],o.ctorParameters=function(){return[]};var r=function(){function t(t){this._ngxZaloService=t}return t.prototype.onClick=function(){this._ngxZaloService.login()},t}();r.decorators=[{type:e.Directive,args:[{selector:"[ngxLoginZalo]"}]}],r.ctorParameters=function(){return[{type:o}]},r.propDecorators={onClick:[{type:e.HostListener,args:["click"]}]};var s=function(){function t(t){this._ngxZaloService=t,this.successEvent=new e.EventEmitter}return t.prototype.onClick=function(){var t=this;this._ngxZaloService.logout().subscribe(function(){t.successEvent.emit()})},t}();s.decorators=[{type:e.Directive,args:[{selector:"[ngxLogoutZalo]"}]}],s.ctorParameters=function(){return[{type:o}]},s.propDecorators={successEvent:[{type:e.Output}],onClick:[{type:e.HostListener,args:["click"]}]};var c=function(){};c.decorators=[{type:e.NgModule,args:[{imports:[n.CommonModule],providers:[o],declarations:[r,s],exports:[r,s]}]}],c.ctorParameters=function(){return[]},t.NgxZaloModule=c,t.NgxZaloService=o,t.ɵa=r,t.ɵb=s,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-zalo.umd.min.js.map