@chatie/angular
Advanced tools
Comparing version 0.1.13 to 0.1.14
116
dist/io.js
@@ -6,4 +6,4 @@ // Io Service should be instanciated each time. (one io service for one wechaty component) | ||
import { Brolog } from 'brolog'; | ||
var IoService = (function () { | ||
function IoService(injector) { | ||
export class IoService { | ||
constructor(injector) { | ||
this.injector = injector; | ||
@@ -18,8 +18,7 @@ this.ENDPOINT = 'wss://api.wechaty.io/v0/websocket/token/'; | ||
} | ||
IoService.prototype.setToken = function (token) { | ||
setToken(token) { | ||
this.log.silly('IoService', 'setToken(%s)', token); | ||
this.token = token; | ||
}; | ||
IoService.prototype.start = function () { | ||
var _this = this; | ||
} | ||
start() { | ||
this.log.silly('IoService', 'start() with token:[%s]', this.token); | ||
@@ -31,10 +30,10 @@ if (!this.token) { | ||
return this.initIoSubject() | ||
.then(function (_) { return _this.initWebSocket(); }) | ||
.then(function (_) { return _this; }) | ||
.catch(function (e) { | ||
_this.log.silly('IoService', 'start() exception: %s', e.message); | ||
.then(_ => this.initWebSocket()) | ||
.then(_ => this) | ||
.catch(e => { | ||
this.log.silly('IoService', 'start() exception: %s', e.message); | ||
throw e; | ||
}); | ||
}; | ||
IoService.prototype.stop = function () { | ||
} | ||
stop() { | ||
this.log.verbose('IoService', 'stop()'); | ||
@@ -49,28 +48,26 @@ this.autoReconnect = false; | ||
return Promise.resolve(this); | ||
}; | ||
IoService.prototype.restart = function () { | ||
var _this = this; | ||
} | ||
restart() { | ||
this.log.silly('IoService', 'restart()'); | ||
return this.stop().then(function (_) { return _this.start(); }); | ||
}; | ||
IoService.prototype.initIoSubject = function () { | ||
var _this = this; | ||
return this.stop().then(_ => this.start()); | ||
} | ||
initIoSubject() { | ||
this.log.verbose('IoService', 'initIoSubject()'); | ||
return new Promise(function (resolve) { | ||
var observable = Observable.create(function (subscriber) { | ||
_this.log.verbose('IoService', 'initIoSubject() Observable.create()'); | ||
_this.subscriber = subscriber; | ||
return new Promise(resolve => { | ||
const observable = Observable.create((subscriber) => { | ||
this.log.verbose('IoService', 'initIoSubject() Observable.create()'); | ||
this.subscriber = subscriber; | ||
//////////////////////// | ||
resolve(); | ||
//////////////////////// | ||
return _this.wsClose.bind(_this); | ||
return this.wsClose.bind(this); | ||
}).share(); | ||
var obs = { | ||
complete: _this.wsClose.bind(_this), | ||
next: _this.wsSend.bind(_this) | ||
const obs = { | ||
complete: this.wsClose.bind(this), | ||
next: this.wsSend.bind(this) | ||
}; | ||
_this.ioSubject = Subject.create(obs, observable); | ||
this.ioSubject = Subject.create(obs, observable); | ||
}); | ||
}; | ||
IoService.prototype.initWebSocket = function () { | ||
} | ||
initWebSocket() { | ||
this.log.silly('IoService', 'initWebSocket() with token:[%s]', this.token); | ||
@@ -86,4 +83,4 @@ if (this.online()) { | ||
this.websocket.onmessage = onMessage.bind(this); | ||
}; | ||
IoService.prototype.online = function () { | ||
} | ||
online() { | ||
if (this.websocket && (this.websocket.readyState === WebSocket.OPEN)) { | ||
@@ -93,4 +90,4 @@ return true; | ||
return false; | ||
}; | ||
IoService.prototype.connecting = function () { | ||
} | ||
connecting() { | ||
if (this.websocket && (this.websocket.readyState === WebSocket.CONNECTING)) { | ||
@@ -100,21 +97,21 @@ return true; | ||
return false; | ||
}; | ||
IoService.prototype.io = function () { | ||
} | ||
io() { | ||
return this.ioSubject; | ||
}; | ||
IoService.prototype.endPoint = function () { | ||
var END_POINT = 'wss://api.chatie.io/websocket/token/'; | ||
var url = END_POINT + this.token; | ||
} | ||
endPoint() { | ||
const END_POINT = 'wss://api.chatie.io/websocket/token/'; | ||
const url = END_POINT + this.token; | ||
this.log.verbose('IoService', 'endPoint() => %s', url); | ||
return url; | ||
}; | ||
IoService.prototype.ding = function (payload) { | ||
} | ||
ding(payload) { | ||
this.log.verbose('IoService', 'ding(%s)', payload); | ||
var e = { | ||
const e = { | ||
name: 'ding', | ||
payload: payload | ||
payload | ||
}; | ||
this.io().next(e); | ||
}; | ||
IoService.prototype.wsClose = function () { | ||
} | ||
wsClose() { | ||
this.log.verbose('IoService', 'wsClose()'); | ||
@@ -125,6 +122,6 @@ if (this.websocket) { | ||
} | ||
}; | ||
IoService.prototype.wsSend = function (e) { | ||
} | ||
wsSend(e) { | ||
this.log.silly('IoService', 'wsSend(%s)', e.name); | ||
var message = JSON.stringify(e); | ||
const message = JSON.stringify(e); | ||
if (this.online()) { | ||
@@ -137,3 +134,3 @@ if (!this.websocket) { | ||
this.log.silly('IoService', 'wsSend() buffer processing: length: %d', this.sendBuffer.length); | ||
var m = this.sendBuffer.shift(); | ||
const m = this.sendBuffer.shift(); | ||
this.websocket.send(m); | ||
@@ -148,10 +145,8 @@ } | ||
} | ||
}; | ||
return IoService; | ||
}()); | ||
export { IoService }; | ||
} | ||
} | ||
function onOpen(e) { | ||
this.log.verbose('IoService', 'onOpen()'); | ||
this.log.verbose('IoService', 'onOpen() require update from io'); | ||
var ioEvent = { | ||
const ioEvent = { | ||
name: 'update', | ||
@@ -166,8 +161,7 @@ payload: 'onOpen' | ||
function onClose(e) { | ||
var _this = this; | ||
this.log.verbose('IoService', 'onClose(%s)', e); | ||
// this.websocket = null | ||
if (this.autoReconnect) { | ||
setTimeout(function (_) { | ||
_this.initWebSocket(); | ||
setTimeout(_ => { | ||
this.initWebSocket(); | ||
}, 1000); | ||
@@ -189,5 +183,5 @@ } | ||
function onMessage(message) { | ||
var data = message.data; // WebSocket data | ||
const data = message.data; // WebSocket data | ||
this.log.verbose('IoService', 'onMessage(%s)', data); | ||
var ioEvent = { | ||
const ioEvent = { | ||
name: 'raw', | ||
@@ -197,3 +191,3 @@ payload: data | ||
try { | ||
var obj = JSON.parse(data); | ||
const obj = JSON.parse(data); | ||
ioEvent.name = obj.name; | ||
@@ -200,0 +194,0 @@ ioEvent.payload = obj.payload; |
@@ -5,4 +5,4 @@ import { Component, EventEmitter, Input, Output, NgZone, Injector, } from '@angular/core'; | ||
import { IoService, } from './io'; | ||
var WechatyComponent = (function () { | ||
function WechatyComponent(ngZone, log, injector) { | ||
export class WechatyComponent { | ||
constructor(ngZone, log, injector) { | ||
this.ngZone = ngZone; | ||
@@ -24,9 +24,5 @@ this.log = log; | ||
} | ||
Object.defineProperty(WechatyComponent.prototype, "token", { | ||
get: function () { return this._token; }, | ||
set: function (token) { this.updateToken(token || ''); }, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
WechatyComponent.prototype.ngOnInit = function () { | ||
set token(token) { this.updateToken(token || ''); } | ||
get token() { return this._token; } | ||
ngOnInit() { | ||
this.log.verbose('Wechaty', 'ngOninit() with token: ' + this.token); | ||
@@ -41,4 +37,4 @@ /** | ||
// this.startTimer() | ||
}; | ||
WechatyComponent.prototype.ngOnDestroy = function () { | ||
} | ||
ngOnDestroy() { | ||
this.log.verbose('Wechaty', 'ngOnDestroy()'); | ||
@@ -54,4 +50,4 @@ this.endTimer(); | ||
} | ||
}; | ||
WechatyComponent.prototype.onIo = function (e) { | ||
} | ||
onIo(e) { | ||
this.log.silly('Wechaty', 'onIo#%d(%s)', this.counter++, e.name); | ||
@@ -90,4 +86,4 @@ this.timestamp = new Date(); | ||
} | ||
}; | ||
WechatyComponent.prototype.updateToken = function (token) { | ||
} | ||
updateToken(token) { | ||
this.log.silly('WechatyCoreCmp', 'set token(%s)', token); | ||
@@ -103,6 +99,6 @@ if (token && this._token === token) { | ||
this.ioService.restart(); | ||
}; | ||
WechatyComponent.prototype.reset = function (reason) { | ||
} | ||
reset(reason) { | ||
this.log.verbose('Wechaty', 'reset(%s)', reason); | ||
var resetEvent = { | ||
const resetEvent = { | ||
name: 'reset', | ||
@@ -116,6 +112,6 @@ payload: reason | ||
.next(resetEvent); | ||
}; | ||
WechatyComponent.prototype.shutdown = function (reason) { | ||
} | ||
shutdown(reason) { | ||
this.log.verbose('Wechaty', 'shutdown(%s)', reason); | ||
var shutdownEvent = { | ||
const shutdownEvent = { | ||
name: 'shutdown', | ||
@@ -129,5 +125,4 @@ payload: reason | ||
.next(shutdownEvent); | ||
}; | ||
WechatyComponent.prototype.startTimer = function () { | ||
var _this = this; | ||
} | ||
startTimer() { | ||
this.log.verbose('Wechaty', 'startTimer()'); | ||
@@ -137,18 +132,18 @@ this.ender = new Subject(); | ||
// https://github.com/juliemr/ngconf-2016-zones/blob/master/src/app/main.ts#L38 | ||
this.ngZone.runOutsideAngular(function () { | ||
_this.timer = Observable.interval(3000) | ||
.do(function (i) { _this.log.verbose('do', ' %d', i); }) | ||
.takeUntil(_this.ender) | ||
this.ngZone.runOutsideAngular(() => { | ||
this.timer = Observable.interval(3000) | ||
.do(i => { this.log.verbose('do', ' %d', i); }) | ||
.takeUntil(this.ender) | ||
.share(); | ||
}); | ||
this.timerSub = this.timer.subscribe(function (t) { | ||
_this.counter = t; | ||
if (!_this.ioService) { | ||
this.timerSub = this.timer.subscribe(t => { | ||
this.counter = t; | ||
if (!this.ioService) { | ||
throw new Error('no ioService'); | ||
} | ||
_this.ioService.ding(_this.counter); | ||
this.ioService.ding(this.counter); | ||
// this.message.emit('#' + this.token + ':' + dong) | ||
}); | ||
}; | ||
WechatyComponent.prototype.endTimer = function () { | ||
} | ||
endTimer() { | ||
this.log.verbose('Wechaty', 'endTimer()'); | ||
@@ -164,6 +159,6 @@ if (this.timerSub) { | ||
} | ||
}; | ||
WechatyComponent.prototype.logoff = function (reason) { | ||
} | ||
logoff(reason) { | ||
this.log.silly('WechatyCoreCmp', 'logoff(%s)', reason); | ||
var quitEvent = { | ||
const quitEvent = { | ||
name: 'logout', | ||
@@ -174,16 +169,14 @@ payload: reason | ||
.next(quitEvent); | ||
}; | ||
WechatyComponent.prototype.online = function () { | ||
} | ||
online() { | ||
return this.ioService.online(); | ||
}; | ||
WechatyComponent.prototype.connecting = function () { | ||
} | ||
connecting() { | ||
return this.ioService.connecting(); | ||
}; | ||
WechatyComponent.prototype.offline = function () { | ||
} | ||
offline() { | ||
return !(this.online() || this.connecting()); | ||
}; | ||
WechatyComponent.prototype.version = function () { return this.npmVersion; }; | ||
return WechatyComponent; | ||
}()); | ||
export { WechatyComponent }; | ||
} | ||
version() { return this.npmVersion; } | ||
} | ||
WechatyComponent.decorators = [ | ||
@@ -207,7 +200,7 @@ { type: Component, args: [{ | ||
/** @nocollapse */ | ||
WechatyComponent.ctorParameters = function () { return [ | ||
WechatyComponent.ctorParameters = () => [ | ||
{ type: NgZone, }, | ||
{ type: Brolog, }, | ||
{ type: Injector, }, | ||
]; }; | ||
]; | ||
WechatyComponent.propDecorators = { | ||
@@ -214,0 +207,0 @@ 'message': [{ type: Output },], |
import { NgModule } from '@angular/core'; | ||
import { WechatyComponent } from './wechaty.component'; | ||
var WechatyModule = (function () { | ||
function WechatyModule() { | ||
} | ||
return WechatyModule; | ||
}()); | ||
export { WechatyModule }; | ||
export class WechatyModule { | ||
} | ||
WechatyModule.decorators = [ | ||
@@ -21,5 +17,5 @@ { type: NgModule, args: [{ | ||
/** @nocollapse */ | ||
WechatyModule.ctorParameters = function () { return []; }; | ||
WechatyModule.ctorParameters = () => []; | ||
// export { WechatyComponent } from './wechaty.component' | ||
export * from './wechaty.component'; | ||
//# sourceMappingURL=wechaty.module.js.map |
{ | ||
"name": "@chatie/angular", | ||
"version": "0.1.13", | ||
"version": "0.1.14", | ||
"description": "Chatie Web Component NgModule for Angular", | ||
@@ -19,3 +19,6 @@ "license": "Apache-2.0", | ||
"e2e": "ng e2e", | ||
"dist": "npm run clean && npm run ngc", | ||
"dist": "npm run clean && npm run ngc && npm run rollup && npm run es5 && npm run minify", | ||
"rollup": "rollup -c", | ||
"minify": "uglifyjs dist/wechaty.umd.js --screw-ie8 --compress --mangle --comments --output dist/wechaty.umd.min.js", | ||
"es5": "tsc --out ./dist/wechaty.umd.js --target es5 --allowJs dist/wechaty.es6.umd.js --lib es6,dom", | ||
"ngc": "ngc -p src/tsconfig.aot.json" | ||
@@ -22,0 +25,0 @@ }, |
@@ -5,3 +5,3 @@ # @chatie/angular | ||
Wechaty Web Component NgModule for Angular 4 | ||
Chatie Web Component NgModule for Angular 4 | ||
@@ -14,5 +14,5 @@ This package is part of Chatie project: <https://github.com/chatie> | ||
## TL;DR; | ||
## TL;DR | ||
Let's see code example: | ||
Talk is cheap, show me the code: | ||
@@ -19,0 +19,0 @@ ### App Module |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
118136
20
1330
2
1