Skip to content

Toger5/device-select-loop-fix-experiment #3289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: livekit
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"livekit-client": "^2.13.0",
"lodash-es": "^4.17.21",
"loglevel": "^1.9.1",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#head=develop",
"matrix-js-sdk": "github:matrix-org/matrix-js-sdk#head=robin/embedded-no-update-state",
"matrix-widget-api": "^1.13.0",
"normalize.css": "^8.0.1",
"observable-hooks": "^4.2.3",
Expand Down
5 changes: 5 additions & 0 deletions src/livekit/MediaDevicesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export interface MediaDeviceHandle {
*/
available: Map<string, DeviceLabel>;
selectedId: string | undefined;
selectedWebDeviceId: string | undefined;

/**
* An additional device configuration that makes us use only one channel of the
* output device and a reduced volume.
Expand Down Expand Up @@ -202,6 +204,7 @@ function useMediaDeviceHandle(
return useMemo(
() => ({
available,
selectedWebDeviceId: selectedId,
selectedId,
useAsEarpiece: false,
selectedGroupId,
Expand All @@ -214,6 +217,7 @@ function useMediaDeviceHandle(
export const deviceStub: MediaDeviceHandle = {
available: new Map(),
selectedId: undefined,
selectedWebDeviceId: undefined,
selectedGroupId: undefined,
select: () => {},
useAsEarpiece: false,
Expand Down Expand Up @@ -379,6 +383,7 @@ function useControlledOutput(): MediaDeviceHandle {
() => ({
available: available,
selectedId,
selectedWebDeviceId: undefined,
selectedGroupId: undefined,
select: setPreferredId,
useAsEarpiece: asEarpiece,
Expand Down
16 changes: 7 additions & 9 deletions src/livekit/useLivekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function useLivekit(
kind: MediaDeviceKind,
device: MediaDeviceHandle,
): void => {
const id = device.selectedId;
const id = device.selectedWebDeviceId;

// Detect if we're trying to use chrome's default device, in which case
// we need to to see if the default device has changed to a different device
Expand Down Expand Up @@ -348,14 +348,12 @@ export function useLivekit(
logger.error(`Failed to restart audio device track`, e);
});
}
} else {
if (id !== undefined && room.getActiveDevice(kind) !== id) {
room
.switchActiveDevice(kind, id)
.catch((e) =>
logger.error(`Failed to sync ${kind} device with LiveKit`, e),
);
}
} else if (id !== undefined && room.getActiveDevice(kind) !== id) {
room
.switchActiveDevice(kind, id)
.catch((e) =>
logger.error(`Failed to sync ${kind} device with LiveKit`, e),
);
}
};

Expand Down
10 changes: 7 additions & 3 deletions src/useAudioContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,18 @@ export function useAudioContext<S extends string>(

// Update the sink ID whenever we change devices.
useEffect(() => {
if (audioContext && "setSinkId" in audioContext) {
if (
audioContext &&
"setSinkId" in audioContext &&
audioOutput.selectedWebDeviceId
) {
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/setSinkId
// @ts-expect-error - setSinkId doesn't exist yet in types, maybe because it's not supported everywhere.
audioContext.setSinkId(audioOutput.selectedId).catch((ex) => {
audioContext.setSinkId(audioOutput.selectedWebDeviceId).catch((ex) => {
logger.warn("Unable to change sink for audio context", ex);
});
}
}, [audioContext, audioOutput.selectedId]);
}, [audioContext, audioOutput.selectedWebDeviceId]);
const { pan: earpiecePan, volume: earpieceVolume } = useEarpieceAudioConfig();

// Don't return a function until we're ready.
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7007,7 +7007,7 @@ __metadata:
livekit-client: "npm:^2.13.0"
lodash-es: "npm:^4.17.21"
loglevel: "npm:^1.9.1"
matrix-js-sdk: "github:matrix-org/matrix-js-sdk#head=develop"
matrix-js-sdk: "github:matrix-org/matrix-js-sdk#head=robin/embedded-no-update-state"
matrix-widget-api: "npm:^1.13.0"
normalize.css: "npm:^8.0.1"
observable-hooks: "npm:^4.2.3"
Expand Down Expand Up @@ -9610,9 +9610,9 @@ __metadata:
languageName: node
linkType: hard

"matrix-js-sdk@github:matrix-org/matrix-js-sdk#head=develop":
"matrix-js-sdk@github:matrix-org/matrix-js-sdk#head=robin/embedded-no-update-state":
version: 37.6.0
resolution: "matrix-js-sdk@https://github.com/matrix-org/matrix-js-sdk.git#commit=93982716951ce2583904bfc26b27d6a86ba17a87"
resolution: "matrix-js-sdk@https://github.com/matrix-org/matrix-js-sdk.git#commit=60c8d83df455cc685d0d00684fa84175c6b86381"
dependencies:
"@babel/runtime": "npm:^7.12.5"
"@matrix-org/matrix-sdk-crypto-wasm": "npm:^14.2.0"
Expand All @@ -9629,7 +9629,7 @@ __metadata:
sdp-transform: "npm:^2.14.1"
unhomoglyph: "npm:^1.0.6"
uuid: "npm:11"
checksum: 10c0/22a28099d2deaf0ca7f609a5859fe00fbd20c314d3b607a95b4a623a8aa159e428310b1849c77ab7b9875a29fc2d924cddbb6fc83dc4e42a74c4713401dcb0be
checksum: 10c0/c21768a8b799867d221a65d91865b43dcff3a0f585f18b4b450df0cbd12f6fdd1ad57f69db2a46dabed58ec145a6c3c822fc3b8a0fbcb45aeb8e991237ed6d56
languageName: node
linkType: hard

Expand Down
Loading