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

Commit 5534206

Browse files
authored
Merge pull request #5223 from matrix-org/travis/ft-sep1620/04-jitsi-hangup
Make the hangup button do things for conference calls
2 parents 36882b8 + bfa269a commit 5534206

File tree

7 files changed

+144
-42
lines changed

7 files changed

+144
-42
lines changed

res/css/views/rooms/_MessageComposer.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ limitations under the License.
217217
}
218218
}
219219

220-
&.mx_MessageComposer_hangup::before {
220+
&.mx_MessageComposer_hangup:not(.mx_AccessibleButton_disabled)::before {
221221
background-color: $warning-color;
222222
}
223223
}

src/CallHandler.tsx

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ import {base32} from "rfc4648";
7474

7575
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
7676
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
77+
import WidgetStore from "./stores/WidgetStore";
78+
import ActiveWidgetStore from "./stores/ActiveWidgetStore";
7779

7880
// until we ts-ify the js-sdk voip code
7981
type Call = any;
@@ -351,6 +353,14 @@ export default class CallHandler {
351353
console.info("Place conference call in %s", payload.room_id);
352354
this.startCallApp(payload.room_id, payload.type);
353355
break;
356+
case 'end_conference':
357+
console.info("Terminating conference call in %s", payload.room_id);
358+
this.terminateCallApp(payload.room_id);
359+
break;
360+
case 'hangup_conference':
361+
console.info("Leaving conference call in %s", payload.room_id);
362+
this.hangupCallApp(payload.room_id);
363+
break;
354364
case 'incoming_call':
355365
{
356366
if (this.getAnyActiveCall()) {
@@ -398,44 +408,19 @@ export default class CallHandler {
398408
show: true,
399409
});
400410

411+
// prevent double clicking the call button
401412
const room = MatrixClientPeg.get().getRoom(roomId);
402413
const currentJitsiWidgets = WidgetUtils.getRoomWidgetsOfType(room, WidgetType.JITSI);
403-
404-
if (WidgetEchoStore.roomHasPendingWidgetsOfType(roomId, currentJitsiWidgets, WidgetType.JITSI)) {
414+
const hasJitsi = currentJitsiWidgets.length > 0
415+
|| WidgetEchoStore.roomHasPendingWidgetsOfType(roomId, currentJitsiWidgets, WidgetType.JITSI);
416+
if (hasJitsi) {
405417
Modal.createTrackedDialog('Call already in progress', '', ErrorDialog, {
406418
title: _t('Call in Progress'),
407419
description: _t('A call is currently being placed!'),
408420
});
409421
return;
410422
}
411423

412-
if (currentJitsiWidgets.length > 0) {
413-
console.warn(
414-
"Refusing to start conference call widget in " + roomId +
415-
" a conference call widget is already present",
416-
);
417-
418-
if (WidgetUtils.canUserModifyWidgets(roomId)) {
419-
Modal.createTrackedDialog('Already have Jitsi Widget', '', QuestionDialog, {
420-
title: _t('End Call'),
421-
description: _t('Remove the group call from the room?'),
422-
button: _t('End Call'),
423-
cancelButton: _t('Cancel'),
424-
onFinished: (endCall) => {
425-
if (endCall) {
426-
WidgetUtils.setRoomWidget(roomId, currentJitsiWidgets[0].getContent()['id']);
427-
}
428-
},
429-
});
430-
} else {
431-
Modal.createTrackedDialog('Already have Jitsi Widget', '', ErrorDialog, {
432-
title: _t('Call in Progress'),
433-
description: _t("You don't have permission to remove the call from the room"),
434-
});
435-
}
436-
return;
437-
}
438-
439424
const jitsiDomain = Jitsi.getInstance().preferredDomain;
440425
const jitsiAuth = await Jitsi.getInstance().getJitsiAuth();
441426
let confId;
@@ -484,4 +469,38 @@ export default class CallHandler {
484469
console.error(e);
485470
});
486471
}
472+
473+
private terminateCallApp(roomId: string) {
474+
Modal.createTrackedDialog('Confirm Jitsi Terminate', '', QuestionDialog, {
475+
hasCancelButton: true,
476+
title: _t("End conference"),
477+
description: _t("This will end the conference for everyone. Continue?"),
478+
button: _t("End conference"),
479+
onFinished: (proceed) => {
480+
if (!proceed) return;
481+
482+
// We'll just obliterate them all. There should only ever be one, but might as well
483+
// be safe.
484+
const roomInfo = WidgetStore.instance.getRoom(roomId);
485+
const jitsiWidgets = roomInfo.widgets.filter(w => WidgetType.JITSI.matches(w.type));
486+
jitsiWidgets.forEach(w => {
487+
// setting invalid content removes it
488+
WidgetUtils.setRoomWidget(roomId, w.id);
489+
});
490+
},
491+
});
492+
}
493+
494+
private hangupCallApp(roomId: string) {
495+
const roomInfo = WidgetStore.instance.getRoom(roomId);
496+
if (!roomInfo) return; // "should never happen" clauses go here
497+
498+
const jitsiWidgets = roomInfo.widgets.filter(w => WidgetType.JITSI.matches(w.type));
499+
jitsiWidgets.forEach(w => {
500+
const messaging = ActiveWidgetStore.getWidgetMessaging(w.id);
501+
if (!messaging) return; // more "should never happen" words
502+
503+
messaging.hangup();
504+
});
505+
}
487506
}

