Use share() on fromEvent() so that we multiplex subscribers onto the event emitter

This commit is contained in:
Hugh Nimmo-Smith
2025-03-06 21:17:32 +00:00
committed by Timo K
parent b5f5ab329a
commit 5d2e5e38e2

View File

@@ -40,6 +40,7 @@ import {
of, of,
race, race,
scan, scan,
share,
skip, skip,
startWith, startWith,
switchAll, switchAll,
@@ -464,6 +465,16 @@ export class CallViewModel extends ViewModel {
}, },
); );
private readonly membershipsChanged$ = fromEvent(
this.matrixRTCSession,
MatrixRTCSessionEvent.MembershipsChanged,
).pipe(share());
private readonly roomMembers$ = fromEvent(
this.matrixRTCSession.room,
RoomStateEvent.Members,
).pipe(share());
/** /**
* Displaynames for each member of the call. This will disambiguate * Displaynames for each member of the call. This will disambiguate
* any displaynames that clashes with another member. Only members * any displaynames that clashes with another member. Only members
@@ -471,9 +482,9 @@ export class CallViewModel extends ViewModel {
*/ */
public readonly memberDisplaynames$ = merge( public readonly memberDisplaynames$ = merge(
// Handle call membership changes. // Handle call membership changes.
fromEvent(this.matrixRTCSession, MatrixRTCSessionEvent.MembershipsChanged), this.membershipsChanged$,
// Handle room membership changes (and displayname updates) // Handle room membership changes (and displayname updates)
fromEvent(this.matrixRTCSession.room, RoomStateEvent.Members), this.roomMembers$,
).pipe( ).pipe(
startWith(null), startWith(null),
map(() => { map(() => {
@@ -496,6 +507,7 @@ export class CallViewModel extends ViewModel {
} }
return displaynameMap; return displaynameMap;
}), }),
this.scope.state(),
); );
/** /**
@@ -508,10 +520,7 @@ export class CallViewModel extends ViewModel {
// Also react to changes in the MatrixRTC session list. // Also react to changes in the MatrixRTC session list.
// The session list will also be update if a room membership changes. // The session list will also be update if a room membership changes.
// No additional RoomState event listener needs to be set up. // No additional RoomState event listener needs to be set up.
fromEvent( this.membershipsChanged$.pipe(startWith(null)),
this.matrixRTCSession,
MatrixRTCSessionEvent.MembershipsChanged,
).pipe(startWith(null)),
showNonMemberTiles.value$, showNonMemberTiles.value$,
]).pipe( ]).pipe(
scan( scan(