diff --git a/index.php b/index.php index 9c0217b9..ca52f163 100644 --- a/index.php +++ b/index.php @@ -31,6 +31,7 @@ + " + + "If you're shure that the remot host is up, than you may not allow unsigned certificates.
" + + "Click here to accept the remote certificate" ).open(); break; case DisconnectReason.CONNECTION_CLOSED: diff --git a/js/codec/BasicCodec.ts b/js/codec/BasicCodec.ts index 85757c0b..24668a87 100644 --- a/js/codec/BasicCodec.ts +++ b/js/codec/BasicCodec.ts @@ -15,7 +15,7 @@ abstract class BasicCodec implements Codec { this.samplesPerUnit = 960; this._audioContext = new OfflineAudioContext(1, 1024,44100 ); this._codecSampleRate = codecSampleRate; - this._decodeResampler = new AudioResampler(); + this._decodeResampler = new AudioResampler(AudioController.globalContext.sampleRate); this._encodeResampler = new AudioResampler(codecSampleRate); } @@ -49,8 +49,13 @@ abstract class BasicCodec implements Codec { cache._chunks.pop_front(); } + let encodeBegin = new Date().getTime(); this.encode(buffer).then(result => { - if(result instanceof Uint8Array) this.on_encoded_data(result); + if(result instanceof Uint8Array) { + if(new Date().getTime() - 20 > encodeBegin) + console.error("Required time: %d", new Date().getTime() - encodeBegin); + this.on_encoded_data(result); + } else console.error("[Codec][" + this.name() + "] Could not encode buffer. Result: " + result); }); } diff --git a/js/codec/CodecWrapper.ts b/js/codec/CodecWrapper.ts index ad991ca0..8c9c42b6 100644 --- a/js/codec/CodecWrapper.ts +++ b/js/codec/CodecWrapper.ts @@ -139,7 +139,7 @@ class CodecWrapper extends BasicCodec { } private spawnWorker() { - this._worker = new Worker("js/codec/CompiledCodecWorker.js"); + this._worker = new Worker("js/codec/workers/CompiledCodecWorker.js"); this._worker.onmessage = event => this.onWorkerMessage(JSON.parse(event.data)); } } \ No newline at end of file diff --git a/js/codec/compile.sh b/js/codec/compile.sh index 7e9bd35e..70a3dd2d 100755 --- a/js/codec/compile.sh +++ b/js/codec/compile.sh @@ -1 +1,2 @@ -/usr/local/bin/tsc +#!/usr/bin/env bash +/usr/local/bin/tsc diff --git a/js/codec/workers/OpusCodec.ts b/js/codec/workers/OpusCodec.ts index 08e6b852..c7f3dbff 100644 --- a/js/codec/workers/OpusCodec.ts +++ b/js/codec/workers/OpusCodec.ts @@ -7,8 +7,12 @@ try { try { importScripts("../../asm/generated/TeaWeb-Native.js"); } catch (e) { - console.error("Could not load native script!"); - console.log(e); + try { + importScripts("../../../asm/generated/TeaWeb-Native.js"); + } catch (e) { + console.error("Could not load native script!"); + console.log(e); + } } } diff --git a/js/connection.ts b/js/connection.ts index d9ea343a..80f281b9 100644 --- a/js/connection.ts +++ b/js/connection.ts @@ -39,7 +39,7 @@ class ServerConnection { commandHandler: ConnectionCommandHandler; private _connectTimeoutHandler: NodeJS.Timer = undefined; - + private _connected: boolean = false; private _retCodeIdx: number; private _retListener: ReturnListener[]; @@ -73,6 +73,7 @@ class ServerConnection { this._remotePort = port; this._handshakeHandler = handshake; this._handshakeHandler.setConnection(this); + this._connected = false; chat.serverChat().appendMessage("Connecting to " + host + ":" + port); const self = this; @@ -89,12 +90,13 @@ class ServerConnection { this._socket.onopen = () => { if(this._socket != sockCpy) return; + this._connected = true; this.on_connect(); }; this._socket.onclose = event => { if(this._socket != sockCpy) return; - this._client.handleDisconnect(DisconnectReason.CONNECTION_CLOSED, { + this._client.handleDisconnect(this._connected ? DisconnectReason.CONNECTION_CLOSED : DisconnectReason.CONNECT_FAILURE, { code: event.code, reason: event.reason, event: event @@ -132,6 +134,7 @@ class ServerConnection { future.reject("Connection closed"); this._retListener = []; this._retCodeIdx = 0; + this._connected = false; return true; } diff --git a/js/crypto/sha.ts b/js/crypto/sha.ts index d1532eb9..d4cc3ca1 100644 --- a/js/crypto/sha.ts +++ b/js/crypto/sha.ts @@ -2,7 +2,7 @@ namespace sha { export function sha1(message: string | ArrayBuffer) : PromiseLike { - let buffer = message instanceof ArrayBuffer ? message : new TextEncoder("utf-8").encode(message); + let buffer = message instanceof ArrayBuffer ? message : new TextEncoder().encode(message); return crypto.subtle.digest("SHA-1", buffer); } diff --git a/js/settings.ts b/js/settings.ts index a7369953..b092dd3a 100644 --- a/js/settings.ts +++ b/js/settings.ts @@ -37,7 +37,7 @@ class Settings { private initializeStatic() { location.search.substr(1).split("&").forEach(part => { let item = part.split("="); - $.spawn("div") + $("") .attr("key", item[0]) .attr("value", item[1]) .appendTo(this._staticPropsTag); @@ -72,7 +72,7 @@ class Settings { static?(key: string, _default?: T) : T { let result = this._staticPropsTag.find("[key='" + key + "']"); - return Settings.transformStO(result.length > 0 ? decodeURIComponent(result.attr("value")) : undefined, _default); + return Settings.transformStO(result.length > 0 ? decodeURIComponent(result.last().attr("value")) : undefined, _default); } diff --git a/js/voice/AudioResampler.ts b/js/voice/AudioResampler.ts index 5a9f176d..c44d8315 100644 --- a/js/voice/AudioResampler.ts +++ b/js/voice/AudioResampler.ts @@ -7,6 +7,7 @@ class AudioResampler { } resample(buffer: AudioBuffer) : Promise { + console.log("Encode from %i to %i", buffer.sampleRate, this.targetSampleRate); if(buffer.sampleRate == this.targetSampleRate) return new Promise(resolve => resolve(buffer)); diff --git a/js/voice/VoiceHandler.ts b/js/voice/VoiceHandler.ts index 9b94392e..53ecf512 100644 --- a/js/voice/VoiceHandler.ts +++ b/js/voice/VoiceHandler.ts @@ -221,6 +221,8 @@ class VoiceConnection { private handleVoiceData(data: AudioBuffer, head: boolean) { if(!this.voiceRecorder) return; + if(!this.client.connected) return false; + if(this.client.controlBar.muteInput) return; if(head) { this.chunkVPacketId = 0;