src/WidgetMessaging.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ export default class WidgetMessaging {
107107
});
108108
}
109109

110+
/**
111+
* Tells the widget to hang up on its call.
112+
* @returns {Promise<*>} Resolves when the widget has acknowledged the message.
113+
*/
114+
hangup() {
115+
return this.messageToWidget({
116+
api: OUTBOUND_API_NAME,
117+
action: KnownWidgetActions.Hangup,
118+
});
119+
}
120+
110121
/**
111122
* Request a screenshot from a widget
112123
* @return {Promise} To be resolved with screenshot data when it has been generated

src/components/views/rooms/MessageComposer.js

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
Copyright 2015, 2016 OpenMarket Ltd
33
Copyright 2017, 2018 New Vector Ltd
4+
Copyright 2020 The Matrix.org Foundation C.I.C.
45
56
Licensed under the Apache License, Version 2.0 (the "License");
67
you may not use this file except in compliance with the License.
@@ -32,6 +33,10 @@ import {aboveLeftOf, ContextMenu, ContextMenuTooltipButton, useContextMenu} from
3233
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
3334
import ReplyPreview from "./ReplyPreview";
3435
import {UIFeature} from "../../../settings/UIFeature";
36+
import WidgetStore from "../../../stores/WidgetStore";
37+
import WidgetUtils from "../../../utils/WidgetUtils";
38+
import {UPDATE_EVENT} from "../../../stores/AsyncStore";
39+
import ActiveWidgetStore from "../../../stores/ActiveWidgetStore";
3540

3641
function ComposerAvatar(props) {
3742
const MemberStatusMessageAvatar = sdk.getComponent('avatars.MemberStatusMessageAvatar');
@@ -85,8 +90,15 @@ VideoCallButton.propTypes = {
8590
};
8691

8792
function HangupButton(props) {
88-
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
8993
const onHangupClick = () => {
94+
if (props.isConference) {
95+
dis.dispatch({
96+
action: props.canEndConference ? 'end_conference' : 'hangup_conference',
97+
room_id: props.roomId,
98+
});
99+
return;
100+
}
101+
90102
const call = CallHandler.sharedInstance().getCallForRoom(props.roomId);
91103
if (!call) {
92104
return;
@@ -98,14 +110,28 @@ function HangupButton(props) {
98110
room_id: call.roomId,
99111
});
100112
};
101-
return (<AccessibleButton className="mx_MessageComposer_button mx_MessageComposer_hangup"
113+
114+
let tooltip = _t("Hangup");
115+
if (props.isConference && props.canEndConference) {
116+
tooltip = _t("End conference");
117+
}
118+
119+
const canLeaveConference = !props.isConference ? true : props.isInConference;
120+
return (
121+
<AccessibleTooltipButton
122+
className="mx_MessageComposer_button mx_MessageComposer_hangup"
102123
onClick={onHangupClick}
103-
title={_t('Hangup')}
104-
/>);
124+
title={tooltip}
125+
disabled={!canLeaveConference}
126+
/>
127+
);
105128
}
106129

107130
HangupButton.propTypes = {
108131
roomId: PropTypes.string.isRequired,
132+
isConference: PropTypes.bool.isRequired,
133+
canEndConference: PropTypes.bool,
134+
isInConference: PropTypes.bool,
109135
};
110136

111137
const EmojiButton = ({addEmoji}) => {
@@ -226,12 +252,17 @@ export default class MessageComposer extends React.Component {
226252
this._onRoomViewStoreUpdate = this._onRoomViewStoreUpdate.bind(this);
227253
this._onTombstoneClick = this._onTombstoneClick.bind(this);
228254
this.renderPlaceholderText = this.renderPlaceholderText.bind(this);
255+
WidgetStore.instance.on(UPDATE_EVENT, this._onWidgetUpdate);
256+
ActiveWidgetStore.on('update', this._onActiveWidgetUpdate);
229257
this._dispatcherRef = null;
258+
230259
this.state = {
231260
isQuoting: Boolean(RoomViewStore.getQuotingEvent()),
232261
tombstone: this._getRoomTombstone(),
233262
canSendMessages: this.props.room.maySendMessage(),
234263
showCallButtons: SettingsStore.getValue("showCallButtonsInComposer"),
264+
hasConference: WidgetStore.instance.doesRoomHaveConference(this.props.room),
265+
joinedConference: WidgetStore.instance.isJoinedToConferenceIn(this.props.room),
235266
};
236267
}
237268

@@ -247,6 +278,14 @@ export default class MessageComposer extends React.Component {
247278
}
248279
};
249280

281+
_onWidgetUpdate = () => {
282+
this.setState({hasConference: WidgetStore.instance.doesRoomHaveConference(this.props.room)});
283+
};
284+
285+
_onActiveWidgetUpdate = () => {
286+
this.setState({joinedConference: WidgetStore.instance.isJoinedToConferenceIn(this.props.room)});
287+
};
288+
250289
componentDidMount() {
251290
this.dispatcherRef = dis.register(this.onAction);
252291
MatrixClientPeg.get().on("RoomState.events", this._onRoomStateEvents);
@@ -277,6 +316,8 @@ export default class MessageComposer extends React.Component {
277316
if (this._roomStoreToken) {
278317
this._roomStoreToken.remove();
279318
}
319+
WidgetStore.instance.removeListener(UPDATE_EVENT, this._onWidgetUpdate);
320+
ActiveWidgetStore.removeListener('update', this._onActiveWidgetUpdate);
280321
dis.unregister(this.dispatcherRef);
281322
}
282323

@@ -392,9 +433,19 @@ export default class MessageComposer extends React.Component {
392433
}
393434

394435
if (this.state.showCallButtons) {
395-
if (callInProgress) {
436+
if (this.state.hasConference) {
437+
const canEndConf = WidgetUtils.canUserModifyWidgets(this.props.room.roomId);
438+
controls.push(
439+
<HangupButton
440+
roomId={this.props.room.roomId}
441+
isConference={true}
442+
canEndConference={canEndConf}
443+
isInConference={this.state.joinedConference}
444+
/>,
445+
);
446+
} else if (callInProgress) {
396447
controls.push(
397-
<HangupButton key="controls_hangup" roomId={this.props.room.roomId} />,
448+
<HangupButton key="controls_hangup" roomId={this.props.room.roomId} isConference={false} />,
398449
);
399450
} else {
400451
controls.push(

src/i18n/strings/en_EN.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@
5050
"You cannot place a call with yourself.": "You cannot place a call with yourself.",
5151
"Call in Progress": "Call in Progress",
5252
"A call is currently being placed!": "A call is currently being placed!",
53-
"End Call": "End Call",
54-
"Remove the group call from the room?": "Remove the group call from the room?",
55-
"Cancel": "Cancel",
56-
"You don't have permission to remove the call from the room": "You don't have permission to remove the call from the room",
5753
"Permission Required": "Permission Required",
5854
"You do not have permission to start a conference call in this room": "You do not have permission to start a conference call in this room",
55+
"End conference": "End conference",
56+
"This will end the conference for everyone. Continue?": "This will end the conference for everyone. Continue?",
5957
"Replying With Files": "Replying With Files",
6058
"At this time it is not possible to reply with a file. Would you like to upload this file without replying?": "At this time it is not possible to reply with a file. Would you like to upload this file without replying?",
6159
"Continue": "Continue",
@@ -143,6 +141,7 @@
143141
"Cancel entering passphrase?": "Cancel entering passphrase?",
144142
"Are you sure you want to cancel entering passphrase?": "Are you sure you want to cancel entering passphrase?",
145143
"Go Back": "Go Back",
144+
"Cancel": "Cancel",
146145
"Setting up keys": "Setting up keys",
147146
"Messages": "Messages",
148147
"Actions": "Actions",

src/stores/WidgetStore.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { AsyncStoreWithClient } from "./AsyncStoreWithClient";
2222
import defaultDispatcher from "../dispatcher/dispatcher";
2323
import SettingsStore from "../settings/SettingsStore";
2424
import WidgetEchoStore from "../stores/WidgetEchoStore";
25+
import ActiveWidgetStore from "../stores/ActiveWidgetStore";
2526
import WidgetUtils from "../utils/WidgetUtils";
2627
import {SettingLevel} from "../settings/SettingLevel";
2728
import {WidgetType} from "../widgets/WidgetType";
@@ -207,6 +208,24 @@ export default class WidgetStore extends AsyncStoreWithClient<IState> {
207208
}
208209
return roomInfo.widgets;
209210
}
211+
212+
public doesRoomHaveConference(room: Room): boolean {
213+
const roomInfo = this.getRoom(room.roomId);
214+
if (!roomInfo) return false;
215+
216+
const currentWidgets = roomInfo.widgets.filter(w => WidgetType.JITSI.matches(w.type));
217+
const hasPendingWidgets = WidgetEchoStore.roomHasPendingWidgetsOfType(room.roomId, [], WidgetType.JITSI);
218+
return currentWidgets.length > 0 || hasPendingWidgets;
219+
}
220+
221+
public isJoinedToConferenceIn(room: Room): boolean {
222+
const roomInfo = this.getRoom(room.roomId);
223+
if (!roomInfo) return false;
224+
225+
// A persistent conference widget indicates that we're participating
226+
const widgets = roomInfo.widgets.filter(w => WidgetType.JITSI.matches(w.type));
227+
return widgets.some(w => ActiveWidgetStore.getWidgetPersistence(w.id));
228+
}
210229
}
211230

212231
window.mxWidgetStore = WidgetStore.instance;

src/widgets/WidgetApi.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export enum KnownWidgetActions {
3939
SetAlwaysOnScreen = "set_always_on_screen",
4040
ClientReady = "im.vector.ready",
4141
Terminate = "im.vector.terminate",
42+
Hangup = "im.vector.hangup",
4243
}
4344

4445
export type WidgetAction = KnownWidgetActions | string;
@@ -119,13 +120,15 @@ export class WidgetApi extends EventEmitter {
119120

120121
// Automatically acknowledge so we can move on
121122
this.replyToRequest(<ToWidgetRequest>payload, {});
122-
} else if (payload.action === KnownWidgetActions.Terminate) {
123+
} else if (payload.action === KnownWidgetActions.Terminate
124+
|| payload.action === KnownWidgetActions.Hangup) {
123125
// Finalization needs to be async, so postpone with a promise
124126
let finalizePromise = Promise.resolve();
125127
const wait = (promise) => {
126128
finalizePromise = finalizePromise.then(() => promise);
127129
};
128-
this.emit('terminate', wait);
130+
const emitName = payload.action === KnownWidgetActions.Terminate ? 'terminate' : 'hangup';
131+
this.emit(emitName, wait);
129132
Promise.resolve(finalizePromise).then(() => {
130133
// Acknowledge that we're shut down now
131134
this.replyToRequest(<ToWidgetRequest>payload, {});

0 commit comments

Comments
 (0)