From 10a5ccbff3ffe5f2afc9836c6003ebde20853e2a Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sat, 11 Apr 2020 11:43:41 +0200 Subject: [PATCH] Fixed some native client related bugs --- shared/js/ConnectionHandler.ts | 2 ++ shared/js/connection/CommandHandler.ts | 4 ++-- shared/js/connection/ConnectionBase.ts | 8 +++++++- shared/js/connection/HandshakeHandler.ts | 22 ++++++++-------------- shared/js/proto.ts | 4 +++- shared/js/ui/view.ts | 8 ++++---- web/js/connection/ServerConnection.ts | 9 --------- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/shared/js/ConnectionHandler.ts b/shared/js/ConnectionHandler.ts index 4ce48ad4..e75e2b87 100644 --- a/shared/js/ConnectionHandler.ts +++ b/shared/js/ConnectionHandler.ts @@ -347,6 +347,7 @@ export class ConnectionHandler { @EventHandler("notify_connection_state_changed") private handleConnectionConnected(event: ConnectionEvents["notify_connection_state_changed"]) { if(event.new_state !== ConnectionState.CONNECTED) return; + log.info(LogCategory.CLIENT, tr("Client connected")); this.log.log(server_log.Type.CONNECTION_CONNECTED, { own_client: this.getClient().log_data() @@ -667,6 +668,7 @@ export class ConnectionHandler { } private on_connection_state_changed(old_state: ConnectionState, new_state: ConnectionState) { + console.log("From %s to %s", ConnectionState[old_state], ConnectionState[new_state]); this.event_registry.fire("notify_connection_state_changed", { old_state: old_state, new_state: new_state diff --git a/shared/js/connection/CommandHandler.ts b/shared/js/connection/CommandHandler.ts index dedb9b2f..a05c2924 100644 --- a/shared/js/connection/CommandHandler.ts +++ b/shared/js/connection/CommandHandler.ts @@ -428,7 +428,7 @@ export class ConnectionCommandHandler extends AbstractCommandHandler { tree.moveClient(client, channel); } - if(this.connection_handler.client_status.queries_visible || client.properties.client_type != ClientType.CLIENT_QUERY) { + if(this.connection_handler.areQueriesShown() || client.properties.client_type != ClientType.CLIENT_QUERY) { const own_channel = this.connection.client.getClient().currentChannel(); this.connection_handler.log.log(server_log.Type.CLIENT_VIEW_ENTER, { channel_from: old_channel ? old_channel.log_data() : undefined, @@ -531,7 +531,7 @@ export class ConnectionCommandHandler extends AbstractCommandHandler { } - if(this.connection_handler.client_status.queries_visible || client.properties.client_type != ClientType.CLIENT_QUERY) { + if(this.connection_handler.areQueriesShown() || client.properties.client_type != ClientType.CLIENT_QUERY) { const own_channel = this.connection.client.getClient().currentChannel(); let channel_from = tree.findChannel(entry["cfid"]); let channel_to = tree.findChannel(entry["ctid"]); diff --git a/shared/js/connection/ConnectionBase.ts b/shared/js/connection/ConnectionBase.ts index 512807dd..b9e6a159 100644 --- a/shared/js/connection/ConnectionBase.ts +++ b/shared/js/connection/ConnectionBase.ts @@ -22,6 +22,7 @@ export type ConnectionStateListener = (old_state: ConnectionState, new_state: Co export abstract class AbstractServerConnection { readonly client: ConnectionHandler; readonly command_helper: CommandHelper; + protected connection_state_: ConnectionState = ConnectionState.UNCONNECTED; protected constructor(client: ConnectionHandler) { this.client = client; @@ -48,7 +49,12 @@ export abstract class AbstractServerConnection { abstract handshake_handler() : HandshakeHandler; /* only valid when connected */ //FIXME: Remove this this is currently only some kind of hack - abstract updateConnectionState(state: ConnectionState); + updateConnectionState(state: ConnectionState) { + const old_state = this.connection_state_; + this.connection_state_ = state; + if(this.onconnectionstatechanged) + this.onconnectionstatechanged(old_state, state); + } abstract ping() : { native: number, diff --git a/shared/js/connection/HandshakeHandler.ts b/shared/js/connection/HandshakeHandler.ts index 14143346..9d6002c6 100644 --- a/shared/js/connection/HandshakeHandler.ts +++ b/shared/js/connection/HandshakeHandler.ts @@ -76,12 +76,11 @@ export class HandshakeHandler { private handshake_finished(version?: string) { const _native = window["native"]; - if(native_client && _native && _native.client_version && !version) { + if(__build.target === "client" && _native.client_version && !version) { _native.client_version() .then( this.handshake_finished.bind(this)) .catch(error => { - console.error(tr("Failed to get version:")); - console.error(error); + console.error(tr("Failed to get version: %o"), error); this.handshake_finished("?.?.?"); }); return; @@ -102,19 +101,16 @@ export class HandshakeHandler { client_server_password: this.parameters.password ? this.parameters.password.password : undefined, client_browser_engine: navigator.product, - client_input_hardware: this.connection.client.client_status.input_hardware, + client_input_hardware: this.connection.client.client_status.input_hardware, //FIXME: No direct access to that state! client_output_hardware: false, - client_input_muted: this.connection.client.client_status.input_muted, - client_output_muted: this.connection.client.client_status.output_muted, + client_input_muted: this.connection.client.client_status.input_muted, //FIXME: No direct access to that state! + client_output_muted: this.connection.client.client_status.output_muted, //FIXME: No direct access to that state! }; - //0.0.1 [Build: 1549713549] Linux 7XvKmrk7uid2ixHFeERGqcC8vupeQqDypLtw2lY9slDNPojEv//F47UaDLG+TmVk4r6S0TseIKefzBpiRtLDAQ== - if(version) { - data.client_version = "TeaClient "; - data.client_version += " " + version; + data.client_version = "TeaClient " + version; - const os = require("os"); + const os = __non_webpack_require__("os"); const arch_mapping = { "x32": "32bit", "x64": "64bit" @@ -129,10 +125,8 @@ export class HandshakeHandler { data.client_platform = (os_mapping[os.platform()] || os.platform()); } - /* required to keep compatibility */ - if(this.profile.selected_type() === IdentitifyType.TEAMSPEAK) { + if(this.profile.selected_type() === IdentitifyType.TEAMSPEAK) data["client_key_offset"] = (this.profile.selected_identity() as TeaSpeakIdentity).hash_number; - } this.connection.send_command("clientinit", data).catch(error => { if(error instanceof CommandResult) { diff --git a/shared/js/proto.ts b/shared/js/proto.ts index 4a3f7bd7..130c5279 100644 --- a/shared/js/proto.ts +++ b/shared/js/proto.ts @@ -78,8 +78,10 @@ declare global { hljs: HighlightJS; remarkable: any; - require(id: string): any; + + readonly require: typeof require; } + const __non_webpack_require__: typeof require; interface Navigator { browserSpecs: { diff --git a/shared/js/ui/view.ts b/shared/js/ui/view.ts index cd0c80db..e237ba3f 100644 --- a/shared/js/ui/view.ts +++ b/shared/js/ui/view.ts @@ -42,15 +42,15 @@ export class ChannelTree { private _listener_document_click; private _listener_document_key; - private _scroll_bar: SimpleBar; + private _scroll_bar/*: SimpleBar*/; constructor(client) { this.client = client; this._tag_container = $.spawn("div").addClass("channel-tree-container"); this._tag_entries = $.spawn("div").addClass("channel-tree"); - if('SimpleBar' in window) /* for MSEdge, and may consider Firefox? */ - this._scroll_bar = new SimpleBar(this._tag_container[0]); + //if('SimpleBar' in window) /* for MSEdge, and may consider Firefox? */ + // this._scroll_bar = new SimpleBar(this._tag_container[0]); this.client_mover = new ClientMover(this); this.reset(); @@ -131,7 +131,7 @@ export class ChannelTree { e.recalculate_repetitive_name(); e.reorderClients(); }); - this._scroll_bar.recalculate(); + this._scroll_bar?.recalculate(); } showContextMenu(x: number, y: number, on_close: () => void = undefined) { diff --git a/web/js/connection/ServerConnection.ts b/web/js/connection/ServerConnection.ts index 39413afe..7eb3ba2c 100644 --- a/web/js/connection/ServerConnection.ts +++ b/web/js/connection/ServerConnection.ts @@ -28,8 +28,6 @@ class ReturnListener { } export class ServerConnection extends AbstractServerConnection { - _connectionState: ConnectionState = ConnectionState.UNCONNECTED; - private _remote_address: ServerAddress; private _handshakeHandler: HandshakeHandler; @@ -297,13 +295,6 @@ export class ServerConnection extends AbstractServerConnection { this._handshakeHandler.startHandshake(); } - updateConnectionState(state: ConnectionState) { - const old_state = this._connectionState; - this._connectionState = state; - if(this._connection_state_listener) - this._connection_state_listener(old_state, state); - } - async disconnect(reason?: string) : Promise { this.updateConnectionState(ConnectionState.DISCONNECTING); try {