Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Maximised widgets always force a call to be shown in PIP mode #7163

Merged
merged 6 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions src/CallHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,16 @@ export default class CallHandler extends EventEmitter {
return callsNotInThatRoom;
}

getAllActiveCallsForPip(roomId) {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
toger5 marked this conversation as resolved.
Show resolved Hide resolved
const room = MatrixClientPeg.get().getRoom(roomId);
if (WidgetLayoutStore.instance.hasMaximisedWidget(room)) {
// This checks if there is space for the call view in the aux panel
// If there is no space any call should be displayed in PiP
return this.getAllActiveCalls();
}
return this.getAllActiveCallsNotInRoom(roomId);
}

getTransfereeForCallId(callId: string): MatrixCall {
return this.transferees[callId];
}
Expand Down
48 changes: 31 additions & 17 deletions src/components/views/voip/CallPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { EventSubscription } from 'fbemitter';
import PictureInPictureDragger from './PictureInPictureDragger';

import { logger } from "matrix-js-sdk/src/logger";
import { WidgetLayoutStore } from '../../../stores/widgets/WidgetLayoutStore';

const SHOW_CALL_IN_STATES = [
CallState.Connected,
Expand Down Expand Up @@ -59,7 +60,9 @@ interface IState {
// (which should be a single element) of other calls.
// The primary will be the one not on hold, or an arbitrary one
// if they're all on hold)
function getPrimarySecondaryCalls(calls: MatrixCall[]): [MatrixCall, MatrixCall[]] {
function getPrimarySecondaryCallsForPip(roomId): [MatrixCall, MatrixCall[]] {
toger5 marked this conversation as resolved.
Show resolved Hide resolved
const calls = CallHandler.sharedInstance().getAllActiveCallsForPip(roomId);

let primary: MatrixCall = null;
let secondaries: MatrixCall[] = [];

Expand Down Expand Up @@ -101,9 +104,7 @@ export default class CallPreview extends React.Component<IProps, IState> {

const roomId = RoomViewStore.getRoomId();

const [primaryCall, secondaryCalls] = getPrimarySecondaryCalls(
CallHandler.sharedInstance().getAllActiveCallsNotInRoom(roomId),
);
const [primaryCall, secondaryCalls] = getPrimarySecondaryCallsForPip(roomId);

this.state = {
roomId,
Expand All @@ -117,6 +118,10 @@ export default class CallPreview extends React.Component<IProps, IState> {
this.roomStoreToken = RoomViewStore.addListener(this.onRoomViewStoreUpdate);
this.dispatcherRef = dis.register(this.onAction);
MatrixClientPeg.get().on(CallEvent.RemoteHoldUnhold, this.onCallRemoteHold);
const room = MatrixClientPeg.get()?.getRoom(this.state.roomId);
if (room) {
WidgetLayoutStore.instance.on(WidgetLayoutStore.emissionForRoom(room), this.updateCalls);
}
}

public componentWillUnmount() {
Expand All @@ -127,18 +132,29 @@ export default class CallPreview extends React.Component<IProps, IState> {
}
dis.unregister(this.dispatcherRef);
SettingsStore.unwatchSetting(this.settingsWatcherRef);
const room = MatrixClientPeg.get().getRoom(this.state.roomId);
WidgetLayoutStore.instance.off(WidgetLayoutStore.emissionForRoom(room), this.updateCalls);
}

private onRoomViewStoreUpdate = () => {
if (RoomViewStore.getRoomId() === this.state.roomId) return;

const roomId = RoomViewStore.getRoomId();
const [primaryCall, secondaryCalls] = getPrimarySecondaryCalls(
CallHandler.sharedInstance().getAllActiveCallsNotInRoom(roomId),
);
const newRoomId = RoomViewStore.getRoomId();
const oldRoomId = this.state.roomId;
if (newRoomId === oldRoomId) return;
// The WidgetLayoutStore observer always tracks the currently viewed Room,
// so we don't end up with multiple observers and know what observer to remove on unmount
const oldRoom = MatrixClientPeg.get()?.getRoom(oldRoomId);
if (oldRoom) {
WidgetLayoutStore.instance.off(WidgetLayoutStore.emissionForRoom(oldRoom), this.updateCalls);
}
const newRoom = MatrixClientPeg.get()?.getRoom(newRoomId);
if (newRoom) {
WidgetLayoutStore.instance.on(WidgetLayoutStore.emissionForRoom(newRoom), this.updateCalls);
}
if (!newRoomId) return;

const [primaryCall, secondaryCalls] = getPrimarySecondaryCallsForPip(newRoomId);
this.setState({
roomId,
roomId: newRoomId,
primaryCall: primaryCall,
secondaryCall: secondaryCalls[0],
});
Expand All @@ -157,9 +173,8 @@ export default class CallPreview extends React.Component<IProps, IState> {
};

private updateCalls = () => {
const [primaryCall, secondaryCalls] = getPrimarySecondaryCalls(
CallHandler.sharedInstance().getAllActiveCallsNotInRoom(this.state.roomId),
);
if (!this.state.roomId) return;
const [primaryCall, secondaryCalls] = getPrimarySecondaryCallsForPip(this.state.roomId);

this.setState({
primaryCall: primaryCall,
Expand All @@ -168,9 +183,8 @@ export default class CallPreview extends React.Component<IProps, IState> {
};

private onCallRemoteHold = () => {
const [primaryCall, secondaryCalls] = getPrimarySecondaryCalls(
CallHandler.sharedInstance().getAllActiveCallsNotInRoom(this.state.roomId),
);
if (!this.state.roomId) return;
const [primaryCall, secondaryCalls] = getPrimarySecondaryCallsForPip(this.state.roomId);

this.setState({
primaryCall: primaryCall,
Expand Down