2015-09-18 01:23:38 +08:00
|
|
|
/*
|
2016-01-07 12:06:39 +08:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2018-06-15 22:12:32 +08:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2020-09-04 15:05:47 +08:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2015-09-18 01:23:38 +08:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Manages a list of all the currently active calls.
|
|
|
|
*
|
|
|
|
* This handler dispatches when voip calls are added/updated/removed from this list:
|
|
|
|
* {
|
|
|
|
* action: 'call_state'
|
|
|
|
* room_id: <room ID of the call>
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* To know the state of the call, this handler exposes a getter to
|
|
|
|
* obtain the call for a room:
|
|
|
|
* var call = CallHandler.getCall(roomId)
|
|
|
|
* var state = call.call_state; // ringing|ringback|connected|ended|busy|stop_ringback|stop_ringing
|
|
|
|
*
|
|
|
|
* This handler listens for and handles the following actions:
|
|
|
|
* {
|
|
|
|
* action: 'place_call',
|
|
|
|
* type: 'voice|video',
|
|
|
|
* room_id: <room that the place call button was pressed in>
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* action: 'incoming_call'
|
|
|
|
* call: MatrixCall
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* action: 'hangup'
|
|
|
|
* room_id: <room that the hangup button was pressed in>
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* {
|
|
|
|
* action: 'answer'
|
|
|
|
* room_id: <room that the answer button was pressed in>
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
2019-12-21 05:13:46 +08:00
|
|
|
import {MatrixClientPeg} from './MatrixClientPeg';
|
2017-06-13 03:15:14 +08:00
|
|
|
import PlatformPeg from './PlatformPeg';
|
|
|
|
import Modal from './Modal';
|
2017-05-25 18:39:08 +08:00
|
|
|
import { _t } from './languageHandler';
|
2017-06-13 03:15:14 +08:00
|
|
|
import Matrix from 'matrix-js-sdk';
|
2020-05-14 10:41:41 +08:00
|
|
|
import dis from './dispatcher/dispatcher';
|
2018-06-26 18:59:16 +08:00
|
|
|
import WidgetUtils from './utils/WidgetUtils';
|
2018-07-03 18:16:44 +08:00
|
|
|
import WidgetEchoStore from './stores/WidgetEchoStore';
|
2020-07-29 06:37:09 +08:00
|
|
|
import SettingsStore from './settings/SettingsStore';
|
2020-03-21 04:19:47 +08:00
|
|
|
import {generateHumanReadableId} from "./utils/NamingUtils";
|
2020-04-07 06:04:41 +08:00
|
|
|
import {Jitsi} from "./widgets/Jitsi";
|
2020-04-10 05:11:57 +08:00
|
|
|
import {WidgetType} from "./widgets/WidgetType";
|
2020-07-29 01:53:43 +08:00
|
|
|
import {SettingLevel} from "./settings/SettingLevel";
|
2020-09-04 15:05:47 +08:00
|
|
|
import {base32} from "rfc4648";
|
2015-09-18 01:23:38 +08:00
|
|
|
|
2020-09-10 21:06:13 +08:00
|
|
|
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
|
2020-09-11 19:20:32 +08:00
|
|
|
import ErrorDialog from "./components/views/dialogs/ErrorDialog";
|
2020-09-10 21:06:13 +08:00
|
|
|
|
2015-10-01 01:21:25 +08:00
|
|
|
global.mxCalls = {
|
2015-09-18 01:23:38 +08:00
|
|
|
//room_id: MatrixCall
|
|
|
|
};
|
2017-10-12 00:56:17 +08:00
|
|
|
const calls = global.mxCalls;
|
|
|
|
let ConferenceHandler = null;
|
2015-09-18 01:23:38 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
const audioPromises = {};
|
2016-08-31 23:38:37 +08:00
|
|
|
|
2015-09-18 01:23:38 +08:00
|
|
|
function play(audioId) {
|
|
|
|
// TODO: Attach an invisible element for this instead
|
|
|
|
// which listens?
|
2017-10-12 00:56:17 +08:00
|
|
|
const audio = document.getElementById(audioId);
|
2015-09-18 01:23:38 +08:00
|
|
|
if (audio) {
|
2019-11-22 01:00:35 +08:00
|
|
|
const playAudio = async () => {
|
|
|
|
try {
|
|
|
|
// This still causes the chrome debugger to break on promise rejection if
|
|
|
|
// the promise is rejected, even though we're catching the exception.
|
|
|
|
await audio.play();
|
|
|
|
} catch (e) {
|
|
|
|
// This is usually because the user hasn't interacted with the document,
|
|
|
|
// or chrome doesn't think so and is denying the request. Not sure what
|
|
|
|
// we can really do here...
|
2020-08-03 23:02:26 +08:00
|
|
|
// https://github.com/vector-im/element-web/issues/7657
|
2019-11-22 01:00:35 +08:00
|
|
|
console.log("Unable to play audio clip", e);
|
|
|
|
}
|
|
|
|
};
|
2016-08-31 23:38:37 +08:00
|
|
|
if (audioPromises[audioId]) {
|
|
|
|
audioPromises[audioId] = audioPromises[audioId].then(()=>{
|
|
|
|
audio.load();
|
2019-11-22 01:00:35 +08:00
|
|
|
return playAudio();
|
2016-08-31 23:38:37 +08:00
|
|
|
});
|
2017-10-12 00:56:17 +08:00
|
|
|
} else {
|
2019-11-22 01:00:35 +08:00
|
|
|
audioPromises[audioId] = playAudio();
|
2016-08-31 23:38:37 +08:00
|
|
|
}
|
2015-09-18 01:23:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function pause(audioId) {
|
|
|
|
// TODO: Attach an invisible element for this instead
|
|
|
|
// which listens?
|
2017-10-12 00:56:17 +08:00
|
|
|
const audio = document.getElementById(audioId);
|
2015-09-18 01:23:38 +08:00
|
|
|
if (audio) {
|
2016-08-31 23:38:37 +08:00
|
|
|
if (audioPromises[audioId]) {
|
|
|
|
audioPromises[audioId] = audioPromises[audioId].then(()=>audio.pause());
|
2017-10-12 00:56:17 +08:00
|
|
|
} else {
|
2016-08-31 23:38:37 +08:00
|
|
|
// pause doesn't actually return a promise, but might as well do this for symmetry with play();
|
|
|
|
audioPromises[audioId] = audio.pause();
|
|
|
|
}
|
2015-09-18 01:23:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setCallListeners(call) {
|
|
|
|
call.on("error", function(err) {
|
2019-08-14 22:06:06 +08:00
|
|
|
console.error("Call error:", err);
|
2020-05-28 23:59:27 +08:00
|
|
|
if (
|
|
|
|
MatrixClientPeg.get().getTurnServers().length === 0 &&
|
|
|
|
SettingsStore.getValue("fallbackICEServerAllowed") === null
|
|
|
|
) {
|
|
|
|
_showICEFallbackPrompt();
|
|
|
|
return;
|
2017-11-15 18:49:29 +08:00
|
|
|
}
|
2020-05-28 23:59:27 +08:00
|
|
|
|
|
|
|
Modal.createTrackedDialog('Call Failed', '', ErrorDialog, {
|
|
|
|
title: _t('Call Failed'),
|
|
|
|
description: err.message,
|
|
|
|
});
|
2017-02-23 00:12:37 +08:00
|
|
|
});
|
2015-09-18 01:23:38 +08:00
|
|
|
call.on("hangup", function() {
|
|
|
|
_setCallState(undefined, call.roomId, "ended");
|
|
|
|
});
|
|
|
|
// map web rtc states to dummy UI state
|
|
|
|
// ringing|ringback|connected|ended|busy|stop_ringback|stop_ringing
|
|
|
|
call.on("state", function(newState, oldState) {
|
|
|
|
if (newState === "ringing") {
|
|
|
|
_setCallState(call, call.roomId, "ringing");
|
|
|
|
pause("ringbackAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (newState === "invite_sent") {
|
2015-09-18 01:23:38 +08:00
|
|
|
_setCallState(call, call.roomId, "ringback");
|
|
|
|
play("ringbackAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (newState === "ended" && oldState === "connected") {
|
2015-09-30 23:50:46 +08:00
|
|
|
_setCallState(undefined, call.roomId, "ended");
|
2015-09-18 01:23:38 +08:00
|
|
|
pause("ringbackAudio");
|
|
|
|
play("callendAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (newState === "ended" && oldState === "invite_sent" &&
|
2015-09-18 01:23:38 +08:00
|
|
|
(call.hangupParty === "remote" ||
|
|
|
|
(call.hangupParty === "local" && call.hangupReason === "invite_timeout")
|
|
|
|
)) {
|
|
|
|
_setCallState(call, call.roomId, "busy");
|
|
|
|
pause("ringbackAudio");
|
|
|
|
play("busyAudio");
|
2017-07-28 00:19:18 +08:00
|
|
|
Modal.createTrackedDialog('Call Handler', 'Call Timeout', ErrorDialog, {
|
2017-05-23 22:16:31 +08:00
|
|
|
title: _t('Call Timeout'),
|
|
|
|
description: _t('The remote side failed to pick up') + '.',
|
2015-09-18 01:23:38 +08:00
|
|
|
});
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (oldState === "invite_sent") {
|
2015-09-18 01:23:38 +08:00
|
|
|
_setCallState(call, call.roomId, "stop_ringback");
|
|
|
|
pause("ringbackAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (oldState === "ringing") {
|
2015-09-18 01:23:38 +08:00
|
|
|
_setCallState(call, call.roomId, "stop_ringing");
|
|
|
|
pause("ringbackAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (newState === "connected") {
|
2015-09-18 01:23:38 +08:00
|
|
|
_setCallState(call, call.roomId, "connected");
|
|
|
|
pause("ringbackAudio");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function _setCallState(call, roomId, status) {
|
|
|
|
console.log(
|
2019-10-30 18:38:34 +08:00
|
|
|
`Call state in ${roomId} changed to ${status} (${call ? call.call_state : "-"})`,
|
2015-09-18 01:23:38 +08:00
|
|
|
);
|
|
|
|
calls[roomId] = call;
|
2015-12-17 10:49:09 +08:00
|
|
|
|
|
|
|
if (status === "ringing") {
|
2017-01-20 22:22:27 +08:00
|
|
|
play("ringAudio");
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (call && call.call_state === "ringing") {
|
2017-01-20 22:22:27 +08:00
|
|
|
pause("ringAudio");
|
2015-12-17 10:49:09 +08:00
|
|
|
}
|
|
|
|
|
2015-09-18 01:23:38 +08:00
|
|
|
if (call) {
|
|
|
|
call.call_state = status;
|
|
|
|
}
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'call_state',
|
2017-05-23 01:33:14 +08:00
|
|
|
room_id: roomId,
|
|
|
|
state: status,
|
2015-09-18 01:23:38 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-08-15 22:04:17 +08:00
|
|
|
function _showICEFallbackPrompt() {
|
2019-08-14 22:06:06 +08:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
const code = sub => <code>{sub}</code>;
|
|
|
|
Modal.createTrackedDialog('No TURN servers', '', QuestionDialog, {
|
2019-08-15 22:04:17 +08:00
|
|
|
title: _t("Call failed due to misconfigured server"),
|
2019-08-14 22:06:06 +08:00
|
|
|
description: <div>
|
2019-08-15 22:04:17 +08:00
|
|
|
<p>{_t(
|
|
|
|
"Please ask the administrator of your homeserver " +
|
|
|
|
"(<code>%(homeserverDomain)s</code>) to configure a TURN server in " +
|
|
|
|
"order for calls to work reliably.",
|
2019-08-14 22:06:06 +08:00
|
|
|
{ homeserverDomain: cli.getDomain() }, { code },
|
2019-08-15 22:04:17 +08:00
|
|
|
)}</p>
|
|
|
|
<p>{_t(
|
|
|
|
"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.",
|
2019-08-14 22:06:06 +08:00
|
|
|
null, { code },
|
|
|
|
)}</p>
|
|
|
|
</div>,
|
2019-08-15 22:04:17 +08:00
|
|
|
button: _t('Try using turn.matrix.org'),
|
|
|
|
cancelButton: _t('OK'),
|
2019-08-14 22:06:06 +08:00
|
|
|
onFinished: (allow) => {
|
|
|
|
SettingsStore.setValue("fallbackICEServerAllowed", null, SettingLevel.DEVICE, allow);
|
|
|
|
cli.setFallbackICEServerAllowed(allow);
|
|
|
|
},
|
|
|
|
}, null, true);
|
|
|
|
}
|
|
|
|
|
2015-10-01 01:21:25 +08:00
|
|
|
function _onAction(payload) {
|
2015-09-30 23:50:46 +08:00
|
|
|
function placeCall(newCall) {
|
|
|
|
_setCallListeners(newCall);
|
|
|
|
if (payload.type === 'voice') {
|
|
|
|
newCall.placeVoiceCall();
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (payload.type === 'video') {
|
2015-10-21 08:21:21 +08:00
|
|
|
newCall.placeVideoCall(
|
|
|
|
payload.remote_element,
|
2017-10-12 00:56:17 +08:00
|
|
|
payload.local_element,
|
2015-10-21 08:21:21 +08:00
|
|
|
);
|
2017-10-12 00:56:17 +08:00
|
|
|
} else if (payload.type === 'screensharing') {
|
2017-01-11 02:37:57 +08:00
|
|
|
const screenCapErrorString = PlatformPeg.get().screenCaptureErrorString();
|
|
|
|
if (screenCapErrorString) {
|
|
|
|
_setCallState(undefined, newCall.roomId, "ended");
|
|
|
|
console.log("Can't capture screen: " + screenCapErrorString);
|
2017-07-28 00:19:18 +08:00
|
|
|
Modal.createTrackedDialog('Call Handler', 'Unable to capture screen', ErrorDialog, {
|
2017-05-23 22:16:31 +08:00
|
|
|
title: _t('Unable to capture screen'),
|
|
|
|
description: screenCapErrorString,
|
2017-01-11 18:06:48 +08:00
|
|
|
});
|
2017-01-11 02:37:57 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-10-20 23:45:26 +08:00
|
|
|
newCall.placeScreenSharingCall(
|
2015-09-30 23:50:46 +08:00
|
|
|
payload.remote_element,
|
2017-10-12 00:56:17 +08:00
|
|
|
payload.local_element,
|
2015-09-30 23:50:46 +08:00
|
|
|
);
|
2017-10-12 00:56:17 +08:00
|
|
|
} else {
|
2015-09-30 23:50:46 +08:00
|
|
|
console.error("Unknown conf call type: %s", payload.type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 01:23:38 +08:00
|
|
|
switch (payload.action) {
|
|
|
|
case 'place_call':
|
2018-06-18 23:00:42 +08:00
|
|
|
{
|
2019-12-20 08:57:50 +08:00
|
|
|
if (callHandler.getAnyActiveCall()) {
|
2018-06-18 23:00:42 +08:00
|
|
|
Modal.createTrackedDialog('Call Handler', 'Existing Call', ErrorDialog, {
|
|
|
|
title: _t('Existing Call'),
|
|
|
|
description: _t('You are already in a call.'),
|
|
|
|
});
|
|
|
|
return; // don't allow >1 call to be placed.
|
|
|
|
}
|
2015-11-03 01:39:00 +08:00
|
|
|
|
2018-06-18 23:00:42 +08:00
|
|
|
// if the runtime env doesn't do VoIP, whine.
|
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
|
|
|
Modal.createTrackedDialog('Call Handler', 'VoIP is unsupported', ErrorDialog, {
|
|
|
|
title: _t('VoIP is unsupported'),
|
|
|
|
description: _t('You cannot place VoIP calls in this browser.'),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 01:39:00 +08:00
|
|
|
|
2018-06-18 23:00:42 +08:00
|
|
|
const room = MatrixClientPeg.get().getRoom(payload.room_id);
|
|
|
|
if (!room) {
|
|
|
|
console.error("Room %s does not exist.", payload.room_id);
|
|
|
|
return;
|
|
|
|
}
|
2015-09-30 23:50:46 +08:00
|
|
|
|
2018-06-18 23:00:42 +08:00
|
|
|
const members = room.getJoinedMembers();
|
|
|
|
if (members.length <= 1) {
|
|
|
|
Modal.createTrackedDialog('Call Handler', 'Cannot place call with self', ErrorDialog, {
|
|
|
|
description: _t('You cannot place a call with yourself.'),
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
} else if (members.length === 2) {
|
2019-11-26 09:14:03 +08:00
|
|
|
console.info("Place %s call in %s", payload.type, payload.room_id);
|
2018-06-18 23:00:42 +08:00
|
|
|
const call = Matrix.createNewMatrixCall(MatrixClientPeg.get(), payload.room_id);
|
|
|
|
placeCall(call);
|
|
|
|
} else { // > 2
|
|
|
|
dis.dispatch({
|
|
|
|
action: "place_conference_call",
|
|
|
|
room_id: payload.room_id,
|
|
|
|
type: payload.type,
|
|
|
|
remote_element: payload.remote_element,
|
|
|
|
local_element: payload.local_element,
|
|
|
|
});
|
|
|
|
}
|
2015-09-18 01:23:38 +08:00
|
|
|
}
|
2015-09-30 23:50:46 +08:00
|
|
|
break;
|
|
|
|
case 'place_conference_call':
|
2019-11-26 09:14:03 +08:00
|
|
|
console.info("Place conference call in %s", payload.room_id);
|
2018-07-25 02:06:19 +08:00
|
|
|
_startCallApp(payload.room_id, payload.type);
|
2015-09-18 01:23:38 +08:00
|
|
|
break;
|
|
|
|
case 'incoming_call':
|
2018-06-18 23:00:42 +08:00
|
|
|
{
|
2019-12-20 08:57:50 +08:00
|
|
|
if (callHandler.getAnyActiveCall()) {
|
2018-06-18 23:00:42 +08:00
|
|
|
// ignore multiple incoming calls. in future, we may want a line-1/line-2 setup.
|
|
|
|
// we avoid rejecting with "busy" in case the user wants to answer it on a different device.
|
|
|
|
// in future we could signal a "local busy" as a warning to the caller.
|
|
|
|
// see https://github.com/vector-im/vector-web/issues/1964
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 01:39:00 +08:00
|
|
|
|
2018-06-18 23:00:42 +08:00
|
|
|
// if the runtime env doesn't do VoIP, stop here.
|
|
|
|
if (!MatrixClientPeg.get().supportsVoip()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 01:39:00 +08:00
|
|
|
|
2018-06-18 23:00:42 +08:00
|
|
|
const call = payload.call;
|
|
|
|
_setCallListeners(call);
|
|
|
|
_setCallState(call, call.roomId, "ringing");
|
|
|
|
}
|
2015-09-18 01:23:38 +08:00
|
|
|
break;
|
|
|
|
case 'hangup':
|
|
|
|
if (!calls[payload.room_id]) {
|
|
|
|
return; // no call to hangup
|
|
|
|
}
|
|
|
|
calls[payload.room_id].hangup();
|
|
|
|
_setCallState(null, payload.room_id, "ended");
|
|
|
|
break;
|
|
|
|
case 'answer':
|
|
|
|
if (!calls[payload.room_id]) {
|
|
|
|
return; // no call to answer
|
|
|
|
}
|
|
|
|
calls[payload.room_id].answer();
|
|
|
|
_setCallState(calls[payload.room_id], payload.room_id, "connected");
|
|
|
|
dis.dispatch({
|
|
|
|
action: "view_room",
|
2017-10-12 00:56:17 +08:00
|
|
|
room_id: payload.room_id,
|
2015-09-18 01:23:38 +08:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2015-10-01 01:21:25 +08:00
|
|
|
}
|
2018-06-15 22:12:32 +08:00
|
|
|
|
2018-07-16 23:54:25 +08:00
|
|
|
async function _startCallApp(roomId, type) {
|
2018-06-15 22:12:32 +08:00
|
|
|
dis.dispatch({
|
|
|
|
action: 'appsDrawer',
|
|
|
|
show: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const room = MatrixClientPeg.get().getRoom(roomId);
|
2020-04-10 05:11:57 +08:00
|
|
|
const currentJitsiWidgets = WidgetUtils.getRoomWidgetsOfType(room, WidgetType.JITSI);
|
2018-07-03 18:16:44 +08:00
|
|
|
|
2020-04-10 05:11:57 +08:00
|
|
|
if (WidgetEchoStore.roomHasPendingWidgetsOfType(roomId, currentJitsiWidgets, WidgetType.JITSI)) {
|
2018-07-16 20:18:10 +08:00
|
|
|
Modal.createTrackedDialog('Call already in progress', '', ErrorDialog, {
|
2018-07-03 18:16:44 +08:00
|
|
|
title: _t('Call in Progress'),
|
|
|
|
description: _t('A call is currently being placed!'),
|
|
|
|
});
|
2018-06-15 22:12:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentJitsiWidgets.length > 0) {
|
|
|
|
console.warn(
|
|
|
|
"Refusing to start conference call widget in " + roomId +
|
|
|
|
" a conference call widget is already present",
|
|
|
|
);
|
2018-06-25 22:30:04 +08:00
|
|
|
|
2020-09-11 19:20:32 +08:00
|
|
|
if (WidgetUtils.canUserModifyWidgets(roomId)) {
|
|
|
|
Modal.createTrackedDialog('Already have Jitsi Widget', '', QuestionDialog, {
|
|
|
|
title: _t('End Call'),
|
|
|
|
description: _t('Remove the group call from the room?'),
|
|
|
|
button: _t('End Call'),
|
|
|
|
cancelButton: _t('Cancel'),
|
|
|
|
onFinished: (endCall) => {
|
|
|
|
if (endCall) {
|
|
|
|
WidgetUtils.setRoomWidget(roomId, currentJitsiWidgets[0].getContent()['id']);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Modal.createTrackedDialog('Already have Jitsi Widget', '', ErrorDialog, {
|
|
|
|
title: _t('Call in Progress'),
|
|
|
|
description: _t("You don't have permission to remove the call from the room"),
|
|
|
|
});
|
|
|
|
}
|
2018-06-15 22:12:32 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:04:41 +08:00
|
|
|
const jitsiDomain = Jitsi.getInstance().preferredDomain;
|
2020-09-04 15:05:47 +08:00
|
|
|
const jitsiAuth = await Jitsi.getInstance().getJitsiAuth();
|
|
|
|
let confId;
|
|
|
|
if (jitsiAuth === 'openidtoken-jwt') {
|
|
|
|
// Create conference ID from room ID
|
|
|
|
// For compatibility with Jitsi, use base32 without padding.
|
|
|
|
// More details here:
|
2020-09-08 00:22:40 +08:00
|
|
|
// https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
|
2020-09-04 15:05:47 +08:00
|
|
|
confId = base32.stringify(Buffer.from(roomId), { pad: false });
|
|
|
|
} else {
|
|
|
|
// Create a random human readable conference ID
|
|
|
|
confId = `JitsiConference${generateHumanReadableId()}`;
|
|
|
|
}
|
2020-03-19 05:50:05 +08:00
|
|
|
|
2020-09-04 17:42:46 +08:00
|
|
|
let widgetUrl = WidgetUtils.getLocalJitsiWrapperUrl({auth: jitsiAuth});
|
2020-03-24 00:17:45 +08:00
|
|
|
|
|
|
|
// TODO: Remove URL hacks when the mobile clients eventually support v2 widgets
|
|
|
|
const parsedUrl = new URL(widgetUrl);
|
|
|
|
parsedUrl.search = ''; // set to empty string to make the URL class use searchParams instead
|
|
|
|
parsedUrl.searchParams.set('confId', confId);
|
|
|
|
widgetUrl = parsedUrl.toString();
|
2018-06-15 22:12:32 +08:00
|
|
|
|
2020-03-19 05:50:05 +08:00
|
|
|
const widgetData = {
|
|
|
|
conferenceId: confId,
|
|
|
|
isAudioOnly: type === 'voice',
|
|
|
|
domain: jitsiDomain,
|
2020-09-04 15:20:58 +08:00
|
|
|
auth: jitsiAuth,
|
2020-03-19 05:50:05 +08:00
|
|
|
};
|
2018-06-25 22:30:04 +08:00
|
|
|
|
2018-06-15 22:12:32 +08:00
|
|
|
const widgetId = (
|
|
|
|
'jitsi_' +
|
|
|
|
MatrixClientPeg.get().credentials.userId +
|
|
|
|
'_' +
|
|
|
|
Date.now()
|
|
|
|
);
|
2018-06-25 22:30:04 +08:00
|
|
|
|
2020-04-10 05:11:57 +08:00
|
|
|
WidgetUtils.setRoomWidget(roomId, widgetId, WidgetType.JITSI, widgetUrl, 'Jitsi', widgetData).then(() => {
|
2018-06-25 22:30:04 +08:00
|
|
|
console.log('Jitsi widget added');
|
|
|
|
}).catch((e) => {
|
2018-07-16 22:41:03 +08:00
|
|
|
if (e.errcode === 'M_FORBIDDEN') {
|
|
|
|
Modal.createTrackedDialog('Call Failed', '', ErrorDialog, {
|
|
|
|
title: _t('Permission Required'),
|
|
|
|
description: _t("You do not have permission to start a conference call in this room"),
|
|
|
|
});
|
|
|
|
}
|
2018-06-25 22:30:04 +08:00
|
|
|
console.error(e);
|
|
|
|
});
|
2018-06-15 22:12:32 +08:00
|
|
|
}
|
|
|
|
|
2015-10-01 01:21:25 +08:00
|
|
|
// FIXME: Nasty way of making sure we only register
|
|
|
|
// with the dispatcher once
|
|
|
|
if (!global.mxCallHandler) {
|
|
|
|
dis.register(_onAction);
|
2019-11-21 23:55:30 +08:00
|
|
|
// add empty handlers for media actions, otherwise the media keys
|
|
|
|
// end up causing the audio elements with our ring/ringback etc
|
|
|
|
// audio clips in to play.
|
2019-11-22 00:11:42 +08:00
|
|
|
if (navigator.mediaSession) {
|
|
|
|
navigator.mediaSession.setActionHandler('play', function() {});
|
|
|
|
navigator.mediaSession.setActionHandler('pause', function() {});
|
|
|
|
navigator.mediaSession.setActionHandler('seekbackward', function() {});
|
|
|
|
navigator.mediaSession.setActionHandler('seekforward', function() {});
|
|
|
|
navigator.mediaSession.setActionHandler('previoustrack', function() {});
|
|
|
|
navigator.mediaSession.setActionHandler('nexttrack', function() {});
|
|
|
|
}
|
2015-10-01 01:21:25 +08:00
|
|
|
}
|
2015-09-30 23:50:46 +08:00
|
|
|
|
2017-10-12 00:56:17 +08:00
|
|
|
const callHandler = {
|
2015-09-30 23:50:46 +08:00
|
|
|
getCallForRoom: function(roomId) {
|
2019-12-20 08:57:50 +08:00
|
|
|
let call = callHandler.getCall(roomId);
|
2015-10-01 16:42:58 +08:00
|
|
|
if (call) return call;
|
|
|
|
|
2015-12-01 02:11:04 +08:00
|
|
|
if (ConferenceHandler) {
|
2015-10-01 16:42:58 +08:00
|
|
|
call = ConferenceHandler.getConferenceCallForRoom(roomId);
|
|
|
|
}
|
|
|
|
if (call) return call;
|
|
|
|
|
|
|
|
return null;
|
2015-09-30 23:50:46 +08:00
|
|
|
},
|
|
|
|
|
2015-09-18 01:23:38 +08:00
|
|
|
getCall: function(roomId) {
|
|
|
|
return calls[roomId] || null;
|
2015-09-30 23:50:46 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getAnyActiveCall: function() {
|
2017-10-12 00:56:17 +08:00
|
|
|
const roomsWithCalls = Object.keys(calls);
|
|
|
|
for (let i = 0; i < roomsWithCalls.length; i++) {
|
2015-09-30 23:50:46 +08:00
|
|
|
if (calls[roomsWithCalls[i]] &&
|
|
|
|
calls[roomsWithCalls[i]].call_state !== "ended") {
|
|
|
|
return calls[roomsWithCalls[i]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2015-12-01 02:11:04 +08:00
|
|
|
},
|
|
|
|
|
2018-07-25 02:06:19 +08:00
|
|
|
/**
|
|
|
|
* The conference handler is a module that deals with implementation-specific
|
2020-08-03 23:02:26 +08:00
|
|
|
* multi-party calling implementations. Element passes in its own which creates
|
2018-07-25 02:06:19 +08:00
|
|
|
* a one-to-one call with a freeswitch conference bridge. As of July 2018,
|
|
|
|
* the de-facto way of conference calling is a Jitsi widget, so this is
|
|
|
|
* deprecated. It reamins here for two reasons:
|
2020-08-03 23:02:26 +08:00
|
|
|
* 1. So Element still supports joining existing freeswitch conference calls
|
2018-07-25 02:06:19 +08:00
|
|
|
* (but doesn't support creating them). After a transition period, we can
|
|
|
|
* remove support for joining them too.
|
|
|
|
* 2. To hide the one-to-one rooms that old-style conferencing creates. This
|
2020-08-03 23:02:26 +08:00
|
|
|
* is much harder to remove: probably either we make Element leave & forget these
|
2018-07-25 02:06:19 +08:00
|
|
|
* rooms after we remove support for joining freeswitch conferences, or we
|
|
|
|
* accept that random rooms with cryptic users will suddently appear for
|
|
|
|
* anyone who's ever used conference calling, or we are stuck with this
|
|
|
|
* code forever.
|
2018-07-25 02:14:44 +08:00
|
|
|
*
|
|
|
|
* @param {object} confHandler The conference handler object
|
2018-07-25 02:06:19 +08:00
|
|
|
*/
|
2015-12-01 02:11:04 +08:00
|
|
|
setConferenceHandler: function(confHandler) {
|
|
|
|
ConferenceHandler = confHandler;
|
2016-03-05 10:30:18 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
getConferenceHandler: function() {
|
|
|
|
return ConferenceHandler;
|
2017-10-12 00:56:17 +08:00
|
|
|
},
|
2015-09-18 01:23:38 +08:00
|
|
|
};
|
2015-10-01 01:21:25 +08:00
|
|
|
// Only things in here which actually need to be global are the
|
|
|
|
// calls list (done separately) and making sure we only register
|
|
|
|
// with the dispatcher once (which uses this mechanism but checks
|
|
|
|
// separately). This could be tidied up.
|
|
|
|
if (global.mxCallHandler === undefined) {
|
|
|
|
global.mxCallHandler = callHandler;
|
|
|
|
}
|
|
|
|
|
2019-12-20 08:45:24 +08:00
|
|
|
export default global.mxCallHandler;
|