fix: Prevent microphone auto-disconnect during calls and restore the removed microphone connected condition (#2597)
- Closes: #2590
This commit is contained in:
@@ -89,7 +89,7 @@ export class CallManager {
|
||||
// the call runs on the parent camera itself.
|
||||
const callCameraID = targetID === parentID ? undefined : targetID;
|
||||
|
||||
const existingCall = this._call;
|
||||
let existingCall = this._call;
|
||||
if (
|
||||
existingCall &&
|
||||
existingCall.cameraID === parentID &&
|
||||
@@ -120,6 +120,13 @@ export class CallManager {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Re-read: another `start()` may have installed a session while the
|
||||
// microphone connect was in flight. Acting on the reading from before the
|
||||
// await would skip the supersede handling below, leaving that session's
|
||||
// microphone marking and view state stranded with nothing able to undo
|
||||
// them.
|
||||
existingCall = this._call;
|
||||
|
||||
// Store the previous view so it can be restored later. A call superseding
|
||||
// another inherits the earlier call's previous view -- the user never left
|
||||
// the call. `queryResults` are dropped (re-fetched fresh on restore).
|
||||
@@ -152,6 +159,10 @@ export class CallManager {
|
||||
answered,
|
||||
};
|
||||
|
||||
// The microphone's own idle timeout knows nothing about calls, so without
|
||||
// this the tracks would be stopped mid-conversation.
|
||||
this._api.getMicrophoneManager().startUsing();
|
||||
|
||||
this._api.getViewManager().setViewByParameters({
|
||||
...(needsNavigation && {
|
||||
params: { view: 'live', camera: parentID },
|
||||
@@ -250,6 +261,7 @@ export class CallManager {
|
||||
this._unansweredTimer.stop();
|
||||
if (this._call) {
|
||||
this._call = null;
|
||||
this._api.getMicrophoneManager().stopUsing();
|
||||
this._api.getConditionStateManager().setState({ call: 'idle' });
|
||||
}
|
||||
this._api
|
||||
@@ -279,6 +291,10 @@ export class CallManager {
|
||||
// and recurse.
|
||||
this._call = null;
|
||||
|
||||
// The call no longer needs the microphone, so the normal
|
||||
// `disconnect_seconds` countdown restarts from here.
|
||||
this._api.getMicrophoneManager().stopUsing();
|
||||
|
||||
const viewManager = this._api.getViewManager();
|
||||
|
||||
// Navigate back only on an explicit end, and only when the call actually
|
||||
|
||||
@@ -25,6 +25,10 @@ export class MicrophoneManager {
|
||||
// it's created it will have the right mute status.
|
||||
private _desireMute = true;
|
||||
|
||||
// Whether something is actively using the microphone, and so when the
|
||||
// connection can safely be closed.
|
||||
private _inUse = false;
|
||||
|
||||
constructor(api: CardMicrophoneAPI) {
|
||||
this._api = api;
|
||||
}
|
||||
@@ -73,12 +77,28 @@ export class MicrophoneManager {
|
||||
}
|
||||
|
||||
public disconnect(): void {
|
||||
this._timer.stop();
|
||||
this._stream?.getTracks().forEach((track) => track.stop());
|
||||
|
||||
this._stream = undefined;
|
||||
this._setState();
|
||||
}
|
||||
|
||||
// Marks the microphone as in use (e.g. by an in-progress call). It stays
|
||||
// connected regardless of `disconnect_seconds` until `stopUsing`, since
|
||||
// stopping the tracks under a user would silently cut their audio.
|
||||
public startUsing(): void {
|
||||
this._inUse = true;
|
||||
this._timer.stop();
|
||||
}
|
||||
|
||||
// Marks the microphone as no longer in use. It is idle again, so the
|
||||
// disconnect countdown restarts from the full `disconnect_seconds`.
|
||||
public stopUsing(): void {
|
||||
this._inUse = false;
|
||||
this._startDisconnectTimer();
|
||||
}
|
||||
|
||||
public getStream(): MediaStream | undefined {
|
||||
return this._stream ?? undefined;
|
||||
}
|
||||
@@ -130,7 +150,7 @@ export class MicrophoneManager {
|
||||
private _startDisconnectTimer(): void {
|
||||
const microphoneConfig = this._api.getConfigManager().getConfig()?.live.microphone;
|
||||
|
||||
if (microphoneConfig?.always_connected) {
|
||||
if (microphoneConfig?.always_connected || this._inUse) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user