|
|
@ -10,6 +10,7 @@ import * as path from 'path'; |
|
|
|
export class AnalyticsService { |
|
|
|
export class AnalyticsService { |
|
|
|
|
|
|
|
|
|
|
|
private _requester: any; |
|
|
|
private _requester: any; |
|
|
|
|
|
|
|
private _ready: boolean = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor(private _onResponse: (response: any) => void) { |
|
|
|
constructor(private _onResponse: (response: any) => void) { |
|
|
@ -17,6 +18,9 @@ export class AnalyticsService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async sendTask(msgObj: any): Promise<void> { |
|
|
|
public async sendTask(msgObj: any): Promise<void> { |
|
|
|
|
|
|
|
if(!this._ready) { |
|
|
|
|
|
|
|
return Promise.reject("Analytics is not ready"); |
|
|
|
|
|
|
|
} |
|
|
|
let message = JSON.stringify(msgObj); |
|
|
|
let message = JSON.stringify(msgObj); |
|
|
|
return this.sendMessage(message); |
|
|
|
return this.sendMessage(message); |
|
|
|
} |
|
|
|
} |
|
|
@ -38,6 +42,8 @@ export class AnalyticsService { |
|
|
|
this._requester.close(); |
|
|
|
this._requester.close(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public get ready() { return this._ready; } |
|
|
|
|
|
|
|
|
|
|
|
private async _initConnection() { |
|
|
|
private async _initConnection() { |
|
|
|
this._requester = zmq.socket('pair'); |
|
|
|
this._requester = zmq.socket('pair'); |
|
|
|
|
|
|
|
|
|
|
@ -55,6 +61,8 @@ export class AnalyticsService { |
|
|
|
|
|
|
|
|
|
|
|
this._requester.on("message", this._onAnalyticsMessage.bind(this)); |
|
|
|
this._requester.on("message", this._onAnalyticsMessage.bind(this)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this._ready = true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async _connectToAnalytics() { |
|
|
|
private async _connectToAnalytics() { |
|
|
|