From e1dd53220528cefd3fb0814a246f584fa985051b Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Wed, 2 Sep 2020 11:41:51 +0200 Subject: [PATCH] Some bugfixing --- ChangeLog.md | 4 ++++ shared/js/audio/recorder.ts | 1 + shared/js/voice/RecorderBase.ts | 2 +- shared/js/voice/RecorderProfile.ts | 6 +++++- web/app/audio/Recorder.ts | 17 +++++++++++------ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index f149db11..7336750c 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,4 +1,8 @@ # Changelog: +* **02.09.20** + - Fixed web client hangup on no device error + - Improved default recorder device detection (selectes by default the best device) + * **31.08.20** - Reworked the audio decode system - Improved audio decode performance diff --git a/shared/js/audio/recorder.ts b/shared/js/audio/recorder.ts index cca8c7de..c8041631 100644 --- a/shared/js/audio/recorder.ts +++ b/shared/js/audio/recorder.ts @@ -40,6 +40,7 @@ export interface IDevice { } export namespace IDevice { export const NoDeviceId = "none"; + export const DefaultDeviceId = "default"; } export type PermissionState = "granted" | "denied" | "unknown"; diff --git a/shared/js/voice/RecorderBase.ts b/shared/js/voice/RecorderBase.ts index 28554024..7fabbb85 100644 --- a/shared/js/voice/RecorderBase.ts +++ b/shared/js/voice/RecorderBase.ts @@ -75,7 +75,7 @@ export interface AbstractInput { * If the target device is unknown than it should return EDEVICEUNKNOWN on start. * After changing the device, the input state falls to InputState.PAUSED. */ - setDeviceId(device: string | undefined) : Promise; + setDeviceId(device: string) : Promise; currentConsumer() : InputConsumer | undefined; setConsumer(consumer: InputConsumer) : Promise; diff --git a/shared/js/voice/RecorderProfile.ts b/shared/js/voice/RecorderProfile.ts index 7f0a7ec3..c52bf10a 100644 --- a/shared/js/voice/RecorderProfile.ts +++ b/shared/js/voice/RecorderProfile.ts @@ -165,7 +165,11 @@ export class RecorderProfile { /* apply initial config values */ this.input.setVolume(this.config.volume / 100); - await this.input.setDeviceId(this.config.device_id); + if(this.config.device_id) { + await this.input.setDeviceId(this.config.device_id); + } else { + await this.input.setDeviceId(IDevice.DefaultDeviceId); + } } private save() { diff --git a/web/app/audio/Recorder.ts b/web/app/audio/Recorder.ts index 5b91f774..81a97d32 100644 --- a/web/app/audio/Recorder.ts +++ b/web/app/audio/Recorder.ts @@ -203,17 +203,22 @@ class JavascriptInput implements AbstractInput { if(this.state != InputState.PAUSED) return; - return await (this.startPromise = this.doStart()); + /* do it async since if the doStart fails on the first iteration, we're setting the start promise, after it's getting cleared */ + return await (this.startPromise = Promise.resolve().then(() => this.doStart())); } private async doStart() : Promise { try { - if(this.state != InputState.PAUSED) + if(this.state != InputState.PAUSED) { throw tr("recorder already started"); + } this.state = InputState.INITIALIZING; - if(!this.deviceId) { - throw tr("invalid device"); + let deviceId; + if(this.deviceId === IDevice.NoDeviceId) { + throw tr("no device selected"); + } else if(this.deviceId === IDevice.DefaultDeviceId) { + deviceId = undefined; } if(!this.audioContext) { @@ -221,7 +226,7 @@ class JavascriptInput implements AbstractInput { return; } - const requestResult = await requestMediaStream(this.deviceId, undefined); + const requestResult = await requestMediaStream(deviceId, undefined); if(!(requestResult instanceof MediaStream)) { this.state = InputState.PAUSED; return requestResult; @@ -292,7 +297,7 @@ class JavascriptInput implements AbstractInput { } - async setDeviceId(deviceId: string | undefined) { + async setDeviceId(deviceId: string) { if(this.deviceId === deviceId) return;