/* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017, 2018 New Vector Ltd Copyright 2019, 2020 The Matrix.org Foundation C.I.C. 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: * } * * 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: * } * * { * action: 'incoming_call' * call: MatrixCall * } * * { * action: 'hangup' * room_id: * } * * { * action: 'answer' * room_id: * } */ import React from 'react'; import {MatrixClientPeg} from './MatrixClientPeg'; import PlatformPeg from './PlatformPeg'; import Modal from './Modal'; import { _t } from './languageHandler'; import { createNewMatrixCall } from 'matrix-js-sdk/src/webrtc/call'; import dis from './dispatcher/dispatcher'; import WidgetUtils from './utils/WidgetUtils'; import WidgetEchoStore from './stores/WidgetEchoStore'; import SettingsStore from './settings/SettingsStore'; import {generateHumanReadableId} from "./utils/NamingUtils"; import {Jitsi} from "./widgets/Jitsi"; import {WidgetType} from "./widgets/WidgetType"; import {SettingLevel} from "./settings/SettingLevel"; import { ActionPayload } from "./dispatcher/payloads"; import {base32} from "rfc4648"; import QuestionDialog from "./components/views/dialogs/QuestionDialog"; import ErrorDialog from "./components/views/dialogs/ErrorDialog"; import WidgetStore from "./stores/WidgetStore"; import { WidgetMessagingStore } from "./stores/widgets/WidgetMessagingStore"; import { ElementWidgetActions } from "./stores/widgets/ElementWidgetActions"; import { MatrixCall, CallErrorCode, CallState, CallEvent, CallParty, CallType } from "matrix-js-sdk/src/webrtc/call"; import Analytics from './Analytics'; import CountlyAnalytics from "./CountlyAnalytics"; enum AudioID { Ring = 'ringAudio', Ringback = 'ringbackAudio', CallEnd = 'callendAudio', Busy = 'busyAudio', } // Unlike 'CallType' in js-sdk, this one includes screen sharing // (because a screen sharing call is only a screen sharing call to the caller, // to the callee it's just a video call, at least as far as the current impl // is concerned). export enum PlaceCallType { Voice = 'voice', Video = 'video', ScreenSharing = 'screensharing', } function getRemoteAudioElement(): HTMLAudioElement { // this needs to be somewhere at the top of the DOM which // always exists to avoid audio interruptions. // Might as well just use DOM. const remoteAudioElement = document.getElementById("remoteAudio") as HTMLAudioElement; if (!remoteAudioElement) { console.error( "Failed to find remoteAudio element - cannot play audio!" + "You need to add an