diff --git a/src/ClientService.ts b/src/ClientService.ts index d57ae7c..32e1401 100644 --- a/src/ClientService.ts +++ b/src/ClientService.ts @@ -21,6 +21,7 @@ export type LocalAgent = { } export interface ClientServiceConfig { + getServiceHost() : string; getSelectedLocaleUrl() : string | null; getSessionType() : ClientSessionType; generateHostInfo() : LocalAgent; @@ -51,7 +52,7 @@ export class ClientServices { this.initializeLocaleId = 0; this.sessionInitialized = false; - this.connection = new ClientServiceConnection(5000); + this.connection = new ClientServiceConnection(config.getServiceHost(), 5000); this.connection.events.on("notify_state_changed", event => { if(event.newState !== "connected") { if(this.sessionInitialized) { diff --git a/src/Connection.ts b/src/Connection.ts index ad4e343..7578c1d 100644 --- a/src/Connection.ts +++ b/src/Connection.ts @@ -22,6 +22,8 @@ export class ClientServiceConnection { readonly events: Registry; readonly reconnectInterval: number; + private readonly serviceHost: string; + private reconnectTimeout: any; private connectionState: ConnectionState; private connection: WebSocket; @@ -29,7 +31,8 @@ export class ClientServiceConnection { private pendingCommands: {[key: string]: PendingCommand} = {}; private notifyHandler: {[key: string]: ((event) => void)[]} = {}; - constructor(reconnectInterval: number) { + constructor(serviceHost: string, reconnectInterval: number) { + this.serviceHost = serviceHost; this.events = new Registry(); this.reconnectInterval = reconnectInterval; } @@ -59,12 +62,7 @@ export class ClientServiceConnection { this.setState("connecting"); - let address; - address = "client-services.teaspeak.de:27791"; - address = "localhost:1244"; - //address = "192.168.40.135:1244"; - - this.connection = new WebSocket(`wss://${address}/ws-api/v${kApiVersion}`); + this.connection = new WebSocket(`wss://${this.serviceHost}/ws-api/v${kApiVersion}`); this.connection.onclose = event => { clientServiceLogger.logTrace("Lost connection to statistics server (Connection closed). Reason: %s", event.reason ? `${event.reason} (${event.code})` : event.code); this.handleConnectionLost(); @@ -214,7 +212,7 @@ export class ClientServiceConnection { const unregisterHandler = () => { const index = handlers.indexOf(handler); if(index !== -1) { - handlers.remove(handler); + handlers.splice(index, 1); } } diff --git a/src/GeoLocation.ts b/src/GeoLocation.ts index 82251b0..bfc3306 100644 --- a/src/GeoLocation.ts +++ b/src/GeoLocation.ts @@ -70,7 +70,7 @@ class GeoLocationProvider { this.cachedInfo = info.info; } catch (error) { - clientServiceLogger.logTrace(tr("Failed to load geo resolve cache: %o"), error); + clientServiceLogger.logTrace(tr("Failed to load geo resolve cache:\n%o"), error); } } @@ -104,7 +104,7 @@ class GeoLocationProvider { } as GeoLocationCache)); return info; } catch (error) { - clientServiceLogger.logTrace(tr("Geo resolver %s failed: %o. Trying next one."), resolver.name(), error); + clientServiceLogger.logTrace(tr("Geo resolver %s failed. Trying next one:\n%o"), resolver.name(), error); } }