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

Commit b10f7a4

Browse files
authored
Merge pull request #5324 from matrix-org/dbkr/hang_up_your_hangups
Support rejecting calls
2 parents d5e9d53 + 4a26199 commit b10f7a4

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

src/CallHandler.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,24 @@ export default class CallHandler {
238238
(call.hangupParty === CallParty.Local && call.hangupReason === CallErrorCode.InviteTimeout)
239239
)) {
240240
this.play(AudioID.Busy);
241-
Modal.createTrackedDialog('Call Handler', 'Call Timeout', ErrorDialog, {
242-
title: _t('Call Timeout'),
243-
description: _t('The remote side failed to pick up') + '.',
241+
let title;
242+
let description;
243+
if (call.hangupReason === CallErrorCode.UserHangup) {
244+
title = _t("Call Declined");
245+
description = _t("The other party declined the call.");
246+
} else if (call.hangupReason === CallErrorCode.InviteTimeout) {
247+
title = _t("Call Failed");
248+
// XXX: full stop appended as some relic here, but these
249+
// strings need proper input from design anyway, so let's
250+
// not change this string until we have a proper one.
251+
description = _t('The remote side failed to pick up') + '.';
252+
} else {
253+
title = _t("Call Failed");
254+
description = _t("The call could not be established");
255+
}
256+
257+
Modal.createTrackedDialog('Call Handler', 'Call Failed', ErrorDialog, {
258+
title, description,
244259
});
245260
} else {
246261
this.play(AudioID.CallEnd);
@@ -422,10 +437,15 @@ export default class CallHandler {
422437
}
423438
break;
424439
case 'hangup':
440+
case 'reject':
425441
if (!this.calls.get(payload.room_id)) {
426442
return; // no call to hangup
427443
}
428-
this.calls.get(payload.room_id).hangup(CallErrorCode.UserHangup, false)
444+
if (payload.action === 'reject') {
445+
this.calls.get(payload.room_id).reject();
446+
} else {
447+
this.calls.get(payload.room_id).hangup(CallErrorCode.UserHangup, false);
448+
}
429449
this.removeCallForRoom(payload.room_id);
430450
break;
431451
case 'answer':

src/TextForEvent.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,27 @@ function textForCallHangupEvent(event) {
300300
reason = _t('(not supported by this browser)');
301301
} else if (eventContent.reason) {
302302
if (eventContent.reason === "ice_failed") {
303+
// We couldn't establish a connection at all
303304
reason = _t('(could not connect media)');
305+
} else if (eventContent.reason === "ice_timeout") {
306+
// We established a connection but it died
307+
reason = _t('(connection failed)');
308+
} else if (eventContent.reason === "user_media_failed") {
309+
// The other side couldn't open capture devices
310+
reason = _t("(their device couldn't start the camera / microphone)");
311+
} else if (eventContent.reason === "unknown_error") {
312+
// An error code the other side doesn't have a way to express
313+
// (as opposed to an error code they gave but we don't know about,
314+
// in which case we show the error code)
315+
reason = _t("(an error occurred)");
304316
} else if (eventContent.reason === "invite_timeout") {
305317
reason = _t('(no answer)');
306-
} else if (eventContent.reason === "user hangup") {
318+
} else if (eventContent.reason === "user hangup" || eventContent.reason === "user_hangup") {
307319
// workaround for https://github.com/vector-im/element-web/issues/5178
308320
// it seems Android randomly sets a reason of "user hangup" which is
309321
// interpreted as an error code :(
310322
// https://github.com/vector-im/riot-android/issues/2623
323+
// Also the correct hangup code as of VoIP v1 (with underscore)
311324
reason = '';
312325
} else {
313326
reason = _t('(unknown failure: %(reason)s)', {reason: eventContent.reason});
@@ -316,6 +329,11 @@ function textForCallHangupEvent(event) {
316329
return _t('%(senderName)s ended the call.', {senderName}) + ' ' + reason;
317330
}
318331

332+
function textForCallRejectEvent(event) {
333+
const senderName = event.sender ? event.sender.name : _t('Someone');
334+
return _t('%(senderName)s declined the call.', {senderName});
335+
}
336+
319337
function textForCallInviteEvent(event) {
320338
const senderName = event.sender ? event.sender.name : _t('Someone');
321339
// FIXME: Find a better way to determine this from the event?
@@ -545,6 +563,7 @@ const handlers = {
545563
'm.call.invite': textForCallInviteEvent,
546564
'm.call.answer': textForCallAnswerEvent,
547565
'm.call.hangup': textForCallHangupEvent,
566+
'm.call.reject': textForCallRejectEvent,
548567
};
549568

550569
const stateHandlers = {

src/components/views/rooms/EventTile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const eventTileTypes = {
4646
'm.call.invite': 'messages.TextualEvent',
4747
'm.call.answer': 'messages.TextualEvent',
4848
'm.call.hangup': 'messages.TextualEvent',
49+
'm.call.reject': 'messages.TextualEvent',
4950
};
5051

5152
const stateEventTileTypes = {

src/components/views/rooms/MessageComposer.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import WidgetUtils from "../../../utils/WidgetUtils";
3838
import {UPDATE_EVENT} from "../../../stores/AsyncStore";
3939
import ActiveWidgetStore from "../../../stores/ActiveWidgetStore";
4040
import { PlaceCallType } from "../../../CallHandler";
41+
import { CallState } from 'matrix-js-sdk/src/webrtc/call';
4142

4243
function ComposerAvatar(props) {
4344
const MemberStatusMessageAvatar = sdk.getComponent('avatars.MemberStatusMessageAvatar');
@@ -104,8 +105,11 @@ function HangupButton(props) {
104105
if (!call) {
105106
return;
106107
}
108+
109+
const action = call.state === CallState.Ringing ? 'reject' : 'hangup';
110+
107111
dis.dispatch({
108-
action: 'hangup',
112+
action,
109113
// hangup the call for this room, which may not be the room in props
110114
// (e.g. conferences which will hangup the 1:1 room instead)
111115
room_id: call.roomId,

src/components/views/voip/IncomingCallBox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export default class IncomingCallBox extends React.Component<IProps, IState> {
7878
private onRejectClick: React.MouseEventHandler = (e) => {
7979
e.stopPropagation();
8080
dis.dispatch({
81-
action: 'hangup',
81+
action: 'reject',
8282
room_id: this.state.incomingCall.roomId,
8383
});
8484
};

src/i18n/strings/en_EN.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@
3535
"Unable to load! Check your network connectivity and try again.": "Unable to load! Check your network connectivity and try again.",
3636
"Dismiss": "Dismiss",
3737
"Call Failed": "Call Failed",
38-
"Call Timeout": "Call Timeout",
38+
"Call Declined": "Call Declined",
39+
"The other party declined the call.": "The other party declined the call.",
3940
"The remote side failed to pick up": "The remote side failed to pick up",
41+
"The call could not be established": "The call could not be established",
4042
"Call failed due to misconfigured server": "Call failed due to misconfigured server",
4143
"Please ask the administrator of your homeserver (<code>%(homeserverDomain)s</code>) to configure a TURN server in order for calls to work reliably.": "Please ask the administrator of your homeserver (<code>%(homeserverDomain)s</code>) to configure a TURN server in order for calls to work reliably.",
4244
"Alternatively, you can try to use the public server at <code>turn.matrix.org</code>, but this will not be as reliable, and it will share your IP address with that server. You can also manage this in Settings.": "Alternatively, you can try to use the public server at <code>turn.matrix.org</code>, but this will not be as reliable, and it will share your IP address with that server. You can also manage this in Settings.",
@@ -259,9 +261,13 @@
259261
"(not supported by this browser)": "(not supported by this browser)",
260262
"%(senderName)s answered the call.": "%(senderName)s answered the call.",
261263
"(could not connect media)": "(could not connect media)",
264+
"(connection failed)": "(connection failed)",
265+
"(their device couldn't start the camera / microphone)": "(their device couldn't start the camera / microphone)",
266+
"(an error occurred)": "(an error occurred)",
262267
"(no answer)": "(no answer)",
263268
"(unknown failure: %(reason)s)": "(unknown failure: %(reason)s)",
264269
"%(senderName)s ended the call.": "%(senderName)s ended the call.",
270+
"%(senderName)s declined the call.": "%(senderName)s declined the call.",
265271
"%(senderName)s placed a voice call.": "%(senderName)s placed a voice call.",
266272
"%(senderName)s placed a voice call. (not supported by this browser)": "%(senderName)s placed a voice call. (not supported by this browser)",
267273
"%(senderName)s placed a video call.": "%(senderName)s placed a video call.",

0 commit comments

Comments
 (0)