Change code style of user media

This commit is contained in:
Timo K
2026-01-09 18:27:56 +01:00
parent 9a88e3dab6
commit 444c50d8c4
2 changed files with 30 additions and 54 deletions

View File

@@ -124,9 +124,9 @@ import {
} from "./remoteMembers/ConnectionManager.ts"; } from "./remoteMembers/ConnectionManager.ts";
import { import {
createMatrixLivekitMembers$, createMatrixLivekitMembers$,
type TaggedParticipant,
type LocalMatrixLivekitMember, type LocalMatrixLivekitMember,
type RemoteMatrixLivekitMember, type RemoteMatrixLivekitMember,
type MatrixLivekitMember,
} from "./remoteMembers/MatrixLivekitMembers.ts"; } from "./remoteMembers/MatrixLivekitMembers.ts";
import { import {
type AutoLeaveReason, type AutoLeaveReason,
@@ -717,62 +717,38 @@ export function createCallViewModel$(
matrixLivekitMembers, matrixLivekitMembers,
duplicateTiles, duplicateTiles,
]) { ]) {
let localUserMediaId: string | undefined = undefined; const computeMediaId = (m: MatrixLivekitMember): string =>
// add local member if available `${m.userId}:${m.membership$.value.deviceId}`;
if (localMatrixLivekitMember) {
const { userId, participant, connection$, membership$ } =
localMatrixLivekitMember;
localUserMediaId = `${userId}:${membership$.value.deviceId}`; const localUserMediaId = localMatrixLivekitMember
? computeMediaId(localMatrixLivekitMember)
: undefined;
const localAsArray = localMatrixLivekitMember
? [localMatrixLivekitMember]
: [];
const remoteWithoutLocal = matrixLivekitMembers.value.filter(
(m) => computeMediaId(m) !== localUserMediaId,
);
const allMatrixLivekitMembers = [
...localAsArray,
...remoteWithoutLocal,
];
for (const matrixLivekitMember of allMatrixLivekitMembers) {
const { userId, participant, connection$, membership$ } =
matrixLivekitMember;
const memb = membership$.value;
const mediaId = computeMediaId(matrixLivekitMember);
for (let dup = 0; dup < 1 + duplicateTiles; dup++) { for (let dup = 0; dup < 1 + duplicateTiles; dup++) {
yield { yield {
keys: [ keys: [dup, mediaId, userId, participant, connection$, memb],
dup,
localUserMediaId,
userId,
participant satisfies TaggedParticipant as TaggedParticipant, // Widen the type safely
connection$,
membership$.value,
],
data: undefined,
};
}
}
// add remote members that are available
for (const {
userId,
participant,
connection$,
membership$,
} of matrixLivekitMembers.value) {
const userMediaId = `${userId}:${membership$.value.deviceId}`;
// skip local user as we added them manually before
if (userMediaId === localUserMediaId) continue;
for (let dup = 0; dup < 1 + duplicateTiles; dup++) {
yield {
keys: [
dup,
userMediaId,
userId,
participant,
connection$,
membership$.value,
],
data: undefined, data: undefined,
}; };
} }
} }
}, },
( (scope, _, dup, mediaId, userId, participant, connection$, memb) => {
scope,
_data$,
dup,
userMediaId,
userId,
participant,
connection$,
membership,
) => {
const livekitRoom$ = scope.behavior( const livekitRoom$ = scope.behavior(
connection$.pipe(map((c) => c?.livekitRoom)), connection$.pipe(map((c) => c?.livekitRoom)),
); );
@@ -787,9 +763,9 @@ export function createCallViewModel$(
return new UserMedia( return new UserMedia(
scope, scope,
`${userMediaId}:${dup}`, `${mediaId}:${dup}`,
userId, userId,
membership, memb,
participant, participant,
options.encryptionSystem, options.encryptionSystem,
livekitRoom$, livekitRoom$,
@@ -798,8 +774,8 @@ export function createCallViewModel$(
localMembership.reconnecting$, localMembership.reconnecting$,
displayName$, displayName$,
matrixMemberMetadataStore.createAvatarUrlBehavior$(userId), matrixMemberMetadataStore.createAvatarUrlBehavior$(userId),
handsRaised$.pipe(map((v) => v[userMediaId]?.time ?? null)), handsRaised$.pipe(map((v) => v[mediaId]?.time ?? null)),
reactions$.pipe(map((v) => v[userMediaId] ?? undefined)), reactions$.pipe(map((v) => v[mediaId] ?? undefined)),
); );
}, },
), ),

View File

@@ -33,7 +33,7 @@ export type TaggedParticipant =
| LocalTaggedParticipant | LocalTaggedParticipant
| RemoteTaggedParticipant; | RemoteTaggedParticipant;
interface MatrixLivekitMember { export interface MatrixLivekitMember {
membership$: Behavior<CallMembership>; membership$: Behavior<CallMembership>;
connection$: Behavior<Connection | null>; connection$: Behavior<Connection | null>;
// participantId: string; We do not want a participantId here since it will be generated by the jwt // participantId: string; We do not want a participantId here since it will be generated by the jwt