mirror of
https://github.com/vector-im/element-web.git
synced 2025-12-08 19:01:43 +01:00
Remember whether sidebar is shown for calls when switching rooms (#30262)
* Remember whether sidebar is shown for calls when switching rooms Stores the sidebar state per-room in LegacyCallHandler, along with other details about calls. * Hide the Show/Hide Sidebar from the Picture-in-Picture preview The toggle sidebar button currently does nothing in PIP mode, since PIP mode never shows a sidebar (even when the call is made fullscreen from the PIP preview) * Add test for Show/Hide Sidebar feature * Add more tests for LegacyCallView and LegacyCallViewForRoom Also, fix issue where LegacyCallViewForRoom used roomId and not callId for checking for sidebar state
This commit is contained in:
parent
4d48d1b2f2
commit
8903927e0c
@ -112,6 +112,7 @@ export enum LegacyCallHandlerEvent {
|
|||||||
CallsChanged = "calls_changed",
|
CallsChanged = "calls_changed",
|
||||||
CallChangeRoom = "call_change_room",
|
CallChangeRoom = "call_change_room",
|
||||||
SilencedCallsChanged = "silenced_calls_changed",
|
SilencedCallsChanged = "silenced_calls_changed",
|
||||||
|
ShownSidebarsChanged = "shown_sidebars_changed",
|
||||||
CallState = "call_state",
|
CallState = "call_state",
|
||||||
ProtocolSupport = "protocol_support",
|
ProtocolSupport = "protocol_support",
|
||||||
}
|
}
|
||||||
@ -120,6 +121,7 @@ type EventEmitterMap = {
|
|||||||
[LegacyCallHandlerEvent.CallsChanged]: (calls: Map<string, MatrixCall>) => void;
|
[LegacyCallHandlerEvent.CallsChanged]: (calls: Map<string, MatrixCall>) => void;
|
||||||
[LegacyCallHandlerEvent.CallChangeRoom]: (call: MatrixCall) => void;
|
[LegacyCallHandlerEvent.CallChangeRoom]: (call: MatrixCall) => void;
|
||||||
[LegacyCallHandlerEvent.SilencedCallsChanged]: (calls: Set<string>) => void;
|
[LegacyCallHandlerEvent.SilencedCallsChanged]: (calls: Set<string>) => void;
|
||||||
|
[LegacyCallHandlerEvent.ShownSidebarsChanged]: (sidebarsShown: Map<string, boolean>) => void;
|
||||||
[LegacyCallHandlerEvent.CallState]: (mappedRoomId: string | null, status: CallState) => void;
|
[LegacyCallHandlerEvent.CallState]: (mappedRoomId: string | null, status: CallState) => void;
|
||||||
[LegacyCallHandlerEvent.ProtocolSupport]: () => void;
|
[LegacyCallHandlerEvent.ProtocolSupport]: () => void;
|
||||||
};
|
};
|
||||||
@ -144,6 +146,8 @@ export default class LegacyCallHandler extends TypedEventEmitter<LegacyCallHandl
|
|||||||
|
|
||||||
private silencedCalls = new Set<string>(); // callIds
|
private silencedCalls = new Set<string>(); // callIds
|
||||||
|
|
||||||
|
private shownSidebars = new Map<string, boolean>(); // callId (call) -> sidebar show
|
||||||
|
|
||||||
private backgroundAudio = new BackgroundAudio();
|
private backgroundAudio = new BackgroundAudio();
|
||||||
private playingSources: Record<string, AudioBufferSourceNode> = {}; // Record them for stopping
|
private playingSources: Record<string, AudioBufferSourceNode> = {}; // Record them for stopping
|
||||||
|
|
||||||
@ -240,6 +244,15 @@ export default class LegacyCallHandler extends TypedEventEmitter<LegacyCallHandl
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setCallSidebarShown(callId: string, sidebarShown: boolean): void {
|
||||||
|
this.shownSidebars.set(callId, sidebarShown);
|
||||||
|
this.emit(LegacyCallHandlerEvent.ShownSidebarsChanged, this.shownSidebars);
|
||||||
|
}
|
||||||
|
|
||||||
|
public isCallSidebarShown(callId?: string): boolean {
|
||||||
|
return !!callId && (this.shownSidebars.get(callId) ?? true);
|
||||||
|
}
|
||||||
|
|
||||||
private async checkProtocols(maxTries: number): Promise<void> {
|
private async checkProtocols(maxTries: number): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const protocols = await MatrixClientPeg.safeGet().getThirdpartyProtocols();
|
const protocols = await MatrixClientPeg.safeGet().getThirdpartyProtocols();
|
||||||
|
|||||||
@ -245,6 +245,7 @@ class PipContainerInner extends React.Component<IProps, IState> {
|
|||||||
secondaryCall={this.state.secondaryCall}
|
secondaryCall={this.state.secondaryCall}
|
||||||
pipMode={pipMode}
|
pipMode={pipMode}
|
||||||
onResize={onResize}
|
onResize={onResize}
|
||||||
|
sidebarShown={false}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,10 @@ interface IProps {
|
|||||||
onMouseDownOnHeader?: (event: React.MouseEvent<Element, MouseEvent>) => void;
|
onMouseDownOnHeader?: (event: React.MouseEvent<Element, MouseEvent>) => void;
|
||||||
|
|
||||||
showApps?: boolean;
|
showApps?: boolean;
|
||||||
|
|
||||||
|
sidebarShown: boolean;
|
||||||
|
|
||||||
|
setSidebarShown?: (sidebarShown: boolean) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
@ -62,7 +66,6 @@ interface IState {
|
|||||||
primaryFeed?: CallFeed;
|
primaryFeed?: CallFeed;
|
||||||
secondaryFeed?: CallFeed;
|
secondaryFeed?: CallFeed;
|
||||||
sidebarFeeds: Array<CallFeed>;
|
sidebarFeeds: Array<CallFeed>;
|
||||||
sidebarShown: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFullScreenElement(): Element | null {
|
function getFullScreenElement(): Element | null {
|
||||||
@ -97,7 +100,6 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
primaryFeed: primary,
|
primaryFeed: primary,
|
||||||
secondaryFeed: secondary,
|
secondaryFeed: secondary,
|
||||||
sidebarFeeds: sidebar,
|
sidebarFeeds: sidebar,
|
||||||
sidebarShown: true,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,8 +271,9 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
isScreensharing = await this.props.call.setScreensharingEnabled(true);
|
isScreensharing = await this.props.call.setScreensharingEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.props.setSidebarShown?.(true);
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
sidebarShown: true,
|
|
||||||
screensharing: isScreensharing,
|
screensharing: isScreensharing,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -320,12 +323,12 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private onToggleSidebar = (): void => {
|
private onToggleSidebar = (): void => {
|
||||||
this.setState({ sidebarShown: !this.state.sidebarShown });
|
this.props.setSidebarShown?.(!this.props.sidebarShown);
|
||||||
};
|
};
|
||||||
|
|
||||||
private renderCallControls(): JSX.Element {
|
private renderCallControls(): JSX.Element {
|
||||||
const { call, pipMode } = this.props;
|
const { call, pipMode, sidebarShown } = this.props;
|
||||||
const { callState, micMuted, vidMuted, screensharing, sidebarShown, secondaryFeed, sidebarFeeds } = this.state;
|
const { callState, micMuted, vidMuted, screensharing, secondaryFeed, sidebarFeeds } = this.state;
|
||||||
|
|
||||||
// If SDPStreamMetadata isn't supported don't show video mute button in voice calls
|
// If SDPStreamMetadata isn't supported don't show video mute button in voice calls
|
||||||
const vidMuteButtonShown = call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack;
|
const vidMuteButtonShown = call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack;
|
||||||
@ -337,7 +340,8 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
(call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack) &&
|
(call.opponentSupportsSDPStreamMetadata() || call.hasLocalUserMediaVideoTrack) &&
|
||||||
call.state === CallState.Connected;
|
call.state === CallState.Connected;
|
||||||
// Show the sidebar button only if there is something to hide/show
|
// Show the sidebar button only if there is something to hide/show
|
||||||
const sidebarButtonShown = (secondaryFeed && !secondaryFeed.isVideoMuted()) || sidebarFeeds.length > 0;
|
const sidebarButtonShown =
|
||||||
|
!pipMode && ((secondaryFeed && !secondaryFeed.isVideoMuted()) || sidebarFeeds.length > 0);
|
||||||
// The dial pad & 'more' button actions are only relevant in a connected call
|
// The dial pad & 'more' button actions are only relevant in a connected call
|
||||||
const contextMenuButtonShown = callState === CallState.Connected;
|
const contextMenuButtonShown = callState === CallState.Connected;
|
||||||
const dialpadButtonShown = callState === CallState.Connected && call.opponentSupportsDTMF();
|
const dialpadButtonShown = callState === CallState.Connected && call.opponentSupportsDTMF();
|
||||||
@ -372,7 +376,7 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderToast(): JSX.Element | null {
|
private renderToast(): JSX.Element | null {
|
||||||
const { call } = this.props;
|
const { call, sidebarShown } = this.props;
|
||||||
const someoneIsScreensharing = call.getFeeds().some((feed) => {
|
const someoneIsScreensharing = call.getFeeds().some((feed) => {
|
||||||
return feed.purpose === SDPStreamMetadataPurpose.Screenshare;
|
return feed.purpose === SDPStreamMetadataPurpose.Screenshare;
|
||||||
});
|
});
|
||||||
@ -380,7 +384,7 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
if (!someoneIsScreensharing) return null;
|
if (!someoneIsScreensharing) return null;
|
||||||
|
|
||||||
const isScreensharing = call.isScreensharing();
|
const isScreensharing = call.isScreensharing();
|
||||||
const { primaryFeed, sidebarShown } = this.state;
|
const { primaryFeed } = this.state;
|
||||||
const sharerName = primaryFeed?.getMember()?.name;
|
const sharerName = primaryFeed?.getMember()?.name;
|
||||||
if (!sharerName) return null;
|
if (!sharerName) return null;
|
||||||
|
|
||||||
@ -393,8 +397,8 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderContent(): JSX.Element {
|
private renderContent(): JSX.Element {
|
||||||
const { pipMode, call, onResize } = this.props;
|
const { pipMode, call, onResize, sidebarShown } = this.props;
|
||||||
const { isLocalOnHold, isRemoteOnHold, sidebarShown, primaryFeed, secondaryFeed, sidebarFeeds } = this.state;
|
const { isLocalOnHold, isRemoteOnHold, primaryFeed, secondaryFeed, sidebarFeeds } = this.state;
|
||||||
|
|
||||||
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
|
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
|
||||||
const callRoom = (callRoomId ? MatrixClientPeg.safeGet().getRoom(callRoomId) : undefined) ?? undefined;
|
const callRoom = (callRoomId ? MatrixClientPeg.safeGet().getRoom(callRoomId) : undefined) ?? undefined;
|
||||||
@ -537,8 +541,8 @@ export default class LegacyCallView extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
const { call, secondaryCall, pipMode, showApps, onMouseDownOnHeader } = this.props;
|
const { call, secondaryCall, pipMode, showApps, onMouseDownOnHeader, sidebarShown } = this.props;
|
||||||
const { sidebarShown, sidebarFeeds } = this.state;
|
const { sidebarFeeds } = this.state;
|
||||||
|
|
||||||
const client = MatrixClientPeg.safeGet();
|
const client = MatrixClientPeg.safeGet();
|
||||||
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
|
const callRoomId = LegacyCallHandler.instance.roomIdForCall(call);
|
||||||
|
|||||||
@ -25,6 +25,7 @@ interface IProps {
|
|||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
call: MatrixCall | null;
|
call: MatrixCall | null;
|
||||||
|
sidebarShown: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -34,19 +35,23 @@ interface IState {
|
|||||||
export default class LegacyCallViewForRoom extends React.Component<IProps, IState> {
|
export default class LegacyCallViewForRoom extends React.Component<IProps, IState> {
|
||||||
public constructor(props: IProps) {
|
public constructor(props: IProps) {
|
||||||
super(props);
|
super(props);
|
||||||
|
const call = this.getCall();
|
||||||
this.state = {
|
this.state = {
|
||||||
call: this.getCall(),
|
call,
|
||||||
|
sidebarShown: !!call && LegacyCallHandler.instance.isCallSidebarShown(call.callId),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentDidMount(): void {
|
public componentDidMount(): void {
|
||||||
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallState, this.updateCall);
|
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallState, this.updateCall);
|
||||||
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCall);
|
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCall);
|
||||||
|
LegacyCallHandler.instance.addListener(LegacyCallHandlerEvent.ShownSidebarsChanged, this.updateCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
public componentWillUnmount(): void {
|
public componentWillUnmount(): void {
|
||||||
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallState, this.updateCall);
|
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallState, this.updateCall);
|
||||||
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCall);
|
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.CallChangeRoom, this.updateCall);
|
||||||
|
LegacyCallHandler.instance.removeListener(LegacyCallHandlerEvent.ShownSidebarsChanged, this.updateCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateCall = (): void => {
|
private updateCall = (): void => {
|
||||||
@ -54,6 +59,10 @@ export default class LegacyCallViewForRoom extends React.Component<IProps, IStat
|
|||||||
if (newCall !== this.state.call) {
|
if (newCall !== this.state.call) {
|
||||||
this.setState({ call: newCall });
|
this.setState({ call: newCall });
|
||||||
}
|
}
|
||||||
|
const newSidebarShown = !!newCall && LegacyCallHandler.instance.isCallSidebarShown(newCall.callId);
|
||||||
|
if (newSidebarShown !== this.state.sidebarShown) {
|
||||||
|
this.setState({ sidebarShown: newSidebarShown });
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private getCall(): MatrixCall | null {
|
private getCall(): MatrixCall | null {
|
||||||
@ -75,6 +84,11 @@ export default class LegacyCallViewForRoom extends React.Component<IProps, IStat
|
|||||||
this.props.resizeNotifier.stopResizing();
|
this.props.resizeNotifier.stopResizing();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private setSidebarShown = (sidebarShown: boolean): void => {
|
||||||
|
if (!this.state.call) return;
|
||||||
|
LegacyCallHandler.instance.setCallSidebarShown(this.state.call.callId, sidebarShown);
|
||||||
|
};
|
||||||
|
|
||||||
public render(): React.ReactNode {
|
public render(): React.ReactNode {
|
||||||
if (!this.state.call) return null;
|
if (!this.state.call) return null;
|
||||||
|
|
||||||
@ -99,7 +113,13 @@ export default class LegacyCallViewForRoom extends React.Component<IProps, IStat
|
|||||||
className="mx_LegacyCallViewForRoom_ResizeWrapper"
|
className="mx_LegacyCallViewForRoom_ResizeWrapper"
|
||||||
handleClasses={{ bottom: "mx_LegacyCallViewForRoom_ResizeHandle" }}
|
handleClasses={{ bottom: "mx_LegacyCallViewForRoom_ResizeHandle" }}
|
||||||
>
|
>
|
||||||
<LegacyCallView call={this.state.call} pipMode={false} showApps={this.props.showApps} />
|
<LegacyCallView
|
||||||
|
call={this.state.call}
|
||||||
|
pipMode={false}
|
||||||
|
showApps={this.props.showApps}
|
||||||
|
sidebarShown={this.state.sidebarShown}
|
||||||
|
setSidebarShown={this.setSidebarShown}
|
||||||
|
/>
|
||||||
</Resizable>
|
</Resizable>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -585,4 +585,42 @@ describe("LegacyCallHandler without third party protocols", () => {
|
|||||||
expect(mockAudioBufferSourceNode.start).not.toHaveBeenCalled();
|
expect(mockAudioBufferSourceNode.start).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("sidebar state", () => {
|
||||||
|
const roomId = "test-room-id";
|
||||||
|
|
||||||
|
it("should default to showing sidebar", () => {
|
||||||
|
const call = new MatrixCall({
|
||||||
|
client: MatrixClientPeg.safeGet(),
|
||||||
|
roomId,
|
||||||
|
});
|
||||||
|
const cli = MatrixClientPeg.safeGet();
|
||||||
|
cli.emit(CallEventHandlerEvent.Incoming, call);
|
||||||
|
|
||||||
|
expect(callHandler.isCallSidebarShown(call.callId)).toEqual(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should remember sidebar state per call", () => {
|
||||||
|
const call = new MatrixCall({
|
||||||
|
client: MatrixClientPeg.safeGet(),
|
||||||
|
roomId,
|
||||||
|
});
|
||||||
|
const cli = MatrixClientPeg.safeGet();
|
||||||
|
cli.emit(CallEventHandlerEvent.Incoming, call);
|
||||||
|
|
||||||
|
expect(callHandler.isCallSidebarShown(call.callId)).toEqual(true);
|
||||||
|
callHandler.setCallSidebarShown(call.callId, false);
|
||||||
|
expect(callHandler.isCallSidebarShown(call.callId)).toEqual(false);
|
||||||
|
|
||||||
|
call.emit(CallEvent.Hangup, call);
|
||||||
|
|
||||||
|
const call2 = new MatrixCall({
|
||||||
|
client: MatrixClientPeg.safeGet(),
|
||||||
|
roomId,
|
||||||
|
});
|
||||||
|
cli.emit(CallEventHandlerEvent.Incoming, call2);
|
||||||
|
|
||||||
|
expect(callHandler.isCallSidebarShown(call2.callId)).toEqual(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -8,9 +8,12 @@ Please see LICENSE files in the repository root for full details.
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { render } from "jest-matrix-react";
|
import { render } from "jest-matrix-react";
|
||||||
import { type MatrixCall } from "matrix-js-sdk/src/matrix";
|
import { type MatrixCall } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { type CallFeed } from "matrix-js-sdk/src/webrtc/callFeed";
|
||||||
|
import { SDPStreamMetadataPurpose } from "matrix-js-sdk/src/webrtc/callEventTypes";
|
||||||
|
|
||||||
import LegacyCallView from "../../../../../src/components/views/voip/LegacyCallView";
|
import LegacyCallView from "../../../../../src/components/views/voip/LegacyCallView";
|
||||||
import { stubClient } from "../../../../test-utils";
|
import { stubClient } from "../../../../test-utils";
|
||||||
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||||
|
|
||||||
describe("LegacyCallView", () => {
|
describe("LegacyCallView", () => {
|
||||||
it("should exit full screen on unmount", () => {
|
it("should exit full screen on unmount", () => {
|
||||||
@ -32,9 +35,70 @@ describe("LegacyCallView", () => {
|
|||||||
isScreensharing: jest.fn().mockReturnValue(false),
|
isScreensharing: jest.fn().mockReturnValue(false),
|
||||||
} as unknown as MatrixCall;
|
} as unknown as MatrixCall;
|
||||||
|
|
||||||
const { unmount } = render(<LegacyCallView call={call} />);
|
const { unmount } = render(<LegacyCallView call={call} sidebarShown={false} />);
|
||||||
expect(document.exitFullscreen).not.toHaveBeenCalled();
|
expect(document.exitFullscreen).not.toHaveBeenCalled();
|
||||||
unmount();
|
unmount();
|
||||||
expect(document.exitFullscreen).toHaveBeenCalled();
|
expect(document.exitFullscreen).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should show/hide the sidebar based on the sidebarShown prop", async () => {
|
||||||
|
stubClient();
|
||||||
|
|
||||||
|
const call = {
|
||||||
|
roomId: "test-room",
|
||||||
|
on: jest.fn(),
|
||||||
|
removeListener: jest.fn(),
|
||||||
|
getFeeds: jest.fn().mockReturnValue(
|
||||||
|
[{ local: true }, { local: false }, { local: true, screenshare: true }].map(
|
||||||
|
(x, i) =>
|
||||||
|
({
|
||||||
|
stream: { id: "test-" + i },
|
||||||
|
addListener: jest.fn(),
|
||||||
|
removeListener: jest.fn(),
|
||||||
|
getMember: jest.fn(),
|
||||||
|
isAudioMuted: jest.fn().mockReturnValue(true),
|
||||||
|
isVideoMuted: jest.fn().mockReturnValue(true),
|
||||||
|
isLocal: jest.fn().mockReturnValue(x.local),
|
||||||
|
purpose: x.screenshare && SDPStreamMetadataPurpose.Screenshare,
|
||||||
|
}) as unknown as CallFeed,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
isLocalOnHold: jest.fn().mockReturnValue(false),
|
||||||
|
isRemoteOnHold: jest.fn().mockReturnValue(false),
|
||||||
|
isMicrophoneMuted: jest.fn().mockReturnValue(true),
|
||||||
|
isLocalVideoMuted: jest.fn().mockReturnValue(true),
|
||||||
|
isScreensharing: jest.fn().mockReturnValue(true),
|
||||||
|
noIncomingFeeds: jest.fn().mockReturnValue(false),
|
||||||
|
opponentSupportsSDPStreamMetadata: jest.fn().mockReturnValue(true),
|
||||||
|
} as unknown as MatrixCall;
|
||||||
|
DMRoomMap.setShared({
|
||||||
|
getUserIdForRoomId: jest.fn().mockReturnValue("test-user"),
|
||||||
|
} as unknown as DMRoomMap);
|
||||||
|
|
||||||
|
const { container, rerender } = render(<LegacyCallView call={call} sidebarShown={true} />);
|
||||||
|
expect(container.querySelector(".mx_LegacyCallViewSidebar")).toBeTruthy();
|
||||||
|
rerender(<LegacyCallView call={call} sidebarShown={true} />);
|
||||||
|
expect(container.querySelector(".mx_LegacyCallViewSidebar")).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not show the sidebar button in picture-in-picture mode", async () => {
|
||||||
|
stubClient();
|
||||||
|
|
||||||
|
const call = {
|
||||||
|
on: jest.fn(),
|
||||||
|
removeListener: jest.fn(),
|
||||||
|
getFeeds: jest.fn().mockReturnValue([]),
|
||||||
|
isLocalOnHold: jest.fn().mockReturnValue(false),
|
||||||
|
isRemoteOnHold: jest.fn().mockReturnValue(false),
|
||||||
|
isMicrophoneMuted: jest.fn().mockReturnValue(false),
|
||||||
|
isLocalVideoMuted: jest.fn().mockReturnValue(false),
|
||||||
|
isScreensharing: jest.fn().mockReturnValue(false),
|
||||||
|
} as unknown as MatrixCall;
|
||||||
|
DMRoomMap.setShared({
|
||||||
|
getUserIdForRoomId: jest.fn().mockReturnValue("test-user"),
|
||||||
|
} as unknown as DMRoomMap);
|
||||||
|
|
||||||
|
const { container } = render(<LegacyCallView call={call} sidebarShown={false} pipMode={true} />);
|
||||||
|
expect(container.querySelector(".mx_LegacyCallViewButtons_button_sidebar")).toBeFalsy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2025 New Vector Ltd.
|
||||||
|
|
||||||
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||||
|
Please see LICENSE files in the repository root for full details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from "react";
|
||||||
|
import { render } from "jest-matrix-react";
|
||||||
|
import { MatrixCall } from "matrix-js-sdk/src/webrtc/call";
|
||||||
|
import { CallEventHandlerEvent } from "matrix-js-sdk/src/webrtc/callEventHandler";
|
||||||
|
|
||||||
|
import LegacyCallView from "../../../../../src/components/views/voip/LegacyCallView";
|
||||||
|
import LegacyCallViewForRoom from "../../../../../src/components/views/voip/LegacyCallViewForRoom";
|
||||||
|
import { mkStubRoom, stubClient } from "../../../../test-utils";
|
||||||
|
import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||||
|
import { MatrixClientPeg } from "../../../../../src/MatrixClientPeg";
|
||||||
|
import ResizeNotifier from "../../../../../src/utils/ResizeNotifier";
|
||||||
|
import LegacyCallHandler from "../../../../../src/LegacyCallHandler";
|
||||||
|
|
||||||
|
jest.mock("../../../../../src/components/views/voip/LegacyCallView", () => jest.fn(() => "LegacyCallView"));
|
||||||
|
|
||||||
|
describe("LegacyCallViewForRoom", () => {
|
||||||
|
const LegacyCallViewMock = LegacyCallView as unknown as jest.Mock;
|
||||||
|
beforeEach(() => {
|
||||||
|
LegacyCallViewMock.mockClear();
|
||||||
|
});
|
||||||
|
it("should remember sidebar state, defaulting to shown", async () => {
|
||||||
|
stubClient();
|
||||||
|
|
||||||
|
const callHandler = new LegacyCallHandler();
|
||||||
|
callHandler.start();
|
||||||
|
jest.spyOn(LegacyCallHandler, "instance", "get").mockImplementation(() => callHandler);
|
||||||
|
|
||||||
|
const call = new MatrixCall({
|
||||||
|
client: MatrixClientPeg.safeGet(),
|
||||||
|
roomId: "test-room",
|
||||||
|
});
|
||||||
|
DMRoomMap.setShared({
|
||||||
|
getUserIdForRoomId: jest.fn().mockReturnValue("test-user"),
|
||||||
|
} as unknown as DMRoomMap);
|
||||||
|
|
||||||
|
const room = mkStubRoom(call.roomId, "room", MatrixClientPeg.safeGet());
|
||||||
|
MatrixClientPeg.safeGet().getRoom = jest.fn().mockReturnValue(room);
|
||||||
|
const cli = MatrixClientPeg.safeGet();
|
||||||
|
cli.emit(CallEventHandlerEvent.Incoming, call);
|
||||||
|
|
||||||
|
const { rerender } = render(
|
||||||
|
<LegacyCallViewForRoom roomId={call.roomId} resizeNotifier={new ResizeNotifier()} />,
|
||||||
|
);
|
||||||
|
|
||||||
|
let props = LegacyCallViewMock.mock.lastCall![0];
|
||||||
|
expect(props.sidebarShown).toBeTruthy(); // Sidebar defaults to shown
|
||||||
|
|
||||||
|
props.setSidebarShown(false); // Hide the sidebar
|
||||||
|
|
||||||
|
rerender(<LegacyCallViewForRoom roomId={call.roomId} resizeNotifier={new ResizeNotifier()} />);
|
||||||
|
|
||||||
|
console.log(LegacyCallViewMock.mock);
|
||||||
|
|
||||||
|
props = LegacyCallViewMock.mock.lastCall![0];
|
||||||
|
expect(props.sidebarShown).toBeFalsy();
|
||||||
|
|
||||||
|
rerender(<div> </div>); // Destroy the LegacyCallViewForRoom and LegacyCallView
|
||||||
|
LegacyCallViewMock.mockClear(); // Drop stored LegacyCallView props
|
||||||
|
|
||||||
|
rerender(<LegacyCallViewForRoom roomId={call.roomId} resizeNotifier={new ResizeNotifier()} />);
|
||||||
|
|
||||||
|
props = LegacyCallViewMock.mock.lastCall![0];
|
||||||
|
expect(props.sidebarShown).toBeFalsy(); // Value was remembered
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
x
Reference in New Issue
Block a user