Skip to content
Merged
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
35 changes: 33 additions & 2 deletions src/state/CallViewModel/localMember/LocalMember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ describe("LocalMembership", () => {
matrixRTCMode: MatrixRTCMode.Matrix_2_0,
}),
matrixRTCSession: {
updateCallIntent: () => {},
leaveRoomSession: () => {},
updateCallIntent: vi.fn().mockReturnValue(Promise.resolve()),
leaveRoomSession: vi.fn(),
} as unknown as MatrixRTCSession,
muteStates: mockMuteStates(),
trackProcessorState$: constant({
Expand Down Expand Up @@ -244,6 +244,37 @@ describe("LocalMembership", () => {
});
});

it("logs if callIntent cannot be updated", async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is indeed testing the code, but looks like the code is talking to us? why are we trying to update call intent if not connected? I also find it strange that the intent is mutable :/ causes traffic everytime you mute/unmute camera

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also played with checking if we are connected here. But it was somewhat redundant. if we already have a check in the js-sdk if we are connected.

const scope = new ObservableScope();

const localTransport$ = new BehaviorSubject(aTransport);
const mockConnectionManager = {
transports$: constant(new Epoch([])),
connectionManagerData$: constant(new Epoch(new ConnectionManagerData())),
};
async function reject(): Promise<void> {
return Promise.reject(new Error("Not connected yet"));
}
const localMembership = createLocalMembership$({
scope,
...defaultCreateLocalMemberValues,
matrixRTCSession: {
updateCallIntent: vi.fn().mockImplementation(reject),
leaveRoomSession: vi.fn(),
},
connectionManager: mockConnectionManager,
localTransport$,
});
const expextedLog =
"'not connected yet' while updating the call intent (this is expected on startup)";
const internalLogger = vi.spyOn(localMembership.internalLoggerRef, "debug");

await flushPromises();
defaultCreateLocalMemberValues.muteStates.video.setEnabled$.value?.(true);
expect(internalLogger).toHaveBeenCalledWith(expextedLog);
scope.end();
});

const aTransport = {
transport: {
livekit_service_url: "a",
Expand Down
21 changes: 15 additions & 6 deletions src/state/CallViewModel/localMember/LocalMember.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ export const createLocalMembership$ = ({
* Fully connected
*/
connected$: Behavior<boolean>;
internalLoggerRef: Logger;
} => {
const logger = parentLogger.getChild("[LocalMembership]");
logger.debug(`Creating local membership..`);
Expand Down Expand Up @@ -520,12 +521,19 @@ export const createLocalMembership$ = ({
}
});

combineLatest([muteStates.video.enabled$, homeserverConnected.combined$])
.pipe(scope.bind())
.subscribe(([videoEnabled, connected]) => {
if (!connected) return;
void matrixRTCSession.updateCallIntent(videoEnabled ? "video" : "audio");
});
muteStates.video.enabled$.pipe(scope.bind()).subscribe((videoEnabled) => {
void matrixRTCSession
.updateCallIntent(videoEnabled ? "video" : "audio")
.catch((e) => {
if (e instanceof Error && e.message === "Not connected yet") {
logger.debug(
"'not connected yet' while updating the call intent (this is expected on startup)",
);
} else {
throw e;
}
});
});

// Keep matrix rtc session in sync with localTransport$, connectRequested$
scope.reconcile(
Expand Down Expand Up @@ -669,6 +677,7 @@ export const createLocalMembership$ = ({
sharingScreen$,
toggleScreenSharing,
connection$: localConnection$,
internalLoggerRef: logger,
};
};

Expand Down
15 changes: 10 additions & 5 deletions src/state/CallViewModel/localMember/LocalTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,22 @@ async function makeTransport(
// MSC4143: Attempt to fetch transports from backend.
if ("_unstable_getRTCTransports" in client) {
try {
const selectedTransport = await getFirstUsableTransport(
await client._unstable_getRTCTransports(),
);
const transportList = await client._unstable_getRTCTransports();
const selectedTransport = await getFirstUsableTransport(transportList);
if (selectedTransport) {
logger.info("Using backend-configured SFU", selectedTransport);
logger.info(
"Using backend-configured (client.getRTCTransports) SFU",
selectedTransport,
);
return selectedTransport;
}
} catch (ex) {
if (ex instanceof MatrixError && ex.httpStatus === 404) {
// Expected, this is an unstable endpoint and it's not required.
logger.debug("Backend does not provide any RTC transports", ex);
// There will be expected 404 errors in the console. When we check if synapse supports the endpoint.
logger.debug(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This a bit strange for a log no? looks lie it is a user facing string.
Maybe keep the old log and add that as a comment?

"Matrix homeserver does not provide any RTC transports via `/rtc/transports` (will retry with well-known.)",
);
} else if (ex instanceof FailToGetOpenIdToken) {
throw ex;
} else {
Expand Down
2 changes: 0 additions & 2 deletions src/tile/SpotlightTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ interface SpotlightItemBaseProps {
mxcAvatarUrl: string | undefined;
focusable: boolean;
"aria-hidden"?: boolean;
localParticipant: boolean;
}

interface SpotlightUserMediaItemBaseProps extends SpotlightItemBaseProps {
Expand Down Expand Up @@ -188,7 +187,6 @@ const SpotlightItem: FC<SpotlightItemProps> = ({
focusable,
encryptionStatus,
"aria-hidden": ariaHidden,
localParticipant: vm.local,
};

return vm instanceof ScreenShareViewModel ? (
Expand Down
4 changes: 3 additions & 1 deletion src/utils/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,9 @@ export class MockRTCSession extends TypedEventEmitter<
return this;
}

public updateCallIntent = vitest.fn();
public updateCallIntent = vitest
.fn()
.mockImplementation(async () => Promise.resolve());

private _membershipStatus = Status.Connected;
public get membershipStatus(): Status {
Expand Down
Loading