X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=webapp%2Fsrc%2Fapp%2Fcommon%2Fxdsagent.service.ts;fp=webapp%2Fsrc%2Fapp%2Fcommon%2Fxdsagent.service.ts;h=86f033664e75bdf0ebbb606e982bfe2bf65144e7;hb=7f1db509a2076311c280964715962df71a1631ce;hp=4d9aadcf570de8ccc0d283d80346b033c77c7d31;hpb=271ffeae46af55459270c3480816c76aa9c80638;p=src%2Fxds%2Fxds-server.git diff --git a/webapp/src/app/common/xdsagent.service.ts b/webapp/src/app/common/xdsagent.service.ts index 4d9aadc..86f0336 100644 --- a/webapp/src/app/common/xdsagent.service.ts +++ b/webapp/src/app/common/xdsagent.service.ts @@ -59,20 +59,12 @@ export class XDSAgentService { this.Status$ = this.statusSubject.asObservable(); this.apikey = DEFAULT_API_KEY; // FIXME Add dynamic allocated key - this._status.baseURL = 'http://localhost:' + DEFAULT_PORT; - this.baseRestUrl = this._status.baseURL + '/api/' + API_VERSION; - let re = this._window.location.origin.match(/http[s]?:\/\/([^\/]*)[\/]?/); - if (re === null || re.length < 2) { - console.error('ERROR: cannot determine Websocket url'); - } else { - this.wsUrl = 'ws://' + re[1]; - } + this._initURLs('http://localhost:' + DEFAULT_PORT); } connect(retry: number, url?: string): Observable { if (url) { - this._status.baseURL = url; - this.baseRestUrl = this._status.baseURL + '/api/' + API_VERSION; + this._initURLs(url); } //FIXME [XDS-Agent]: not implemented yet, set always as connected //this._status.connected = false; @@ -103,6 +95,18 @@ export class XDSAgentService { }); } + private _initURLs(url: string) { + this._status.baseURL = url; + this.baseRestUrl = this._status.baseURL + '/api/' + API_VERSION; + let re = this._status.baseURL.match(/http[s]?:\/\/([^\/]*)[\/]?/); + if (re === null || re.length < 2) { + this.wsUrl = ''; + console.error('ERROR: cannot determine Websocket url'); + return; + } + this.wsUrl = 'ws://' + re[1]; + } + private _WSState(sts: boolean) { this._status.WS_connected = sts; this.statusSubject.next(Object.assign({}, this._status));