introduce publishingParticipants$
Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
@@ -66,6 +66,7 @@ import { logger } from "matrix-js-sdk/lib/logger";
|
|||||||
import {
|
import {
|
||||||
type CallMembership,
|
type CallMembership,
|
||||||
isLivekitFocusConfig,
|
isLivekitFocusConfig,
|
||||||
|
LivekitFocusConfig,
|
||||||
type MatrixRTCSession,
|
type MatrixRTCSession,
|
||||||
MatrixRTCSessionEvent,
|
MatrixRTCSessionEvent,
|
||||||
type MatrixRTCSessionEventHandlerMap,
|
type MatrixRTCSessionEventHandlerMap,
|
||||||
@@ -490,7 +491,6 @@ class Connection {
|
|||||||
for (const track of tracks) {
|
for (const track of tracks) {
|
||||||
await this.livekitRoom.localParticipant.publishTrack(track);
|
await this.livekitRoom.localParticipant.publishTrack(track);
|
||||||
}
|
}
|
||||||
// await this.livekitRoom.localParticipant.enableCameraAndMicrophone();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,17 +501,45 @@ class Connection {
|
|||||||
this.stopped = true;
|
this.stopped = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly participants$ = this.scope.behavior(
|
public readonly participantsIncludingJustSubscribers$ = this.scope.behavior(
|
||||||
connectedParticipantsObserver(this.livekitRoom),
|
connectedParticipantsObserver(this.livekitRoom),
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public readonly publishingParticipants$ = (
|
||||||
|
memberships$: Behavior<CallMembership[]>,
|
||||||
|
): Observable<RemoteParticipant[]> =>
|
||||||
|
this.scope.behavior(
|
||||||
|
combineLatest([
|
||||||
|
connectedParticipantsObserver(this.livekitRoom),
|
||||||
|
memberships$,
|
||||||
|
]).pipe(
|
||||||
|
map(([participants, memberships]) => {
|
||||||
|
const publishingMembers = membershipsFocusUrl(
|
||||||
|
memberships,
|
||||||
|
this.matrixRTCSession,
|
||||||
|
)
|
||||||
|
.filter((f) => f.livekit_service_url === this.serviceUrl)
|
||||||
|
.map((f) => f.membership);
|
||||||
|
return publishingMembers
|
||||||
|
.map((m) =>
|
||||||
|
participants.find(
|
||||||
|
(p) => p.identity === `${m.sender}:${m.deviceId}`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.filter((p): p is RemoteParticipant => !!p);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
public constructor(
|
public constructor(
|
||||||
private readonly livekitRoom: LivekitRoom,
|
private readonly livekitRoom: LivekitRoom,
|
||||||
private readonly serviceUrl: string,
|
private readonly serviceUrl: string,
|
||||||
private readonly livekitAlias: string,
|
private readonly livekitAlias: string,
|
||||||
private readonly client: MatrixClient,
|
private readonly client: MatrixClient,
|
||||||
private readonly scope: ObservableScope,
|
private readonly scope: ObservableScope,
|
||||||
|
private readonly matrixRTCSession: MatrixRTCSession,
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -523,7 +551,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
|
|
||||||
private readonly livekitAlias = getLivekitAlias(this.matrixRTCSession);
|
private readonly livekitAlias = getLivekitAlias(this.matrixRTCSession);
|
||||||
|
|
||||||
private readonly livekitRoom = new LivekitRoom({
|
private readonly localConnectionLivekitRoom = new LivekitRoom({
|
||||||
...defaultLiveKitOptions,
|
...defaultLiveKitOptions,
|
||||||
e2ee: this.e2eeOptions,
|
e2ee: this.e2eeOptions,
|
||||||
});
|
});
|
||||||
@@ -533,11 +561,12 @@ export class CallViewModel extends ViewModel {
|
|||||||
private readonly localConnection = this.localFocus.then(
|
private readonly localConnection = this.localFocus.then(
|
||||||
(focus) =>
|
(focus) =>
|
||||||
new Connection(
|
new Connection(
|
||||||
this.livekitRoom,
|
this.localConnectionLivekitRoom,
|
||||||
focus.livekit_service_url,
|
focus.livekit_service_url,
|
||||||
this.livekitAlias,
|
this.livekitAlias,
|
||||||
this.matrixRTCSession.room.client,
|
this.matrixRTCSession.room.client,
|
||||||
this.scope,
|
this.scope,
|
||||||
|
this.matrixRTCSession,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -553,10 +582,9 @@ export class CallViewModel extends ViewModel {
|
|||||||
map(
|
map(
|
||||||
(memberships) =>
|
(memberships) =>
|
||||||
new Set(
|
new Set(
|
||||||
memberships
|
membershipsFocusUrl(memberships, this.matrixRTCSession).map(
|
||||||
.map((m) => this.matrixRTCSession.resolveActiveFocus(m))
|
(f) => f.livekit_service_url,
|
||||||
.filter((f) => f !== undefined && isLivekitFocusConfig(f))
|
),
|
||||||
.map((f) => f.livekit_service_url),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -584,6 +612,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
this.livekitAlias,
|
this.livekitAlias,
|
||||||
this.matrixRTCSession.room.client,
|
this.matrixRTCSession.room.client,
|
||||||
this.scope,
|
this.scope,
|
||||||
|
this.matrixRTCSession,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -698,7 +727,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
private readonly remoteParticipants$ = this.scope
|
private readonly remoteParticipants$ = this.scope
|
||||||
.behavior<
|
.behavior<
|
||||||
RemoteParticipant[]
|
RemoteParticipant[]
|
||||||
>(combineLatest([this.localConnection, this.remoteConnections$], (localConnection, remoteConnections) => combineLatest([localConnection.participants$, ...[...remoteConnections.values()].map((c) => c.participants$)], (...ps) => ps.flat(1))).pipe(switchAll(), startWith([])))
|
>(combineLatest([this.localConnection, this.remoteConnections$], (localConnection, remoteConnections) => combineLatest([localConnection.participantsIncludingJustSubscribers$, ...[...remoteConnections.values()].map((c) => c.participantsIncludingJustSubscribers$)], (...ps) => ps.flat(1))).pipe(switchAll(), startWith([])))
|
||||||
.pipe(pauseWhen(this.pretendToBeDisconnected$));
|
.pipe(pauseWhen(this.pretendToBeDisconnected$));
|
||||||
|
|
||||||
private readonly memberships$ = this.scope.behavior(
|
private readonly memberships$ = this.scope.behavior(
|
||||||
@@ -781,7 +810,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
private readonly mediaItems$ = this.scope.behavior<MediaItem[]>(
|
private readonly mediaItems$ = this.scope.behavior<MediaItem[]>(
|
||||||
combineLatest([
|
combineLatest([
|
||||||
this.remoteParticipants$,
|
this.remoteParticipants$,
|
||||||
observeParticipantMedia(this.livekitRoom.localParticipant),
|
observeParticipantMedia(this.localConnectionLivekitRoom.localParticipant),
|
||||||
duplicateTiles.value$,
|
duplicateTiles.value$,
|
||||||
this.memberships$,
|
this.memberships$,
|
||||||
showNonMemberTiles.value$,
|
showNonMemberTiles.value$,
|
||||||
@@ -849,7 +878,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
member,
|
member,
|
||||||
participant,
|
participant,
|
||||||
this.options.encryptionSystem,
|
this.options.encryptionSystem,
|
||||||
this.livekitRoom,
|
this.localConnectionLivekitRoom,
|
||||||
this.mediaDevices,
|
this.mediaDevices,
|
||||||
this.pretendToBeDisconnected$,
|
this.pretendToBeDisconnected$,
|
||||||
this.memberDisplaynames$.pipe(
|
this.memberDisplaynames$.pipe(
|
||||||
@@ -874,7 +903,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
member,
|
member,
|
||||||
participant,
|
participant,
|
||||||
this.options.encryptionSystem,
|
this.options.encryptionSystem,
|
||||||
this.livekitRoom,
|
this.localConnectionLivekitRoom,
|
||||||
this.pretendToBeDisconnected$,
|
this.pretendToBeDisconnected$,
|
||||||
this.memberDisplaynames$.pipe(
|
this.memberDisplaynames$.pipe(
|
||||||
map((m) => m.get(matrixIdentifier) ?? "[👻]"),
|
map((m) => m.get(matrixIdentifier) ?? "[👻]"),
|
||||||
@@ -916,7 +945,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
undefined,
|
undefined,
|
||||||
participant,
|
participant,
|
||||||
this.options.encryptionSystem,
|
this.options.encryptionSystem,
|
||||||
this.livekitRoom,
|
this.localConnectionLivekitRoom,
|
||||||
this.mediaDevices,
|
this.mediaDevices,
|
||||||
this.pretendToBeDisconnected$,
|
this.pretendToBeDisconnected$,
|
||||||
this.memberDisplaynames$.pipe(
|
this.memberDisplaynames$.pipe(
|
||||||
@@ -1862,7 +1891,7 @@ export class CallViewModel extends ViewModel {
|
|||||||
// that our own media is displayed on screen.
|
// that our own media is displayed on screen.
|
||||||
this.matrixConnected$.pipe(this.scope.bind()).subscribe((connected) => {
|
this.matrixConnected$.pipe(this.scope.bind()).subscribe((connected) => {
|
||||||
const publications =
|
const publications =
|
||||||
this.livekitRoom.localParticipant.trackPublications.values();
|
this.localConnectionLivekitRoom.localParticipant.trackPublications.values();
|
||||||
if (connected) {
|
if (connected) {
|
||||||
for (const p of publications) {
|
for (const p of publications) {
|
||||||
if (p.track?.isUpstreamPaused === true) {
|
if (p.track?.isUpstreamPaused === true) {
|
||||||
@@ -1904,3 +1933,22 @@ export class CallViewModel extends ViewModel {
|
|||||||
this.join(); // TODO-MULTI-SFU: Use this view model for the lobby as well, and only call this once 'join' is clicked?
|
this.join(); // TODO-MULTI-SFU: Use this view model for the lobby as well, and only call this once 'join' is clicked?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const membershipsFocusUrl = (
|
||||||
|
memberships: CallMembership[],
|
||||||
|
matrixRTCSession: MatrixRTCSession,
|
||||||
|
): { livekit_service_url: string; membership: CallMembership }[] => {
|
||||||
|
return memberships
|
||||||
|
.map(
|
||||||
|
(m) =>
|
||||||
|
[matrixRTCSession.resolveActiveFocus(m), m] as [
|
||||||
|
LivekitFocusConfig | undefined,
|
||||||
|
CallMembership,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.filter(([f, _]) => f !== undefined && isLivekitFocusConfig(f))
|
||||||
|
.map(([f, m]) => ({
|
||||||
|
livekit_service_url: f!.livekit_service_url,
|
||||||
|
membership: m,
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user