mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +00:00
review: rename to AbortHandles
This commit is contained in:
@@ -24,7 +24,7 @@ import {
|
|||||||
InsufficientCapacityError,
|
InsufficientCapacityError,
|
||||||
UnknownCallError,
|
UnknownCallError,
|
||||||
} from "../utils/errors.ts";
|
} from "../utils/errors.ts";
|
||||||
import { Cancellable } from "../utils/cancellable.ts";
|
import { AbortHandle } from "../utils/abortHandle.ts";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
@@ -60,7 +60,7 @@ async function doConnect(
|
|||||||
sfuConfig: SFUConfig,
|
sfuConfig: SFUConfig,
|
||||||
audioEnabled: boolean,
|
audioEnabled: boolean,
|
||||||
initialDeviceId: string | undefined,
|
initialDeviceId: string | undefined,
|
||||||
cancellable: Cancellable,
|
cancellable: AbortHandle,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
// Always create an audio track manually.
|
// Always create an audio track manually.
|
||||||
// livekit (by default) keeps the mic track open when you mute, but if you start muted,
|
// livekit (by default) keeps the mic track open when you mute, but if you start muted,
|
||||||
@@ -93,7 +93,7 @@ async function doConnect(
|
|||||||
}
|
}
|
||||||
// There was a yield point previously (awaiting for the track to be created) so we need to check
|
// There was a yield point previously (awaiting for the track to be created) so we need to check
|
||||||
// if the operation was cancelled and stop connecting if needed.
|
// if the operation was cancelled and stop connecting if needed.
|
||||||
if (cancellable.isCancelled()) {
|
if (cancellable.isAborted()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"[Lifecycle] Signal Aborted: Pre-created audio track but connection aborted",
|
"[Lifecycle] Signal Aborted: Pre-created audio track but connection aborted",
|
||||||
);
|
);
|
||||||
@@ -109,7 +109,7 @@ async function doConnect(
|
|||||||
if (!audioEnabled) {
|
if (!audioEnabled) {
|
||||||
await preCreatedAudioTrack?.mute();
|
await preCreatedAudioTrack?.mute();
|
||||||
// There was a yield point. Check if the operation was cancelled and stop connecting.
|
// There was a yield point. Check if the operation was cancelled and stop connecting.
|
||||||
if (cancellable.isCancelled()) {
|
if (cancellable.isAborted()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"[Lifecycle] Signal Aborted: Pre-created audio track but connection aborted",
|
"[Lifecycle] Signal Aborted: Pre-created audio track but connection aborted",
|
||||||
);
|
);
|
||||||
@@ -132,7 +132,7 @@ async function doConnect(
|
|||||||
logger.info("[Lifecycle] Connecting & publishing");
|
logger.info("[Lifecycle] Connecting & publishing");
|
||||||
try {
|
try {
|
||||||
await connectAndPublish(livekitRoom, sfuConfig, preCreatedAudioTrack, []);
|
await connectAndPublish(livekitRoom, sfuConfig, preCreatedAudioTrack, []);
|
||||||
if (cancellable.isCancelled()) {
|
if (cancellable.isAborted()) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"[Lifecycle] Signal Aborted: Connected but operation was cancelled. Force disconnect",
|
"[Lifecycle] Signal Aborted: Connected but operation was cancelled. Force disconnect",
|
||||||
);
|
);
|
||||||
@@ -284,15 +284,15 @@ export function useECConnectionState(
|
|||||||
// Protection against potential leaks, where the component to be unmounted and there is
|
// Protection against potential leaks, where the component to be unmounted and there is
|
||||||
// still a pending doConnect promise. This would lead the user to still be in the call even
|
// still a pending doConnect promise. This would lead the user to still be in the call even
|
||||||
// if the component is unmounted.
|
// if the component is unmounted.
|
||||||
const cancelBag = useRef(new Set<Cancellable>());
|
const abortHandlesBag = useRef(new Set<AbortHandle>());
|
||||||
|
|
||||||
// This is a cleanup function that will be called when the component is unmounted.
|
// This is a cleanup function that will be called when the component is about to be unmounted.
|
||||||
// It will cancel all cancellables in the bag
|
// It will cancel all abortHandles in the bag
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const bag = cancelBag.current;
|
const bag = abortHandlesBag.current;
|
||||||
return (): void => {
|
return (): void => {
|
||||||
bag.forEach((cancellable) => {
|
bag.forEach((cancellable) => {
|
||||||
cancellable.cancel();
|
cancellable.abort();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
@@ -323,8 +323,8 @@ export function useECConnectionState(
|
|||||||
// always capturing audio: it helps keep bluetooth headsets in the right mode and
|
// always capturing audio: it helps keep bluetooth headsets in the right mode and
|
||||||
// mobile browsers to know we're doing a call.
|
// mobile browsers to know we're doing a call.
|
||||||
setIsInDoConnect(true);
|
setIsInDoConnect(true);
|
||||||
const cancellable = new Cancellable();
|
const cancellable = new AbortHandle();
|
||||||
cancelBag.current.add(cancellable);
|
abortHandlesBag.current.add(cancellable);
|
||||||
doConnect(
|
doConnect(
|
||||||
livekitRoom!,
|
livekitRoom!,
|
||||||
sfuConfig!,
|
sfuConfig!,
|
||||||
@@ -340,7 +340,7 @@ export function useECConnectionState(
|
|||||||
} else logger.error("Failed to connect to SFU", e);
|
} else logger.error("Failed to connect to SFU", e);
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
cancelBag.current.delete(cancellable);
|
abortHandlesBag.current.delete(cancellable);
|
||||||
setIsInDoConnect(false);
|
setIsInDoConnect(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/utils/abortHandle.ts
Normal file
18
src/utils/abortHandle.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2025 New Vector Ltd.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
Please see LICENSE in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class AbortHandle {
|
||||||
|
public constructor(private aborted = false) {}
|
||||||
|
|
||||||
|
public abort(): void {
|
||||||
|
this.aborted = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public isAborted(): boolean {
|
||||||
|
return this.aborted;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright 2025 New Vector Ltd.
|
|
||||||
|
|
||||||
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
||||||
Please see LICENSE in the repository root for full details.
|
|
||||||
*/
|
|
||||||
|
|
||||||
export class Cancellable {
|
|
||||||
public constructor(private cancelled = false) {}
|
|
||||||
|
|
||||||
public cancel(): void {
|
|
||||||
this.cancelled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public isCancelled(): boolean {
|
|
||||||
return this.cancelled;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user