@unwanted/matrix-sdk-mini 34.12.0-1 → 34.12.0-2
Sign up to get free protection for your applications and to get access to all the features.
- package/git-revision.txt +1 -1
- package/lib/@types/event.d.ts +0 -19
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js.map +1 -1
- package/lib/client.d.ts +2 -50
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +391 -501
- package/lib/client.js.map +1 -1
- package/lib/embedded.d.ts.map +1 -1
- package/lib/embedded.js +0 -1
- package/lib/embedded.js.map +1 -1
- package/lib/matrix.d.ts +0 -6
- package/lib/matrix.d.ts.map +1 -1
- package/lib/matrix.js +1 -5
- package/lib/matrix.js.map +1 -1
- package/package.json +1 -1
- package/src/@types/event.ts +2 -36
- package/src/client.ts +1 -150
- package/src/embedded.ts +0 -2
- package/src/matrix.ts +0 -13
- package/lib/matrixrtc/CallMembership.d.ts +0 -66
- package/lib/matrixrtc/CallMembership.d.ts.map +0 -1
- package/lib/matrixrtc/CallMembership.js +0 -197
- package/lib/matrixrtc/CallMembership.js.map +0 -1
- package/lib/matrixrtc/LivekitFocus.d.ts +0 -16
- package/lib/matrixrtc/LivekitFocus.d.ts.map +0 -1
- package/lib/matrixrtc/LivekitFocus.js +0 -20
- package/lib/matrixrtc/LivekitFocus.js.map +0 -1
- package/lib/matrixrtc/MatrixRTCSession.d.ts +0 -295
- package/lib/matrixrtc/MatrixRTCSession.d.ts.map +0 -1
- package/lib/matrixrtc/MatrixRTCSession.js +0 -1043
- package/lib/matrixrtc/MatrixRTCSession.js.map +0 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts +0 -40
- package/lib/matrixrtc/MatrixRTCSessionManager.d.ts.map +0 -1
- package/lib/matrixrtc/MatrixRTCSessionManager.js +0 -146
- package/lib/matrixrtc/MatrixRTCSessionManager.js.map +0 -1
- package/lib/matrixrtc/focus.d.ts +0 -10
- package/lib/matrixrtc/focus.d.ts.map +0 -1
- package/lib/matrixrtc/focus.js +0 -1
- package/lib/matrixrtc/focus.js.map +0 -1
- package/lib/matrixrtc/index.d.ts +0 -7
- package/lib/matrixrtc/index.d.ts.map +0 -1
- package/lib/matrixrtc/index.js +0 -21
- package/lib/matrixrtc/index.js.map +0 -1
- package/lib/matrixrtc/types.d.ts +0 -19
- package/lib/matrixrtc/types.d.ts.map +0 -1
- package/lib/matrixrtc/types.js +0 -1
- package/lib/matrixrtc/types.js.map +0 -1
- package/lib/webrtc/audioContext.d.ts +0 -15
- package/lib/webrtc/audioContext.d.ts.map +0 -1
- package/lib/webrtc/audioContext.js +0 -46
- package/lib/webrtc/audioContext.js.map +0 -1
- package/lib/webrtc/call.d.ts +0 -560
- package/lib/webrtc/call.d.ts.map +0 -1
- package/lib/webrtc/call.js +0 -2541
- package/lib/webrtc/call.js.map +0 -1
- package/lib/webrtc/callEventHandler.d.ts +0 -37
- package/lib/webrtc/callEventHandler.d.ts.map +0 -1
- package/lib/webrtc/callEventHandler.js +0 -344
- package/lib/webrtc/callEventHandler.js.map +0 -1
- package/lib/webrtc/callEventTypes.d.ts +0 -73
- package/lib/webrtc/callEventTypes.d.ts.map +0 -1
- package/lib/webrtc/callEventTypes.js +0 -13
- package/lib/webrtc/callEventTypes.js.map +0 -1
- package/lib/webrtc/callFeed.d.ts +0 -128
- package/lib/webrtc/callFeed.d.ts.map +0 -1
- package/lib/webrtc/callFeed.js +0 -289
- package/lib/webrtc/callFeed.js.map +0 -1
- package/lib/webrtc/groupCall.d.ts +0 -323
- package/lib/webrtc/groupCall.d.ts.map +0 -1
- package/lib/webrtc/groupCall.js +0 -1337
- package/lib/webrtc/groupCall.js.map +0 -1
- package/lib/webrtc/groupCallEventHandler.d.ts +0 -31
- package/lib/webrtc/groupCallEventHandler.d.ts.map +0 -1
- package/lib/webrtc/groupCallEventHandler.js +0 -178
- package/lib/webrtc/groupCallEventHandler.js.map +0 -1
- package/lib/webrtc/mediaHandler.d.ts +0 -89
- package/lib/webrtc/mediaHandler.d.ts.map +0 -1
- package/lib/webrtc/mediaHandler.js +0 -437
- package/lib/webrtc/mediaHandler.js.map +0 -1
- package/lib/webrtc/stats/callFeedStatsReporter.d.ts +0 -8
- package/lib/webrtc/stats/callFeedStatsReporter.d.ts.map +0 -1
- package/lib/webrtc/stats/callFeedStatsReporter.js +0 -82
- package/lib/webrtc/stats/callFeedStatsReporter.js.map +0 -1
- package/lib/webrtc/stats/callStatsReportGatherer.d.ts +0 -25
- package/lib/webrtc/stats/callStatsReportGatherer.d.ts.map +0 -1
- package/lib/webrtc/stats/callStatsReportGatherer.js +0 -199
- package/lib/webrtc/stats/callStatsReportGatherer.js.map +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.d.ts +0 -17
- package/lib/webrtc/stats/callStatsReportSummary.d.ts.map +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.js +0 -1
- package/lib/webrtc/stats/callStatsReportSummary.js.map +0 -1
- package/lib/webrtc/stats/connectionStats.d.ts +0 -28
- package/lib/webrtc/stats/connectionStats.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStats.js +0 -26
- package/lib/webrtc/stats/connectionStats.js.map +0 -1
- package/lib/webrtc/stats/connectionStatsBuilder.d.ts +0 -5
- package/lib/webrtc/stats/connectionStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStatsBuilder.js +0 -27
- package/lib/webrtc/stats/connectionStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts +0 -7
- package/lib/webrtc/stats/connectionStatsReportBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.js +0 -121
- package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +0 -1
- package/lib/webrtc/stats/groupCallStats.d.ts +0 -22
- package/lib/webrtc/stats/groupCallStats.d.ts.map +0 -1
- package/lib/webrtc/stats/groupCallStats.js +0 -78
- package/lib/webrtc/stats/groupCallStats.js.map +0 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts +0 -10
- package/lib/webrtc/stats/media/mediaSsrcHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.js +0 -57
- package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.d.ts +0 -12
- package/lib/webrtc/stats/media/mediaTrackHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.js +0 -62
- package/lib/webrtc/stats/media/mediaTrackHandler.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStats.d.ts +0 -86
- package/lib/webrtc/stats/media/mediaTrackStats.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStats.js +0 -142
- package/lib/webrtc/stats/media/mediaTrackStats.js.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts +0 -22
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.d.ts.map +0 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +0 -76
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +0 -1
- package/lib/webrtc/stats/statsReport.d.ts +0 -99
- package/lib/webrtc/stats/statsReport.d.ts.map +0 -1
- package/lib/webrtc/stats/statsReport.js +0 -32
- package/lib/webrtc/stats/statsReport.js.map +0 -1
- package/lib/webrtc/stats/statsReportEmitter.d.ts +0 -15
- package/lib/webrtc/stats/statsReportEmitter.d.ts.map +0 -1
- package/lib/webrtc/stats/statsReportEmitter.js +0 -33
- package/lib/webrtc/stats/statsReportEmitter.js.map +0 -1
- package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts +0 -16
- package/lib/webrtc/stats/summaryStatsReportGatherer.d.ts.map +0 -1
- package/lib/webrtc/stats/summaryStatsReportGatherer.js +0 -116
- package/lib/webrtc/stats/summaryStatsReportGatherer.js.map +0 -1
- package/lib/webrtc/stats/trackStatsBuilder.d.ts +0 -19
- package/lib/webrtc/stats/trackStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/trackStatsBuilder.js +0 -168
- package/lib/webrtc/stats/trackStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/transportStats.d.ts +0 -11
- package/lib/webrtc/stats/transportStats.d.ts.map +0 -1
- package/lib/webrtc/stats/transportStats.js +0 -1
- package/lib/webrtc/stats/transportStats.js.map +0 -1
- package/lib/webrtc/stats/transportStatsBuilder.d.ts +0 -5
- package/lib/webrtc/stats/transportStatsBuilder.d.ts.map +0 -1
- package/lib/webrtc/stats/transportStatsBuilder.js +0 -34
- package/lib/webrtc/stats/transportStatsBuilder.js.map +0 -1
- package/lib/webrtc/stats/valueFormatter.d.ts +0 -4
- package/lib/webrtc/stats/valueFormatter.d.ts.map +0 -1
- package/lib/webrtc/stats/valueFormatter.js +0 -25
- package/lib/webrtc/stats/valueFormatter.js.map +0 -1
- package/src/matrixrtc/CallMembership.ts +0 -247
- package/src/matrixrtc/LivekitFocus.ts +0 -39
- package/src/matrixrtc/MatrixRTCSession.ts +0 -1319
- package/src/matrixrtc/MatrixRTCSessionManager.ts +0 -166
- package/src/matrixrtc/focus.ts +0 -25
- package/src/matrixrtc/index.ts +0 -22
- package/src/matrixrtc/types.ts +0 -36
- package/src/webrtc/audioContext.ts +0 -44
- package/src/webrtc/call.ts +0 -3074
- package/src/webrtc/callEventHandler.ts +0 -425
- package/src/webrtc/callEventTypes.ts +0 -93
- package/src/webrtc/callFeed.ts +0 -364
- package/src/webrtc/groupCall.ts +0 -1735
- package/src/webrtc/groupCallEventHandler.ts +0 -234
- package/src/webrtc/mediaHandler.ts +0 -484
- package/src/webrtc/stats/callFeedStatsReporter.ts +0 -94
- package/src/webrtc/stats/callStatsReportGatherer.ts +0 -219
- package/src/webrtc/stats/callStatsReportSummary.ts +0 -30
- package/src/webrtc/stats/connectionStats.ts +0 -47
- package/src/webrtc/stats/connectionStatsBuilder.ts +0 -28
- package/src/webrtc/stats/connectionStatsReportBuilder.ts +0 -140
- package/src/webrtc/stats/groupCallStats.ts +0 -93
- package/src/webrtc/stats/media/mediaSsrcHandler.ts +0 -57
- package/src/webrtc/stats/media/mediaTrackHandler.ts +0 -76
- package/src/webrtc/stats/media/mediaTrackStats.ts +0 -176
- package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +0 -90
- package/src/webrtc/stats/statsReport.ts +0 -133
- package/src/webrtc/stats/statsReportEmitter.ts +0 -49
- package/src/webrtc/stats/summaryStatsReportGatherer.ts +0 -148
- package/src/webrtc/stats/trackStatsBuilder.ts +0 -207
- package/src/webrtc/stats/transportStats.ts +0 -26
- package/src/webrtc/stats/transportStatsBuilder.ts +0 -48
- package/src/webrtc/stats/valueFormatter.ts +0 -27
package/lib/webrtc/call.js
DELETED
@@ -1,2541 +0,0 @@
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
2
|
-
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
5
|
-
/*
|
6
|
-
Copyright 2015, 2016 OpenMarket Ltd
|
7
|
-
Copyright 2017 New Vector Ltd
|
8
|
-
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
9
|
-
Copyright 2021 - 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
10
|
-
|
11
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
-
you may not use this file except in compliance with the License.
|
13
|
-
You may obtain a copy of the License at
|
14
|
-
|
15
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
16
|
-
|
17
|
-
Unless required by applicable law or agreed to in writing, software
|
18
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
-
See the License for the specific language governing permissions and
|
21
|
-
limitations under the License.
|
22
|
-
*/
|
23
|
-
|
24
|
-
/**
|
25
|
-
* This is an internal module. See {@link createNewMatrixCall} for the public API.
|
26
|
-
*/
|
27
|
-
|
28
|
-
import { v4 as uuidv4 } from "uuid";
|
29
|
-
import { parse as parseSdp, write as writeSdp } from "sdp-transform";
|
30
|
-
import { logger } from "../logger.js";
|
31
|
-
import { checkObjectHasKeys, isNullOrUndefined, recursivelyAssign } from "../utils.js";
|
32
|
-
import { EventType, ToDeviceMessageId } from "../@types/event.js";
|
33
|
-
import { randomString } from "../randomstring.js";
|
34
|
-
import { SDPStreamMetadataPurpose, SDPStreamMetadataKey } from "./callEventTypes.js";
|
35
|
-
import { CallFeed } from "./callFeed.js";
|
36
|
-
import { EventEmitterEvents, TypedEventEmitter } from "../models/typed-event-emitter.js";
|
37
|
-
import { DeviceInfo } from "../crypto/deviceinfo.js";
|
38
|
-
import { GroupCallUnknownDeviceError } from "./groupCall.js";
|
39
|
-
import { MatrixError } from "../http-api/index.js";
|
40
|
-
var MediaType = /*#__PURE__*/function (MediaType) {
|
41
|
-
MediaType["AUDIO"] = "audio";
|
42
|
-
MediaType["VIDEO"] = "video";
|
43
|
-
return MediaType;
|
44
|
-
}(MediaType || {});
|
45
|
-
var CodecName = /*#__PURE__*/function (CodecName) {
|
46
|
-
CodecName["OPUS"] = "opus";
|
47
|
-
return CodecName;
|
48
|
-
}(CodecName || {}); // add more as needed
|
49
|
-
// Used internally to specify modifications to codec parameters in SDP
|
50
|
-
export var CallState = /*#__PURE__*/function (CallState) {
|
51
|
-
CallState["Fledgling"] = "fledgling";
|
52
|
-
CallState["InviteSent"] = "invite_sent";
|
53
|
-
CallState["WaitLocalMedia"] = "wait_local_media";
|
54
|
-
CallState["CreateOffer"] = "create_offer";
|
55
|
-
CallState["CreateAnswer"] = "create_answer";
|
56
|
-
CallState["Connecting"] = "connecting";
|
57
|
-
CallState["Connected"] = "connected";
|
58
|
-
CallState["Ringing"] = "ringing";
|
59
|
-
CallState["Ended"] = "ended";
|
60
|
-
return CallState;
|
61
|
-
}({});
|
62
|
-
export var CallType = /*#__PURE__*/function (CallType) {
|
63
|
-
CallType["Voice"] = "voice";
|
64
|
-
CallType["Video"] = "video";
|
65
|
-
return CallType;
|
66
|
-
}({});
|
67
|
-
export var CallDirection = /*#__PURE__*/function (CallDirection) {
|
68
|
-
CallDirection["Inbound"] = "inbound";
|
69
|
-
CallDirection["Outbound"] = "outbound";
|
70
|
-
return CallDirection;
|
71
|
-
}({});
|
72
|
-
export var CallParty = /*#__PURE__*/function (CallParty) {
|
73
|
-
CallParty["Local"] = "local";
|
74
|
-
CallParty["Remote"] = "remote";
|
75
|
-
return CallParty;
|
76
|
-
}({});
|
77
|
-
export var CallEvent = /*#__PURE__*/function (CallEvent) {
|
78
|
-
CallEvent["Hangup"] = "hangup";
|
79
|
-
CallEvent["State"] = "state";
|
80
|
-
CallEvent["Error"] = "error";
|
81
|
-
CallEvent["Replaced"] = "replaced";
|
82
|
-
CallEvent["LocalHoldUnhold"] = "local_hold_unhold";
|
83
|
-
CallEvent["RemoteHoldUnhold"] = "remote_hold_unhold";
|
84
|
-
CallEvent["HoldUnhold"] = "hold_unhold";
|
85
|
-
CallEvent["FeedsChanged"] = "feeds_changed";
|
86
|
-
CallEvent["AssertedIdentityChanged"] = "asserted_identity_changed";
|
87
|
-
CallEvent["LengthChanged"] = "length_changed";
|
88
|
-
CallEvent["DataChannel"] = "datachannel";
|
89
|
-
CallEvent["SendVoipEvent"] = "send_voip_event";
|
90
|
-
CallEvent["PeerConnectionCreated"] = "peer_connection_created";
|
91
|
-
return CallEvent;
|
92
|
-
}({});
|
93
|
-
export var CallErrorCode = /*#__PURE__*/function (CallErrorCode) {
|
94
|
-
CallErrorCode["UserHangup"] = "user_hangup";
|
95
|
-
CallErrorCode["LocalOfferFailed"] = "local_offer_failed";
|
96
|
-
CallErrorCode["NoUserMedia"] = "no_user_media";
|
97
|
-
CallErrorCode["UnknownDevices"] = "unknown_devices";
|
98
|
-
CallErrorCode["SendInvite"] = "send_invite";
|
99
|
-
CallErrorCode["CreateAnswer"] = "create_answer";
|
100
|
-
CallErrorCode["CreateOffer"] = "create_offer";
|
101
|
-
CallErrorCode["SendAnswer"] = "send_answer";
|
102
|
-
CallErrorCode["SetRemoteDescription"] = "set_remote_description";
|
103
|
-
CallErrorCode["SetLocalDescription"] = "set_local_description";
|
104
|
-
CallErrorCode["AnsweredElsewhere"] = "answered_elsewhere";
|
105
|
-
CallErrorCode["IceFailed"] = "ice_failed";
|
106
|
-
CallErrorCode["InviteTimeout"] = "invite_timeout";
|
107
|
-
CallErrorCode["Replaced"] = "replaced";
|
108
|
-
CallErrorCode["SignallingFailed"] = "signalling_timeout";
|
109
|
-
CallErrorCode["UserBusy"] = "user_busy";
|
110
|
-
CallErrorCode["Transferred"] = "transferred";
|
111
|
-
CallErrorCode["NewSession"] = "new_session";
|
112
|
-
return CallErrorCode;
|
113
|
-
}({});
|
114
|
-
|
115
|
-
/**
|
116
|
-
* The version field that we set in m.call.* events
|
117
|
-
*/
|
118
|
-
var VOIP_PROTO_VERSION = "1";
|
119
|
-
|
120
|
-
/** The fallback ICE server to use for STUN or TURN protocols. */
|
121
|
-
export var FALLBACK_ICE_SERVER = "stun:turn.matrix.org";
|
122
|
-
|
123
|
-
/** The length of time a call can be ringing for. */
|
124
|
-
var CALL_TIMEOUT_MS = 60 * 1000; // ms
|
125
|
-
/** The time after which we increment callLength */
|
126
|
-
var CALL_LENGTH_INTERVAL = 1000; // ms
|
127
|
-
/** The time after which we end the call, if ICE got disconnected */
|
128
|
-
var ICE_DISCONNECTED_TIMEOUT = 30 * 1000; // ms
|
129
|
-
/** The time after which we try a ICE restart, if ICE got disconnected */
|
130
|
-
var ICE_RECONNECTING_TIMEOUT = 2 * 1000; // ms
|
131
|
-
export class CallError extends Error {
|
132
|
-
constructor(code, msg, err) {
|
133
|
-
// Still don't think there's any way to have proper nested errors
|
134
|
-
super(msg + ": " + err);
|
135
|
-
_defineProperty(this, "code", void 0);
|
136
|
-
this.code = code;
|
137
|
-
}
|
138
|
-
}
|
139
|
-
export function genCallID() {
|
140
|
-
return Date.now().toString() + randomString(16);
|
141
|
-
}
|
142
|
-
function getCodecParamMods(isPtt) {
|
143
|
-
var mods = [{
|
144
|
-
mediaType: "audio",
|
145
|
-
codec: "opus",
|
146
|
-
enableDtx: true,
|
147
|
-
maxAverageBitrate: isPtt ? 12000 : undefined
|
148
|
-
}];
|
149
|
-
return mods;
|
150
|
-
}
|
151
|
-
|
152
|
-
/**
|
153
|
-
* These now all have the call object as an argument. Why? Well, to know which call a given event is
|
154
|
-
* about you have three options:
|
155
|
-
* 1. Use a closure as the callback that remembers what call it's listening to. This can be
|
156
|
-
* a pain because you need to pass the listener function again when you remove the listener,
|
157
|
-
* which might be somewhere else.
|
158
|
-
* 2. Use not-very-well-known fact that EventEmitter sets 'this' to the emitter object in the
|
159
|
-
* callback. This doesn't really play well with modern Typescript and eslint and doesn't work
|
160
|
-
* with our pattern of re-emitting events.
|
161
|
-
* 3. Pass the object in question as an argument to the callback.
|
162
|
-
*
|
163
|
-
* Now that we have group calls which have to deal with multiple call objects, this will
|
164
|
-
* become more important, and I think methods 1 and 2 are just going to cause issues.
|
165
|
-
*/
|
166
|
-
|
167
|
-
// The key of the transceiver map (purpose + media type, separated by ':')
|
168
|
-
|
169
|
-
// generates keys for the map of transceivers
|
170
|
-
// kind is unfortunately a string rather than MediaType as this is the type of
|
171
|
-
// track.kind
|
172
|
-
function getTransceiverKey(purpose, kind) {
|
173
|
-
return purpose + ":" + kind;
|
174
|
-
}
|
175
|
-
export class MatrixCall extends TypedEventEmitter {
|
176
|
-
/**
|
177
|
-
* Construct a new Matrix Call.
|
178
|
-
* @param opts - Config options.
|
179
|
-
*/
|
180
|
-
constructor(opts) {
|
181
|
-
var _this, _opts$forceTURN;
|
182
|
-
super();
|
183
|
-
_this = this;
|
184
|
-
_defineProperty(this, "roomId", void 0);
|
185
|
-
_defineProperty(this, "callId", void 0);
|
186
|
-
_defineProperty(this, "invitee", void 0);
|
187
|
-
_defineProperty(this, "hangupParty", void 0);
|
188
|
-
_defineProperty(this, "hangupReason", void 0);
|
189
|
-
_defineProperty(this, "direction", void 0);
|
190
|
-
_defineProperty(this, "ourPartyId", void 0);
|
191
|
-
_defineProperty(this, "peerConn", void 0);
|
192
|
-
_defineProperty(this, "toDeviceSeq", 0);
|
193
|
-
// whether this call should have push-to-talk semantics
|
194
|
-
// This should be set by the consumer on incoming & outgoing calls.
|
195
|
-
_defineProperty(this, "isPtt", false);
|
196
|
-
_defineProperty(this, "_state", CallState.Fledgling);
|
197
|
-
_defineProperty(this, "client", void 0);
|
198
|
-
_defineProperty(this, "forceTURN", void 0);
|
199
|
-
_defineProperty(this, "turnServers", void 0);
|
200
|
-
// A queue for candidates waiting to go out.
|
201
|
-
// We try to amalgamate candidates into a single candidate message where
|
202
|
-
// possible
|
203
|
-
_defineProperty(this, "candidateSendQueue", []);
|
204
|
-
_defineProperty(this, "candidateSendTries", 0);
|
205
|
-
_defineProperty(this, "candidatesEnded", false);
|
206
|
-
_defineProperty(this, "feeds", []);
|
207
|
-
// our transceivers for each purpose and type of media
|
208
|
-
_defineProperty(this, "transceivers", new Map());
|
209
|
-
_defineProperty(this, "inviteOrAnswerSent", false);
|
210
|
-
_defineProperty(this, "waitForLocalAVStream", false);
|
211
|
-
_defineProperty(this, "successor", void 0);
|
212
|
-
_defineProperty(this, "opponentMember", void 0);
|
213
|
-
_defineProperty(this, "opponentVersion", void 0);
|
214
|
-
// The party ID of the other side: undefined if we haven't chosen a partner
|
215
|
-
// yet, null if we have but they didn't send a party ID.
|
216
|
-
_defineProperty(this, "opponentPartyId", void 0);
|
217
|
-
_defineProperty(this, "opponentCaps", void 0);
|
218
|
-
_defineProperty(this, "iceDisconnectedTimeout", void 0);
|
219
|
-
_defineProperty(this, "iceReconnectionTimeOut", void 0);
|
220
|
-
_defineProperty(this, "inviteTimeout", void 0);
|
221
|
-
_defineProperty(this, "removeTrackListeners", new Map());
|
222
|
-
// The logic of when & if a call is on hold is nontrivial and explained in is*OnHold
|
223
|
-
// This flag represents whether we want the other party to be on hold
|
224
|
-
_defineProperty(this, "remoteOnHold", false);
|
225
|
-
// the stats for the call at the point it ended. We can't get these after we
|
226
|
-
// tear the call down, so we just grab a snapshot before we stop the call.
|
227
|
-
// The typescript definitions have this type as 'any' :(
|
228
|
-
_defineProperty(this, "callStatsAtEnd", void 0);
|
229
|
-
// Perfect negotiation state: https://www.w3.org/TR/webrtc/#perfect-negotiation-example
|
230
|
-
_defineProperty(this, "makingOffer", false);
|
231
|
-
_defineProperty(this, "ignoreOffer", false);
|
232
|
-
_defineProperty(this, "isSettingRemoteAnswerPending", false);
|
233
|
-
_defineProperty(this, "responsePromiseChain", void 0);
|
234
|
-
// If candidates arrive before we've picked an opponent (which, in particular,
|
235
|
-
// will happen if the opponent sends candidates eagerly before the user answers
|
236
|
-
// the call) we buffer them up here so we can then add the ones from the party we pick
|
237
|
-
_defineProperty(this, "remoteCandidateBuffer", new Map());
|
238
|
-
_defineProperty(this, "remoteAssertedIdentity", void 0);
|
239
|
-
_defineProperty(this, "remoteSDPStreamMetadata", void 0);
|
240
|
-
_defineProperty(this, "callLengthInterval", void 0);
|
241
|
-
_defineProperty(this, "callStartTime", void 0);
|
242
|
-
_defineProperty(this, "opponentDeviceId", void 0);
|
243
|
-
_defineProperty(this, "opponentDeviceInfo", void 0);
|
244
|
-
_defineProperty(this, "opponentSessionId", void 0);
|
245
|
-
_defineProperty(this, "groupCallId", void 0);
|
246
|
-
// Used to keep the timer for the delay before actually stopping our
|
247
|
-
// video track after muting (see setLocalVideoMuted)
|
248
|
-
_defineProperty(this, "stopVideoTrackTimer", void 0);
|
249
|
-
// Used to allow connection without Video and Audio. To establish a webrtc connection without media a Data channel is
|
250
|
-
// needed At the moment this property is true if we allow MatrixClient with isVoipWithNoMediaAllowed = true
|
251
|
-
_defineProperty(this, "isOnlyDataChannelAllowed", void 0);
|
252
|
-
_defineProperty(this, "stats", void 0);
|
253
|
-
/**
|
254
|
-
* Internal
|
255
|
-
*/
|
256
|
-
_defineProperty(this, "gotLocalIceCandidate", event => {
|
257
|
-
if (event.candidate) {
|
258
|
-
if (this.candidatesEnded) {
|
259
|
-
logger.warn("Call ".concat(this.callId, " gotLocalIceCandidate() got candidate after candidates have ended!"));
|
260
|
-
}
|
261
|
-
logger.debug("Call ".concat(this.callId, " got local ICE ").concat(event.candidate.sdpMid, " ").concat(event.candidate.candidate));
|
262
|
-
if (this.callHasEnded()) return;
|
263
|
-
|
264
|
-
// As with the offer, note we need to make a copy of this object, not
|
265
|
-
// pass the original: that broke in Chrome ~m43.
|
266
|
-
if (event.candidate.candidate === "") {
|
267
|
-
this.queueCandidate(null);
|
268
|
-
} else {
|
269
|
-
this.queueCandidate(event.candidate);
|
270
|
-
}
|
271
|
-
}
|
272
|
-
});
|
273
|
-
_defineProperty(this, "onIceGatheringStateChange", event => {
|
274
|
-
var _this$peerConn;
|
275
|
-
logger.debug("Call ".concat(this.callId, " onIceGatheringStateChange() ice gathering state changed to ").concat(this.peerConn.iceGatheringState));
|
276
|
-
if (((_this$peerConn = this.peerConn) === null || _this$peerConn === void 0 ? void 0 : _this$peerConn.iceGatheringState) === "complete") {
|
277
|
-
this.queueCandidate(null); // We should leave it to WebRTC to announce the end
|
278
|
-
logger.debug("Call ".concat(this.callId, " onIceGatheringStateChange() ice gathering state complete, set candidates have ended"));
|
279
|
-
}
|
280
|
-
});
|
281
|
-
_defineProperty(this, "getLocalOfferFailed", err => {
|
282
|
-
logger.error("Call ".concat(this.callId, " getLocalOfferFailed() running"), err);
|
283
|
-
this.emit(CallEvent.Error, new CallError(CallErrorCode.LocalOfferFailed, "Failed to get local offer!", err), this);
|
284
|
-
this.terminate(CallParty.Local, CallErrorCode.LocalOfferFailed, false);
|
285
|
-
});
|
286
|
-
_defineProperty(this, "getUserMediaFailed", err => {
|
287
|
-
if (this.successor) {
|
288
|
-
this.successor.getUserMediaFailed(err);
|
289
|
-
return;
|
290
|
-
}
|
291
|
-
logger.warn("Call ".concat(this.callId, " getUserMediaFailed() failed to get user media - ending call"), err);
|
292
|
-
this.emit(CallEvent.Error, new CallError(CallErrorCode.NoUserMedia, "Couldn't start capturing media! Is your microphone set up and does this app have permission?", err), this);
|
293
|
-
this.terminate(CallParty.Local, CallErrorCode.NoUserMedia, false);
|
294
|
-
});
|
295
|
-
_defineProperty(this, "placeCallFailed", err => {
|
296
|
-
if (this.successor) {
|
297
|
-
this.successor.placeCallFailed(err);
|
298
|
-
return;
|
299
|
-
}
|
300
|
-
logger.warn("Call ".concat(this.callId, " placeCallWithCallFeeds() failed - ending call"), err);
|
301
|
-
this.emit(CallEvent.Error, new CallError(CallErrorCode.IceFailed, "Couldn't start call! Invalid ICE server configuration.", err), this);
|
302
|
-
this.terminate(CallParty.Local, CallErrorCode.IceFailed, false);
|
303
|
-
});
|
304
|
-
_defineProperty(this, "onIceConnectionStateChanged", () => {
|
305
|
-
var _this$peerConn2, _this$peerConn3, _this$peerConn$iceCon, _this$peerConn4, _this$peerConn5, _this$peerConn8;
|
306
|
-
if (this.callHasEnded()) {
|
307
|
-
return; // because ICE can still complete as we're ending the call
|
308
|
-
}
|
309
|
-
logger.debug("Call ".concat(this.callId, " onIceConnectionStateChanged() running (state=").concat((_this$peerConn2 = this.peerConn) === null || _this$peerConn2 === void 0 ? void 0 : _this$peerConn2.iceConnectionState, ", conn=").concat((_this$peerConn3 = this.peerConn) === null || _this$peerConn3 === void 0 ? void 0 : _this$peerConn3.connectionState, ")"));
|
310
|
-
|
311
|
-
// ideally we'd consider the call to be connected when we get media but
|
312
|
-
// chrome doesn't implement any of the 'onstarted' events yet
|
313
|
-
if (["connected", "completed"].includes((_this$peerConn$iceCon = (_this$peerConn4 = this.peerConn) === null || _this$peerConn4 === void 0 ? void 0 : _this$peerConn4.iceConnectionState) !== null && _this$peerConn$iceCon !== void 0 ? _this$peerConn$iceCon : "")) {
|
314
|
-
clearTimeout(this.iceDisconnectedTimeout);
|
315
|
-
this.iceDisconnectedTimeout = undefined;
|
316
|
-
if (this.iceReconnectionTimeOut) {
|
317
|
-
clearTimeout(this.iceReconnectionTimeOut);
|
318
|
-
}
|
319
|
-
this.state = CallState.Connected;
|
320
|
-
if (!this.callLengthInterval && !this.callStartTime) {
|
321
|
-
this.callStartTime = Date.now();
|
322
|
-
this.callLengthInterval = setInterval(() => {
|
323
|
-
this.emit(CallEvent.LengthChanged, Math.round((Date.now() - this.callStartTime) / 1000), this);
|
324
|
-
}, CALL_LENGTH_INTERVAL);
|
325
|
-
}
|
326
|
-
} else if (((_this$peerConn5 = this.peerConn) === null || _this$peerConn5 === void 0 ? void 0 : _this$peerConn5.iceConnectionState) == "failed") {
|
327
|
-
var _this$peerConn6;
|
328
|
-
this.candidatesEnded = false;
|
329
|
-
// Firefox for Android does not yet have support for restartIce()
|
330
|
-
// (the types say it's always defined though, so we have to cast
|
331
|
-
// to prevent typescript from warning).
|
332
|
-
if ((_this$peerConn6 = this.peerConn) !== null && _this$peerConn6 !== void 0 && _this$peerConn6.restartIce) {
|
333
|
-
var _this$peerConn7;
|
334
|
-
this.candidatesEnded = false;
|
335
|
-
logger.debug("Call ".concat(this.callId, " onIceConnectionStateChanged() ice restart (state=").concat((_this$peerConn7 = this.peerConn) === null || _this$peerConn7 === void 0 ? void 0 : _this$peerConn7.iceConnectionState, ")"));
|
336
|
-
this.peerConn.restartIce();
|
337
|
-
} else {
|
338
|
-
logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() hanging up call (ICE failed and no ICE restart method)"));
|
339
|
-
this.hangup(CallErrorCode.IceFailed, false);
|
340
|
-
}
|
341
|
-
} else if (((_this$peerConn8 = this.peerConn) === null || _this$peerConn8 === void 0 ? void 0 : _this$peerConn8.iceConnectionState) == "disconnected") {
|
342
|
-
this.candidatesEnded = false;
|
343
|
-
this.iceReconnectionTimeOut = setTimeout(() => {
|
344
|
-
var _this$peerConn9, _this$peerConn10, _this$peerConn11;
|
345
|
-
logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() ICE restarting because of ICE disconnected, (state=").concat((_this$peerConn9 = this.peerConn) === null || _this$peerConn9 === void 0 ? void 0 : _this$peerConn9.iceConnectionState, ", conn=").concat((_this$peerConn10 = this.peerConn) === null || _this$peerConn10 === void 0 ? void 0 : _this$peerConn10.connectionState, ")"));
|
346
|
-
if ((_this$peerConn11 = this.peerConn) !== null && _this$peerConn11 !== void 0 && _this$peerConn11.restartIce) {
|
347
|
-
this.candidatesEnded = false;
|
348
|
-
this.peerConn.restartIce();
|
349
|
-
}
|
350
|
-
this.iceReconnectionTimeOut = undefined;
|
351
|
-
}, ICE_RECONNECTING_TIMEOUT);
|
352
|
-
this.iceDisconnectedTimeout = setTimeout(() => {
|
353
|
-
logger.info("Call ".concat(this.callId, " onIceConnectionStateChanged() hanging up call (ICE disconnected for too long)"));
|
354
|
-
this.hangup(CallErrorCode.IceFailed, false);
|
355
|
-
}, ICE_DISCONNECTED_TIMEOUT);
|
356
|
-
this.state = CallState.Connecting;
|
357
|
-
}
|
358
|
-
|
359
|
-
// In PTT mode, override feed status to muted when we lose connection to
|
360
|
-
// the peer, since we don't want to block the line if they're not saying anything.
|
361
|
-
// Experimenting in Chrome, this happens after 5 or 6 seconds, which is probably
|
362
|
-
// fast enough.
|
363
|
-
if (this.isPtt && ["failed", "disconnected"].includes(this.peerConn.iceConnectionState)) {
|
364
|
-
for (var feed of this.getRemoteFeeds()) {
|
365
|
-
feed.setAudioVideoMuted(true, true);
|
366
|
-
}
|
367
|
-
}
|
368
|
-
});
|
369
|
-
_defineProperty(this, "onSignallingStateChanged", () => {
|
370
|
-
var _this$peerConn12;
|
371
|
-
logger.debug("Call ".concat(this.callId, " onSignallingStateChanged() running (state=").concat((_this$peerConn12 = this.peerConn) === null || _this$peerConn12 === void 0 ? void 0 : _this$peerConn12.signalingState, ")"));
|
372
|
-
});
|
373
|
-
_defineProperty(this, "onTrack", ev => {
|
374
|
-
if (ev.streams.length === 0) {
|
375
|
-
logger.warn("Call ".concat(this.callId, " onTrack() called with streamless track streamless (kind=").concat(ev.track.kind, ")"));
|
376
|
-
return;
|
377
|
-
}
|
378
|
-
var stream = ev.streams[0];
|
379
|
-
this.pushRemoteFeed(stream);
|
380
|
-
if (!this.removeTrackListeners.has(stream)) {
|
381
|
-
var onRemoveTrack = () => {
|
382
|
-
if (stream.getTracks().length === 0) {
|
383
|
-
logger.info("Call ".concat(this.callId, " onTrack() removing track (streamId=").concat(stream.id, ")"));
|
384
|
-
this.deleteFeedByStream(stream);
|
385
|
-
stream.removeEventListener("removetrack", onRemoveTrack);
|
386
|
-
this.removeTrackListeners.delete(stream);
|
387
|
-
}
|
388
|
-
};
|
389
|
-
stream.addEventListener("removetrack", onRemoveTrack);
|
390
|
-
this.removeTrackListeners.set(stream, onRemoveTrack);
|
391
|
-
}
|
392
|
-
});
|
393
|
-
_defineProperty(this, "onDataChannel", ev => {
|
394
|
-
this.emit(CallEvent.DataChannel, ev.channel, this);
|
395
|
-
});
|
396
|
-
_defineProperty(this, "onNegotiationNeeded", /*#__PURE__*/_asyncToGenerator(function* () {
|
397
|
-
logger.info("Call ".concat(_this.callId, " onNegotiationNeeded() negotiation is needed!"));
|
398
|
-
if (_this.state !== CallState.CreateOffer && _this.opponentVersion === 0) {
|
399
|
-
logger.info("Call ".concat(_this.callId, " onNegotiationNeeded() opponent does not support renegotiation: ignoring negotiationneeded event"));
|
400
|
-
return;
|
401
|
-
}
|
402
|
-
_this.queueGotLocalOffer();
|
403
|
-
}));
|
404
|
-
_defineProperty(this, "onHangupReceived", msg => {
|
405
|
-
logger.debug("Call ".concat(this.callId, " onHangupReceived() running"));
|
406
|
-
|
407
|
-
// party ID must match (our chosen partner hanging up the call) or be undefined (we haven't chosen
|
408
|
-
// a partner yet but we're treating the hangup as a reject as per VoIP v0)
|
409
|
-
if (this.partyIdMatches(msg) || this.state === CallState.Ringing) {
|
410
|
-
// default reason is user_hangup
|
411
|
-
this.terminate(CallParty.Remote, msg.reason || CallErrorCode.UserHangup, true);
|
412
|
-
} else {
|
413
|
-
logger.info("Call ".concat(this.callId, " onHangupReceived() ignoring message from party ID ").concat(msg.party_id, ": our partner is ").concat(this.opponentPartyId));
|
414
|
-
}
|
415
|
-
});
|
416
|
-
_defineProperty(this, "onRejectReceived", msg => {
|
417
|
-
logger.debug("Call ".concat(this.callId, " onRejectReceived() running"));
|
418
|
-
|
419
|
-
// No need to check party_id for reject because if we'd received either
|
420
|
-
// an answer or reject, we wouldn't be in state InviteSent
|
421
|
-
|
422
|
-
var shouldTerminate =
|
423
|
-
// reject events also end the call if it's ringing: it's another of
|
424
|
-
// our devices rejecting the call.
|
425
|
-
[CallState.InviteSent, CallState.Ringing].includes(this.state) ||
|
426
|
-
// also if we're in the init state and it's an inbound call, since
|
427
|
-
// this means we just haven't entered the ringing state yet
|
428
|
-
this.state === CallState.Fledgling && this.direction === CallDirection.Inbound;
|
429
|
-
if (shouldTerminate) {
|
430
|
-
this.terminate(CallParty.Remote, msg.reason || CallErrorCode.UserHangup, true);
|
431
|
-
} else {
|
432
|
-
logger.debug("Call ".concat(this.callId, " onRejectReceived() called in wrong state (state=").concat(this.state, ")"));
|
433
|
-
}
|
434
|
-
});
|
435
|
-
_defineProperty(this, "onAnsweredElsewhere", msg => {
|
436
|
-
logger.debug("Call ".concat(this.callId, " onAnsweredElsewhere() running"));
|
437
|
-
this.terminate(CallParty.Remote, CallErrorCode.AnsweredElsewhere, true);
|
438
|
-
});
|
439
|
-
this.roomId = opts.roomId;
|
440
|
-
this.invitee = opts.invitee;
|
441
|
-
this.client = opts.client;
|
442
|
-
if (!this.client.deviceId) throw new Error("Client must have a device ID to start calls");
|
443
|
-
this.forceTURN = (_opts$forceTURN = opts.forceTURN) !== null && _opts$forceTURN !== void 0 ? _opts$forceTURN : false;
|
444
|
-
this.ourPartyId = this.client.deviceId;
|
445
|
-
this.opponentDeviceId = opts.opponentDeviceId;
|
446
|
-
this.opponentSessionId = opts.opponentSessionId;
|
447
|
-
this.groupCallId = opts.groupCallId;
|
448
|
-
// Array of Objects with urls, username, credential keys
|
449
|
-
this.turnServers = opts.turnServers || [];
|
450
|
-
if (this.turnServers.length === 0 && this.client.isFallbackICEServerAllowed()) {
|
451
|
-
this.turnServers.push({
|
452
|
-
urls: [FALLBACK_ICE_SERVER]
|
453
|
-
});
|
454
|
-
}
|
455
|
-
for (var server of this.turnServers) {
|
456
|
-
checkObjectHasKeys(server, ["urls"]);
|
457
|
-
}
|
458
|
-
this.callId = genCallID();
|
459
|
-
// If the Client provides calls without audio and video we need a datachannel for a webrtc connection
|
460
|
-
this.isOnlyDataChannelAllowed = this.client.isVoipWithNoMediaAllowed;
|
461
|
-
}
|
462
|
-
|
463
|
-
/**
|
464
|
-
* Place a voice call to this room.
|
465
|
-
* @throws If you have not specified a listener for 'error' events.
|
466
|
-
*/
|
467
|
-
placeVoiceCall() {
|
468
|
-
var _this2 = this;
|
469
|
-
return _asyncToGenerator(function* () {
|
470
|
-
yield _this2.placeCall(true, false);
|
471
|
-
})();
|
472
|
-
}
|
473
|
-
|
474
|
-
/**
|
475
|
-
* Place a video call to this room.
|
476
|
-
* @throws If you have not specified a listener for 'error' events.
|
477
|
-
*/
|
478
|
-
placeVideoCall() {
|
479
|
-
var _this3 = this;
|
480
|
-
return _asyncToGenerator(function* () {
|
481
|
-
yield _this3.placeCall(true, true);
|
482
|
-
})();
|
483
|
-
}
|
484
|
-
|
485
|
-
/**
|
486
|
-
* Create a datachannel using this call's peer connection.
|
487
|
-
* @param label - A human readable label for this datachannel
|
488
|
-
* @param options - An object providing configuration options for the data channel.
|
489
|
-
*/
|
490
|
-
createDataChannel(label, options) {
|
491
|
-
var dataChannel = this.peerConn.createDataChannel(label, options);
|
492
|
-
this.emit(CallEvent.DataChannel, dataChannel, this);
|
493
|
-
return dataChannel;
|
494
|
-
}
|
495
|
-
getOpponentMember() {
|
496
|
-
return this.opponentMember;
|
497
|
-
}
|
498
|
-
getOpponentDeviceId() {
|
499
|
-
return this.opponentDeviceId;
|
500
|
-
}
|
501
|
-
getOpponentSessionId() {
|
502
|
-
return this.opponentSessionId;
|
503
|
-
}
|
504
|
-
opponentCanBeTransferred() {
|
505
|
-
return Boolean(this.opponentCaps && this.opponentCaps["m.call.transferee"]);
|
506
|
-
}
|
507
|
-
opponentSupportsDTMF() {
|
508
|
-
return Boolean(this.opponentCaps && this.opponentCaps["m.call.dtmf"]);
|
509
|
-
}
|
510
|
-
getRemoteAssertedIdentity() {
|
511
|
-
return this.remoteAssertedIdentity;
|
512
|
-
}
|
513
|
-
get state() {
|
514
|
-
return this._state;
|
515
|
-
}
|
516
|
-
set state(state) {
|
517
|
-
var oldState = this._state;
|
518
|
-
this._state = state;
|
519
|
-
this.emit(CallEvent.State, state, oldState, this);
|
520
|
-
}
|
521
|
-
get type() {
|
522
|
-
// we may want to look for a video receiver here rather than a track to match the
|
523
|
-
// sender behaviour, although in practice they should be the same thing
|
524
|
-
return this.hasUserMediaVideoSender || this.hasRemoteUserMediaVideoTrack ? CallType.Video : CallType.Voice;
|
525
|
-
}
|
526
|
-
get hasLocalUserMediaVideoTrack() {
|
527
|
-
var _this$localUsermediaS;
|
528
|
-
return !!((_this$localUsermediaS = this.localUsermediaStream) !== null && _this$localUsermediaS !== void 0 && _this$localUsermediaS.getVideoTracks().length);
|
529
|
-
}
|
530
|
-
get hasRemoteUserMediaVideoTrack() {
|
531
|
-
return this.getRemoteFeeds().some(feed => {
|
532
|
-
var _feed$stream;
|
533
|
-
return feed.purpose === SDPStreamMetadataPurpose.Usermedia && ((_feed$stream = feed.stream) === null || _feed$stream === void 0 ? void 0 : _feed$stream.getVideoTracks().length);
|
534
|
-
});
|
535
|
-
}
|
536
|
-
get hasLocalUserMediaAudioTrack() {
|
537
|
-
var _this$localUsermediaS2;
|
538
|
-
return !!((_this$localUsermediaS2 = this.localUsermediaStream) !== null && _this$localUsermediaS2 !== void 0 && _this$localUsermediaS2.getAudioTracks().length);
|
539
|
-
}
|
540
|
-
get hasRemoteUserMediaAudioTrack() {
|
541
|
-
return this.getRemoteFeeds().some(feed => {
|
542
|
-
var _feed$stream2;
|
543
|
-
return feed.purpose === SDPStreamMetadataPurpose.Usermedia && !!((_feed$stream2 = feed.stream) !== null && _feed$stream2 !== void 0 && _feed$stream2.getAudioTracks().length);
|
544
|
-
});
|
545
|
-
}
|
546
|
-
get hasUserMediaAudioSender() {
|
547
|
-
var _this$transceivers$ge;
|
548
|
-
return Boolean((_this$transceivers$ge = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "audio"))) === null || _this$transceivers$ge === void 0 ? void 0 : _this$transceivers$ge.sender);
|
549
|
-
}
|
550
|
-
get hasUserMediaVideoSender() {
|
551
|
-
var _this$transceivers$ge2;
|
552
|
-
return Boolean((_this$transceivers$ge2 = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this$transceivers$ge2 === void 0 ? void 0 : _this$transceivers$ge2.sender);
|
553
|
-
}
|
554
|
-
get localUsermediaFeed() {
|
555
|
-
return this.getLocalFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
|
556
|
-
}
|
557
|
-
get localScreensharingFeed() {
|
558
|
-
return this.getLocalFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
|
559
|
-
}
|
560
|
-
get localUsermediaStream() {
|
561
|
-
var _this$localUsermediaF;
|
562
|
-
return (_this$localUsermediaF = this.localUsermediaFeed) === null || _this$localUsermediaF === void 0 ? void 0 : _this$localUsermediaF.stream;
|
563
|
-
}
|
564
|
-
get localScreensharingStream() {
|
565
|
-
var _this$localScreenshar;
|
566
|
-
return (_this$localScreenshar = this.localScreensharingFeed) === null || _this$localScreenshar === void 0 ? void 0 : _this$localScreenshar.stream;
|
567
|
-
}
|
568
|
-
get remoteUsermediaFeed() {
|
569
|
-
return this.getRemoteFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Usermedia);
|
570
|
-
}
|
571
|
-
get remoteScreensharingFeed() {
|
572
|
-
return this.getRemoteFeeds().find(feed => feed.purpose === SDPStreamMetadataPurpose.Screenshare);
|
573
|
-
}
|
574
|
-
get remoteUsermediaStream() {
|
575
|
-
var _this$remoteUsermedia;
|
576
|
-
return (_this$remoteUsermedia = this.remoteUsermediaFeed) === null || _this$remoteUsermedia === void 0 ? void 0 : _this$remoteUsermedia.stream;
|
577
|
-
}
|
578
|
-
get remoteScreensharingStream() {
|
579
|
-
var _this$remoteScreensha;
|
580
|
-
return (_this$remoteScreensha = this.remoteScreensharingFeed) === null || _this$remoteScreensha === void 0 ? void 0 : _this$remoteScreensha.stream;
|
581
|
-
}
|
582
|
-
getFeedByStreamId(streamId) {
|
583
|
-
return this.getFeeds().find(feed => feed.stream.id === streamId);
|
584
|
-
}
|
585
|
-
|
586
|
-
/**
|
587
|
-
* Returns an array of all CallFeeds
|
588
|
-
* @returns CallFeeds
|
589
|
-
*/
|
590
|
-
getFeeds() {
|
591
|
-
return this.feeds;
|
592
|
-
}
|
593
|
-
|
594
|
-
/**
|
595
|
-
* Returns an array of all local CallFeeds
|
596
|
-
* @returns local CallFeeds
|
597
|
-
*/
|
598
|
-
getLocalFeeds() {
|
599
|
-
return this.feeds.filter(feed => feed.isLocal());
|
600
|
-
}
|
601
|
-
|
602
|
-
/**
|
603
|
-
* Returns an array of all remote CallFeeds
|
604
|
-
* @returns remote CallFeeds
|
605
|
-
*/
|
606
|
-
getRemoteFeeds() {
|
607
|
-
return this.feeds.filter(feed => !feed.isLocal());
|
608
|
-
}
|
609
|
-
initOpponentCrypto() {
|
610
|
-
var _this4 = this;
|
611
|
-
return _asyncToGenerator(function* () {
|
612
|
-
var _this4$getOpponentMem, _deviceInfoMap$get;
|
613
|
-
if (!_this4.opponentDeviceId) return;
|
614
|
-
if (!_this4.client.getUseE2eForGroupCall()) return;
|
615
|
-
// It's possible to want E2EE and yet not have the means to manage E2EE
|
616
|
-
// ourselves (for example if the client is a RoomWidgetClient)
|
617
|
-
if (!_this4.client.isCryptoEnabled()) {
|
618
|
-
// All we know is the device ID
|
619
|
-
_this4.opponentDeviceInfo = new DeviceInfo(_this4.opponentDeviceId);
|
620
|
-
return;
|
621
|
-
}
|
622
|
-
// if we've got to this point, we do want to init crypto, so throw if we can't
|
623
|
-
if (!_this4.client.crypto) throw new Error("Crypto is not initialised.");
|
624
|
-
var userId = _this4.invitee || ((_this4$getOpponentMem = _this4.getOpponentMember()) === null || _this4$getOpponentMem === void 0 ? void 0 : _this4$getOpponentMem.userId);
|
625
|
-
if (!userId) throw new Error("Couldn't find opponent user ID to init crypto");
|
626
|
-
var deviceInfoMap = yield _this4.client.crypto.deviceList.downloadKeys([userId], false);
|
627
|
-
_this4.opponentDeviceInfo = (_deviceInfoMap$get = deviceInfoMap.get(userId)) === null || _deviceInfoMap$get === void 0 ? void 0 : _deviceInfoMap$get.get(_this4.opponentDeviceId);
|
628
|
-
if (_this4.opponentDeviceInfo === undefined) {
|
629
|
-
throw new GroupCallUnknownDeviceError(userId);
|
630
|
-
}
|
631
|
-
})();
|
632
|
-
}
|
633
|
-
|
634
|
-
/**
|
635
|
-
* Generates and returns localSDPStreamMetadata
|
636
|
-
* @returns localSDPStreamMetadata
|
637
|
-
*/
|
638
|
-
getLocalSDPStreamMetadata() {
|
639
|
-
var updateStreamIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
640
|
-
var metadata = {};
|
641
|
-
for (var localFeed of this.getLocalFeeds()) {
|
642
|
-
if (updateStreamIds) {
|
643
|
-
localFeed.sdpMetadataStreamId = localFeed.stream.id;
|
644
|
-
}
|
645
|
-
metadata[localFeed.sdpMetadataStreamId] = {
|
646
|
-
purpose: localFeed.purpose,
|
647
|
-
audio_muted: localFeed.isAudioMuted(),
|
648
|
-
video_muted: localFeed.isVideoMuted()
|
649
|
-
};
|
650
|
-
}
|
651
|
-
return metadata;
|
652
|
-
}
|
653
|
-
|
654
|
-
/**
|
655
|
-
* Returns true if there are no incoming feeds,
|
656
|
-
* otherwise returns false
|
657
|
-
* @returns no incoming feeds
|
658
|
-
*/
|
659
|
-
noIncomingFeeds() {
|
660
|
-
return !this.feeds.some(feed => !feed.isLocal());
|
661
|
-
}
|
662
|
-
pushRemoteFeed(stream) {
|
663
|
-
// Fallback to old behavior if the other side doesn't support SDPStreamMetadata
|
664
|
-
if (!this.opponentSupportsSDPStreamMetadata()) {
|
665
|
-
this.pushRemoteFeedWithoutMetadata(stream);
|
666
|
-
return;
|
667
|
-
}
|
668
|
-
var userId = this.getOpponentMember().userId;
|
669
|
-
var purpose = this.remoteSDPStreamMetadata[stream.id].purpose;
|
670
|
-
var audioMuted = this.remoteSDPStreamMetadata[stream.id].audio_muted;
|
671
|
-
var videoMuted = this.remoteSDPStreamMetadata[stream.id].video_muted;
|
672
|
-
if (!purpose) {
|
673
|
-
logger.warn("Call ".concat(this.callId, " pushRemoteFeed() ignoring stream because we didn't get any metadata about it (streamId=").concat(stream.id, ")"));
|
674
|
-
return;
|
675
|
-
}
|
676
|
-
if (this.getFeedByStreamId(stream.id)) {
|
677
|
-
logger.warn("Call ".concat(this.callId, " pushRemoteFeed() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
|
678
|
-
return;
|
679
|
-
}
|
680
|
-
this.feeds.push(new CallFeed({
|
681
|
-
client: this.client,
|
682
|
-
call: this,
|
683
|
-
roomId: this.roomId,
|
684
|
-
userId,
|
685
|
-
deviceId: this.getOpponentDeviceId(),
|
686
|
-
stream,
|
687
|
-
purpose,
|
688
|
-
audioMuted,
|
689
|
-
videoMuted
|
690
|
-
}));
|
691
|
-
this.emit(CallEvent.FeedsChanged, this.feeds, this);
|
692
|
-
logger.info("Call ".concat(this.callId, " pushRemoteFeed() pushed stream (streamId=").concat(stream.id, ", active=").concat(stream.active, ", purpose=").concat(purpose, ")"));
|
693
|
-
}
|
694
|
-
|
695
|
-
/**
|
696
|
-
* This method is used ONLY if the other client doesn't support sending SDPStreamMetadata
|
697
|
-
*/
|
698
|
-
pushRemoteFeedWithoutMetadata(stream) {
|
699
|
-
var _this$feeds$find;
|
700
|
-
var userId = this.getOpponentMember().userId;
|
701
|
-
// We can guess the purpose here since the other client can only send one stream
|
702
|
-
var purpose = SDPStreamMetadataPurpose.Usermedia;
|
703
|
-
var oldRemoteStream = (_this$feeds$find = this.feeds.find(feed => !feed.isLocal())) === null || _this$feeds$find === void 0 ? void 0 : _this$feeds$find.stream;
|
704
|
-
|
705
|
-
// Note that we check by ID and always set the remote stream: Chrome appears
|
706
|
-
// to make new stream objects when transceiver directionality is changed and the 'active'
|
707
|
-
// status of streams change - Dave
|
708
|
-
// If we already have a stream, check this stream has the same id
|
709
|
-
if (oldRemoteStream && stream.id !== oldRemoteStream.id) {
|
710
|
-
logger.warn("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() ignoring new stream because we already have stream (streamId=").concat(stream.id, ")"));
|
711
|
-
return;
|
712
|
-
}
|
713
|
-
if (this.getFeedByStreamId(stream.id)) {
|
714
|
-
logger.warn("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
|
715
|
-
return;
|
716
|
-
}
|
717
|
-
this.feeds.push(new CallFeed({
|
718
|
-
client: this.client,
|
719
|
-
call: this,
|
720
|
-
roomId: this.roomId,
|
721
|
-
audioMuted: false,
|
722
|
-
videoMuted: false,
|
723
|
-
userId,
|
724
|
-
deviceId: this.getOpponentDeviceId(),
|
725
|
-
stream,
|
726
|
-
purpose
|
727
|
-
}));
|
728
|
-
this.emit(CallEvent.FeedsChanged, this.feeds, this);
|
729
|
-
logger.info("Call ".concat(this.callId, " pushRemoteFeedWithoutMetadata() pushed stream (streamId=").concat(stream.id, ", active=").concat(stream.active, ")"));
|
730
|
-
}
|
731
|
-
pushNewLocalFeed(stream, purpose) {
|
732
|
-
var addToPeerConnection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
733
|
-
var userId = this.client.getUserId();
|
734
|
-
|
735
|
-
// Tracks don't always start off enabled, eg. chrome will give a disabled
|
736
|
-
// audio track if you ask for user media audio and already had one that
|
737
|
-
// you'd set to disabled (presumably because it clones them internally).
|
738
|
-
setTracksEnabled(stream.getAudioTracks(), true);
|
739
|
-
setTracksEnabled(stream.getVideoTracks(), true);
|
740
|
-
if (this.getFeedByStreamId(stream.id)) {
|
741
|
-
logger.warn("Call ".concat(this.callId, " pushNewLocalFeed() ignoring stream because we already have a feed for it (streamId=").concat(stream.id, ")"));
|
742
|
-
return;
|
743
|
-
}
|
744
|
-
this.pushLocalFeed(new CallFeed({
|
745
|
-
client: this.client,
|
746
|
-
roomId: this.roomId,
|
747
|
-
audioMuted: false,
|
748
|
-
videoMuted: false,
|
749
|
-
userId,
|
750
|
-
deviceId: this.getOpponentDeviceId(),
|
751
|
-
stream,
|
752
|
-
purpose
|
753
|
-
}), addToPeerConnection);
|
754
|
-
}
|
755
|
-
|
756
|
-
/**
|
757
|
-
* Pushes supplied feed to the call
|
758
|
-
* @param callFeed - to push
|
759
|
-
* @param addToPeerConnection - whether to add the tracks to the peer connection
|
760
|
-
*/
|
761
|
-
pushLocalFeed(callFeed) {
|
762
|
-
var _this5 = this;
|
763
|
-
var addToPeerConnection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
764
|
-
if (this.feeds.some(feed => callFeed.stream.id === feed.stream.id)) {
|
765
|
-
logger.info("Call ".concat(this.callId, " pushLocalFeed() ignoring duplicate local stream (streamId=").concat(callFeed.stream.id, ")"));
|
766
|
-
return;
|
767
|
-
}
|
768
|
-
this.feeds.push(callFeed);
|
769
|
-
if (addToPeerConnection) {
|
770
|
-
var _loop = function _loop() {
|
771
|
-
logger.info("Call ".concat(_this5.callId, " pushLocalFeed() adding track to peer connection (id=").concat(track.id, ", kind=").concat(track.kind, ", streamId=").concat(callFeed.stream.id, ", streamPurpose=").concat(callFeed.purpose, ", enabled=").concat(track.enabled, ")"));
|
772
|
-
var tKey = getTransceiverKey(callFeed.purpose, track.kind);
|
773
|
-
if (_this5.transceivers.has(tKey)) {
|
774
|
-
// we already have a sender, so we re-use it. We try to re-use transceivers as much
|
775
|
-
// as possible because they can't be removed once added, so otherwise they just
|
776
|
-
// accumulate which makes the SDP very large very quickly: in fact it only takes
|
777
|
-
// about 6 video tracks to exceed the maximum size of an Olm-encrypted
|
778
|
-
// Matrix event.
|
779
|
-
var transceiver = _this5.transceivers.get(tKey);
|
780
|
-
transceiver.sender.replaceTrack(track);
|
781
|
-
// set the direction to indicate we're going to start sending again
|
782
|
-
// (this will trigger the re-negotiation)
|
783
|
-
transceiver.direction = transceiver.direction === "inactive" ? "sendonly" : "sendrecv";
|
784
|
-
} else {
|
785
|
-
// create a new one. We need to use addTrack rather addTransceiver for this because firefox
|
786
|
-
// doesn't yet implement RTCRTPSender.setStreams()
|
787
|
-
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1510802) so we'd have no way to group the
|
788
|
-
// two tracks together into a stream.
|
789
|
-
var newSender = _this5.peerConn.addTrack(track, callFeed.stream);
|
790
|
-
|
791
|
-
// now go & fish for the new transceiver
|
792
|
-
var newTransceiver = _this5.peerConn.getTransceivers().find(t => t.sender === newSender);
|
793
|
-
if (newTransceiver) {
|
794
|
-
_this5.transceivers.set(tKey, newTransceiver);
|
795
|
-
} else {
|
796
|
-
logger.warn("Call ".concat(_this5.callId, " pushLocalFeed() didn't find a matching transceiver after adding track!"));
|
797
|
-
}
|
798
|
-
}
|
799
|
-
};
|
800
|
-
for (var track of callFeed.stream.getTracks()) {
|
801
|
-
_loop();
|
802
|
-
}
|
803
|
-
}
|
804
|
-
logger.info("Call ".concat(this.callId, " pushLocalFeed() pushed stream (id=").concat(callFeed.stream.id, ", active=").concat(callFeed.stream.active, ", purpose=").concat(callFeed.purpose, ")"));
|
805
|
-
this.emit(CallEvent.FeedsChanged, this.feeds, this);
|
806
|
-
}
|
807
|
-
|
808
|
-
/**
|
809
|
-
* Removes local call feed from the call and its tracks from the peer
|
810
|
-
* connection
|
811
|
-
* @param callFeed - to remove
|
812
|
-
*/
|
813
|
-
removeLocalFeed(callFeed) {
|
814
|
-
var audioTransceiverKey = getTransceiverKey(callFeed.purpose, "audio");
|
815
|
-
var videoTransceiverKey = getTransceiverKey(callFeed.purpose, "video");
|
816
|
-
for (var transceiverKey of [audioTransceiverKey, videoTransceiverKey]) {
|
817
|
-
// this is slightly mixing the track and transceiver API but is basically just shorthand.
|
818
|
-
// There is no way to actually remove a transceiver, so this just sets it to inactive
|
819
|
-
// (or recvonly) and replaces the source with nothing.
|
820
|
-
if (this.transceivers.has(transceiverKey)) {
|
821
|
-
var transceiver = this.transceivers.get(transceiverKey);
|
822
|
-
if (transceiver.sender) this.peerConn.removeTrack(transceiver.sender);
|
823
|
-
}
|
824
|
-
}
|
825
|
-
if (callFeed.purpose === SDPStreamMetadataPurpose.Screenshare) {
|
826
|
-
this.client.getMediaHandler().stopScreensharingStream(callFeed.stream);
|
827
|
-
}
|
828
|
-
this.deleteFeed(callFeed);
|
829
|
-
}
|
830
|
-
deleteAllFeeds() {
|
831
|
-
for (var feed of this.feeds) {
|
832
|
-
if (!feed.isLocal() || !this.groupCallId) {
|
833
|
-
feed.dispose();
|
834
|
-
}
|
835
|
-
}
|
836
|
-
this.feeds = [];
|
837
|
-
this.emit(CallEvent.FeedsChanged, this.feeds, this);
|
838
|
-
}
|
839
|
-
deleteFeedByStream(stream) {
|
840
|
-
var feed = this.getFeedByStreamId(stream.id);
|
841
|
-
if (!feed) {
|
842
|
-
logger.warn("Call ".concat(this.callId, " deleteFeedByStream() didn't find the feed to delete (streamId=").concat(stream.id, ")"));
|
843
|
-
return;
|
844
|
-
}
|
845
|
-
this.deleteFeed(feed);
|
846
|
-
}
|
847
|
-
deleteFeed(feed) {
|
848
|
-
feed.dispose();
|
849
|
-
this.feeds.splice(this.feeds.indexOf(feed), 1);
|
850
|
-
this.emit(CallEvent.FeedsChanged, this.feeds, this);
|
851
|
-
}
|
852
|
-
|
853
|
-
// The typescript definitions have this type as 'any' :(
|
854
|
-
getCurrentCallStats() {
|
855
|
-
var _this6 = this;
|
856
|
-
return _asyncToGenerator(function* () {
|
857
|
-
if (_this6.callHasEnded()) {
|
858
|
-
return _this6.callStatsAtEnd;
|
859
|
-
}
|
860
|
-
return _this6.collectCallStats();
|
861
|
-
})();
|
862
|
-
}
|
863
|
-
collectCallStats() {
|
864
|
-
var _this7 = this;
|
865
|
-
return _asyncToGenerator(function* () {
|
866
|
-
// This happens when the call fails before it starts.
|
867
|
-
// For example when we fail to get capture sources
|
868
|
-
if (!_this7.peerConn) return;
|
869
|
-
var statsReport = yield _this7.peerConn.getStats();
|
870
|
-
var stats = [];
|
871
|
-
statsReport.forEach(item => {
|
872
|
-
stats.push(item);
|
873
|
-
});
|
874
|
-
return stats;
|
875
|
-
})();
|
876
|
-
}
|
877
|
-
|
878
|
-
/**
|
879
|
-
* Configure this call from an invite event. Used by MatrixClient.
|
880
|
-
* @param event - The m.call.invite event
|
881
|
-
*/
|
882
|
-
initWithInvite(event) {
|
883
|
-
var _this8 = this;
|
884
|
-
return _asyncToGenerator(function* () {
|
885
|
-
var _this8$feeds$find;
|
886
|
-
var invite = event.getContent();
|
887
|
-
_this8.direction = CallDirection.Inbound;
|
888
|
-
|
889
|
-
// make sure we have valid turn creds. Unless something's gone wrong, it should
|
890
|
-
// poll and keep the credentials valid so this should be instant.
|
891
|
-
var haveTurnCreds = yield _this8.client.checkTurnServers();
|
892
|
-
if (!haveTurnCreds) {
|
893
|
-
logger.warn("Call ".concat(_this8.callId, " initWithInvite() failed to get TURN credentials! Proceeding with call anyway..."));
|
894
|
-
}
|
895
|
-
var sdpStreamMetadata = invite[SDPStreamMetadataKey];
|
896
|
-
if (sdpStreamMetadata) {
|
897
|
-
_this8.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
898
|
-
} else {
|
899
|
-
logger.debug("Call ".concat(_this8.callId, " initWithInvite() did not get any SDPStreamMetadata! Can not send/receive multiple streams"));
|
900
|
-
}
|
901
|
-
_this8.peerConn = _this8.createPeerConnection();
|
902
|
-
_this8.emit(CallEvent.PeerConnectionCreated, _this8.peerConn, _this8);
|
903
|
-
// we must set the party ID before await-ing on anything: the call event
|
904
|
-
// handler will start giving us more call events (eg. candidates) so if
|
905
|
-
// we haven't set the party ID, we'll ignore them.
|
906
|
-
_this8.chooseOpponent(event);
|
907
|
-
yield _this8.initOpponentCrypto();
|
908
|
-
try {
|
909
|
-
yield _this8.peerConn.setRemoteDescription(invite.offer);
|
910
|
-
logger.debug("Call ".concat(_this8.callId, " initWithInvite() set remote description: ").concat(invite.offer.type));
|
911
|
-
yield _this8.addBufferedIceCandidates();
|
912
|
-
} catch (e) {
|
913
|
-
logger.debug("Call ".concat(_this8.callId, " initWithInvite() failed to set remote description"), e);
|
914
|
-
_this8.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
|
915
|
-
return;
|
916
|
-
}
|
917
|
-
var remoteStream = (_this8$feeds$find = _this8.feeds.find(feed => !feed.isLocal())) === null || _this8$feeds$find === void 0 ? void 0 : _this8$feeds$find.stream;
|
918
|
-
|
919
|
-
// According to previous comments in this file, firefox at some point did not
|
920
|
-
// add streams until media started arriving on them. Testing latest firefox
|
921
|
-
// (81 at time of writing), this is no longer a problem, so let's do it the correct way.
|
922
|
-
//
|
923
|
-
// For example in case of no media webrtc connections like screen share only call we have to allow webrtc
|
924
|
-
// connections without remote media. In this case we always use a data channel. At the moment we allow as well
|
925
|
-
// only data channel as media in the WebRTC connection with this setup here.
|
926
|
-
if (!_this8.isOnlyDataChannelAllowed && (!remoteStream || remoteStream.getTracks().length === 0)) {
|
927
|
-
logger.error("Call ".concat(_this8.callId, " initWithInvite() no remote stream or no tracks after setting remote description!"));
|
928
|
-
_this8.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
|
929
|
-
return;
|
930
|
-
}
|
931
|
-
_this8.state = CallState.Ringing;
|
932
|
-
if (event.getLocalAge()) {
|
933
|
-
// Time out the call if it's ringing for too long
|
934
|
-
var ringingTimer = setTimeout(() => {
|
935
|
-
if (_this8.state == CallState.Ringing) {
|
936
|
-
var _this8$stats;
|
937
|
-
logger.debug("Call ".concat(_this8.callId, " initWithInvite() invite has expired. Hanging up."));
|
938
|
-
_this8.hangupParty = CallParty.Remote; // effectively
|
939
|
-
_this8.state = CallState.Ended;
|
940
|
-
_this8.stopAllMedia();
|
941
|
-
if (_this8.peerConn.signalingState != "closed") {
|
942
|
-
_this8.peerConn.close();
|
943
|
-
}
|
944
|
-
(_this8$stats = _this8.stats) === null || _this8$stats === void 0 || _this8$stats.removeStatsReportGatherer(_this8.callId);
|
945
|
-
_this8.emit(CallEvent.Hangup, _this8);
|
946
|
-
}
|
947
|
-
}, invite.lifetime - event.getLocalAge());
|
948
|
-
var onState = state => {
|
949
|
-
if (state !== CallState.Ringing) {
|
950
|
-
clearTimeout(ringingTimer);
|
951
|
-
_this8.off(CallEvent.State, onState);
|
952
|
-
}
|
953
|
-
};
|
954
|
-
_this8.on(CallEvent.State, onState);
|
955
|
-
}
|
956
|
-
})();
|
957
|
-
}
|
958
|
-
|
959
|
-
/**
|
960
|
-
* Configure this call from a hangup or reject event. Used by MatrixClient.
|
961
|
-
* @param event - The m.call.hangup event
|
962
|
-
*/
|
963
|
-
initWithHangup(event) {
|
964
|
-
// perverse as it may seem, sometimes we want to instantiate a call with a
|
965
|
-
// hangup message (because when getting the state of the room on load, events
|
966
|
-
// come in reverse order and we want to remember that a call has been hung up)
|
967
|
-
this.state = CallState.Ended;
|
968
|
-
}
|
969
|
-
shouldAnswerWithMediaType(wantedValue, valueOfTheOtherSide, type) {
|
970
|
-
if (wantedValue && !valueOfTheOtherSide) {
|
971
|
-
// TODO: Figure out how to do this
|
972
|
-
logger.warn("Call ".concat(this.callId, " shouldAnswerWithMediaType() unable to answer with ").concat(type, " because the other side isn't sending it either."));
|
973
|
-
return false;
|
974
|
-
} else if (!isNullOrUndefined(wantedValue) && wantedValue !== valueOfTheOtherSide && !this.opponentSupportsSDPStreamMetadata()) {
|
975
|
-
logger.warn("Call ".concat(this.callId, " shouldAnswerWithMediaType() unable to answer with ").concat(type, "=").concat(wantedValue, " because the other side doesn't support it. Answering with ").concat(type, "=").concat(valueOfTheOtherSide, "."));
|
976
|
-
return valueOfTheOtherSide;
|
977
|
-
}
|
978
|
-
return wantedValue !== null && wantedValue !== void 0 ? wantedValue : valueOfTheOtherSide;
|
979
|
-
}
|
980
|
-
|
981
|
-
/**
|
982
|
-
* Answer a call.
|
983
|
-
*/
|
984
|
-
answer(audio, video) {
|
985
|
-
var _this9 = this;
|
986
|
-
return _asyncToGenerator(function* () {
|
987
|
-
if (_this9.inviteOrAnswerSent) return;
|
988
|
-
// TODO: Figure out how to do this
|
989
|
-
if (audio === false && video === false) throw new Error("You CANNOT answer a call without media");
|
990
|
-
if (!_this9.localUsermediaStream && !_this9.waitForLocalAVStream) {
|
991
|
-
var prevState = _this9.state;
|
992
|
-
var answerWithAudio = _this9.shouldAnswerWithMediaType(audio, _this9.hasRemoteUserMediaAudioTrack, "audio");
|
993
|
-
var answerWithVideo = _this9.shouldAnswerWithMediaType(video, _this9.hasRemoteUserMediaVideoTrack, "video");
|
994
|
-
_this9.state = CallState.WaitLocalMedia;
|
995
|
-
_this9.waitForLocalAVStream = true;
|
996
|
-
try {
|
997
|
-
var _this9$client$getDevi;
|
998
|
-
var stream = yield _this9.client.getMediaHandler().getUserMediaStream(answerWithAudio, answerWithVideo);
|
999
|
-
_this9.waitForLocalAVStream = false;
|
1000
|
-
var usermediaFeed = new CallFeed({
|
1001
|
-
client: _this9.client,
|
1002
|
-
roomId: _this9.roomId,
|
1003
|
-
userId: _this9.client.getUserId(),
|
1004
|
-
deviceId: (_this9$client$getDevi = _this9.client.getDeviceId()) !== null && _this9$client$getDevi !== void 0 ? _this9$client$getDevi : undefined,
|
1005
|
-
stream,
|
1006
|
-
purpose: SDPStreamMetadataPurpose.Usermedia,
|
1007
|
-
audioMuted: false,
|
1008
|
-
videoMuted: false
|
1009
|
-
});
|
1010
|
-
var feeds = [usermediaFeed];
|
1011
|
-
if (_this9.localScreensharingFeed) {
|
1012
|
-
feeds.push(_this9.localScreensharingFeed);
|
1013
|
-
}
|
1014
|
-
_this9.answerWithCallFeeds(feeds);
|
1015
|
-
} catch (e) {
|
1016
|
-
if (answerWithVideo) {
|
1017
|
-
// Try to answer without video
|
1018
|
-
logger.warn("Call ".concat(_this9.callId, " answer() failed to getUserMedia(), trying to getUserMedia() without video"));
|
1019
|
-
_this9.state = prevState;
|
1020
|
-
_this9.waitForLocalAVStream = false;
|
1021
|
-
yield _this9.answer(answerWithAudio, false);
|
1022
|
-
} else {
|
1023
|
-
_this9.getUserMediaFailed(e);
|
1024
|
-
return;
|
1025
|
-
}
|
1026
|
-
}
|
1027
|
-
} else if (_this9.waitForLocalAVStream) {
|
1028
|
-
_this9.state = CallState.WaitLocalMedia;
|
1029
|
-
}
|
1030
|
-
})();
|
1031
|
-
}
|
1032
|
-
answerWithCallFeeds(callFeeds) {
|
1033
|
-
if (this.inviteOrAnswerSent) return;
|
1034
|
-
this.queueGotCallFeedsForAnswer(callFeeds);
|
1035
|
-
}
|
1036
|
-
|
1037
|
-
/**
|
1038
|
-
* Replace this call with a new call, e.g. for glare resolution. Used by
|
1039
|
-
* MatrixClient.
|
1040
|
-
* @param newCall - The new call.
|
1041
|
-
*/
|
1042
|
-
replacedBy(newCall) {
|
1043
|
-
logger.debug("Call ".concat(this.callId, " replacedBy() running (newCallId=").concat(newCall.callId, ")"));
|
1044
|
-
if (this.state === CallState.WaitLocalMedia) {
|
1045
|
-
logger.debug("Call ".concat(this.callId, " replacedBy() telling new call to wait for local media (newCallId=").concat(newCall.callId, ")"));
|
1046
|
-
newCall.waitForLocalAVStream = true;
|
1047
|
-
} else if ([CallState.CreateOffer, CallState.InviteSent].includes(this.state)) {
|
1048
|
-
if (newCall.direction === CallDirection.Outbound) {
|
1049
|
-
newCall.queueGotCallFeedsForAnswer([]);
|
1050
|
-
} else {
|
1051
|
-
logger.debug("Call ".concat(this.callId, " replacedBy() handing local stream to new call(newCallId=").concat(newCall.callId, ")"));
|
1052
|
-
newCall.queueGotCallFeedsForAnswer(this.getLocalFeeds().map(feed => feed.clone()));
|
1053
|
-
}
|
1054
|
-
}
|
1055
|
-
this.successor = newCall;
|
1056
|
-
this.emit(CallEvent.Replaced, newCall, this);
|
1057
|
-
this.hangup(CallErrorCode.Replaced, true);
|
1058
|
-
}
|
1059
|
-
|
1060
|
-
/**
|
1061
|
-
* Hangup a call.
|
1062
|
-
* @param reason - The reason why the call is being hung up.
|
1063
|
-
* @param suppressEvent - True to suppress emitting an event.
|
1064
|
-
*/
|
1065
|
-
hangup(reason, suppressEvent) {
|
1066
|
-
if (this.callHasEnded()) return;
|
1067
|
-
logger.debug("Call ".concat(this.callId, " hangup() ending call (reason=").concat(reason, ")"));
|
1068
|
-
this.terminate(CallParty.Local, reason, !suppressEvent);
|
1069
|
-
// We don't want to send hangup here if we didn't even get to sending an invite
|
1070
|
-
if ([CallState.Fledgling, CallState.WaitLocalMedia].includes(this.state)) return;
|
1071
|
-
var content = {};
|
1072
|
-
// Don't send UserHangup reason to older clients
|
1073
|
-
if (this.opponentVersion && this.opponentVersion !== 0 || reason !== CallErrorCode.UserHangup) {
|
1074
|
-
content["reason"] = reason;
|
1075
|
-
}
|
1076
|
-
this.sendVoipEvent(EventType.CallHangup, content);
|
1077
|
-
}
|
1078
|
-
|
1079
|
-
/**
|
1080
|
-
* Reject a call
|
1081
|
-
* This used to be done by calling hangup, but is a separate method and protocol
|
1082
|
-
* event as of MSC2746.
|
1083
|
-
*/
|
1084
|
-
reject() {
|
1085
|
-
if (this.state !== CallState.Ringing) {
|
1086
|
-
throw Error("Call must be in 'ringing' state to reject!");
|
1087
|
-
}
|
1088
|
-
if (this.opponentVersion === 0) {
|
1089
|
-
logger.info("Call ".concat(this.callId, " reject() opponent version is less than 1: sending hangup instead of reject (opponentVersion=").concat(this.opponentVersion, ")"));
|
1090
|
-
this.hangup(CallErrorCode.UserHangup, true);
|
1091
|
-
return;
|
1092
|
-
}
|
1093
|
-
logger.debug("Rejecting call: " + this.callId);
|
1094
|
-
this.terminate(CallParty.Local, CallErrorCode.UserHangup, true);
|
1095
|
-
this.sendVoipEvent(EventType.CallReject, {});
|
1096
|
-
}
|
1097
|
-
|
1098
|
-
/**
|
1099
|
-
* Adds an audio and/or video track - upgrades the call
|
1100
|
-
* @param audio - should add an audio track
|
1101
|
-
* @param video - should add an video track
|
1102
|
-
*/
|
1103
|
-
upgradeCall(audio, video) {
|
1104
|
-
var _this10 = this;
|
1105
|
-
return _asyncToGenerator(function* () {
|
1106
|
-
// We don't do call downgrades
|
1107
|
-
if (!audio && !video) return;
|
1108
|
-
if (!_this10.opponentSupportsSDPStreamMetadata()) return;
|
1109
|
-
try {
|
1110
|
-
logger.debug("Call ".concat(_this10.callId, " upgradeCall() upgrading call (audio=").concat(audio, ", video=").concat(video, ")"));
|
1111
|
-
var getAudio = audio || _this10.hasLocalUserMediaAudioTrack;
|
1112
|
-
var getVideo = video || _this10.hasLocalUserMediaVideoTrack;
|
1113
|
-
|
1114
|
-
// updateLocalUsermediaStream() will take the tracks, use them as
|
1115
|
-
// replacement and throw the stream away, so it isn't reusable
|
1116
|
-
var stream = yield _this10.client.getMediaHandler().getUserMediaStream(getAudio, getVideo, false);
|
1117
|
-
yield _this10.updateLocalUsermediaStream(stream, audio, video);
|
1118
|
-
} catch (error) {
|
1119
|
-
logger.error("Call ".concat(_this10.callId, " upgradeCall() failed to upgrade the call"), error);
|
1120
|
-
_this10.emit(CallEvent.Error, new CallError(CallErrorCode.NoUserMedia, "Failed to get camera access: ", error), _this10);
|
1121
|
-
}
|
1122
|
-
})();
|
1123
|
-
}
|
1124
|
-
|
1125
|
-
/**
|
1126
|
-
* Returns true if this.remoteSDPStreamMetadata is defined, otherwise returns false
|
1127
|
-
* @returns can screenshare
|
1128
|
-
*/
|
1129
|
-
opponentSupportsSDPStreamMetadata() {
|
1130
|
-
return Boolean(this.remoteSDPStreamMetadata);
|
1131
|
-
}
|
1132
|
-
|
1133
|
-
/**
|
1134
|
-
* If there is a screensharing stream returns true, otherwise returns false
|
1135
|
-
* @returns is screensharing
|
1136
|
-
*/
|
1137
|
-
isScreensharing() {
|
1138
|
-
return Boolean(this.localScreensharingStream);
|
1139
|
-
}
|
1140
|
-
|
1141
|
-
/**
|
1142
|
-
* Starts/stops screensharing
|
1143
|
-
* @param enabled - the desired screensharing state
|
1144
|
-
* @param opts - screen sharing options
|
1145
|
-
* @returns new screensharing state
|
1146
|
-
*/
|
1147
|
-
setScreensharingEnabled(enabled, opts) {
|
1148
|
-
var _this11 = this;
|
1149
|
-
return _asyncToGenerator(function* () {
|
1150
|
-
// Skip if there is nothing to do
|
1151
|
-
if (enabled && _this11.isScreensharing()) {
|
1152
|
-
logger.warn("Call ".concat(_this11.callId, " setScreensharingEnabled() there is already a screensharing stream - there is nothing to do!"));
|
1153
|
-
return true;
|
1154
|
-
} else if (!enabled && !_this11.isScreensharing()) {
|
1155
|
-
logger.warn("Call ".concat(_this11.callId, " setScreensharingEnabled() there already isn't a screensharing stream - there is nothing to do!"));
|
1156
|
-
return false;
|
1157
|
-
}
|
1158
|
-
|
1159
|
-
// Fallback to replaceTrack()
|
1160
|
-
if (!_this11.opponentSupportsSDPStreamMetadata()) {
|
1161
|
-
return _this11.setScreensharingEnabledWithoutMetadataSupport(enabled, opts);
|
1162
|
-
}
|
1163
|
-
logger.debug("Call ".concat(_this11.callId, " setScreensharingEnabled() running (enabled=").concat(enabled, ")"));
|
1164
|
-
if (enabled) {
|
1165
|
-
try {
|
1166
|
-
var stream = yield _this11.client.getMediaHandler().getScreensharingStream(opts);
|
1167
|
-
if (!stream) return false;
|
1168
|
-
_this11.pushNewLocalFeed(stream, SDPStreamMetadataPurpose.Screenshare);
|
1169
|
-
return true;
|
1170
|
-
} catch (err) {
|
1171
|
-
logger.error("Call ".concat(_this11.callId, " setScreensharingEnabled() failed to get screen-sharing stream:"), err);
|
1172
|
-
return false;
|
1173
|
-
}
|
1174
|
-
} else {
|
1175
|
-
var audioTransceiver = _this11.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "audio"));
|
1176
|
-
var videoTransceiver = _this11.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"));
|
1177
|
-
for (var transceiver of [audioTransceiver, videoTransceiver]) {
|
1178
|
-
// this is slightly mixing the track and transceiver API but is basically just shorthand
|
1179
|
-
// for removing the sender.
|
1180
|
-
if (transceiver && transceiver.sender) _this11.peerConn.removeTrack(transceiver.sender);
|
1181
|
-
}
|
1182
|
-
_this11.client.getMediaHandler().stopScreensharingStream(_this11.localScreensharingStream);
|
1183
|
-
_this11.deleteFeedByStream(_this11.localScreensharingStream);
|
1184
|
-
return false;
|
1185
|
-
}
|
1186
|
-
})();
|
1187
|
-
}
|
1188
|
-
|
1189
|
-
/**
|
1190
|
-
* Starts/stops screensharing
|
1191
|
-
* Should be used ONLY if the opponent doesn't support SDPStreamMetadata
|
1192
|
-
* @param enabled - the desired screensharing state
|
1193
|
-
* @param opts - screen sharing options
|
1194
|
-
* @returns new screensharing state
|
1195
|
-
*/
|
1196
|
-
setScreensharingEnabledWithoutMetadataSupport(enabled, opts) {
|
1197
|
-
var _this12 = this;
|
1198
|
-
return _asyncToGenerator(function* () {
|
1199
|
-
logger.debug("Call ".concat(_this12.callId, " setScreensharingEnabledWithoutMetadataSupport() running (enabled=").concat(enabled, ")"));
|
1200
|
-
if (enabled) {
|
1201
|
-
try {
|
1202
|
-
var _this12$transceivers$;
|
1203
|
-
var stream = yield _this12.client.getMediaHandler().getScreensharingStream(opts);
|
1204
|
-
if (!stream) return false;
|
1205
|
-
var track = stream.getTracks().find(track => track.kind === "video");
|
1206
|
-
var sender = (_this12$transceivers$ = _this12.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this12$transceivers$ === void 0 ? void 0 : _this12$transceivers$.sender;
|
1207
|
-
sender === null || sender === void 0 || sender.replaceTrack(track !== null && track !== void 0 ? track : null);
|
1208
|
-
_this12.pushNewLocalFeed(stream, SDPStreamMetadataPurpose.Screenshare, false);
|
1209
|
-
return true;
|
1210
|
-
} catch (err) {
|
1211
|
-
logger.error("Call ".concat(_this12.callId, " setScreensharingEnabledWithoutMetadataSupport() failed to get screen-sharing stream:"), err);
|
1212
|
-
return false;
|
1213
|
-
}
|
1214
|
-
} else {
|
1215
|
-
var _this12$localUsermedi, _this12$transceivers$2;
|
1216
|
-
var _track = (_this12$localUsermedi = _this12.localUsermediaStream) === null || _this12$localUsermedi === void 0 ? void 0 : _this12$localUsermedi.getTracks().find(track => track.kind === "video");
|
1217
|
-
var _sender = (_this12$transceivers$2 = _this12.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, "video"))) === null || _this12$transceivers$2 === void 0 ? void 0 : _this12$transceivers$2.sender;
|
1218
|
-
_sender === null || _sender === void 0 || _sender.replaceTrack(_track !== null && _track !== void 0 ? _track : null);
|
1219
|
-
_this12.client.getMediaHandler().stopScreensharingStream(_this12.localScreensharingStream);
|
1220
|
-
_this12.deleteFeedByStream(_this12.localScreensharingStream);
|
1221
|
-
return false;
|
1222
|
-
}
|
1223
|
-
})();
|
1224
|
-
}
|
1225
|
-
|
1226
|
-
/**
|
1227
|
-
* Replaces/adds the tracks from the passed stream to the localUsermediaStream
|
1228
|
-
* @param stream - to use a replacement for the local usermedia stream
|
1229
|
-
*/
|
1230
|
-
updateLocalUsermediaStream(stream) {
|
1231
|
-
var _arguments = arguments,
|
1232
|
-
_this13 = this;
|
1233
|
-
return _asyncToGenerator(function* () {
|
1234
|
-
var forceAudio = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : false;
|
1235
|
-
var forceVideo = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : false;
|
1236
|
-
var callFeed = _this13.localUsermediaFeed;
|
1237
|
-
var audioEnabled = forceAudio || !callFeed.isAudioMuted() && !_this13.remoteOnHold;
|
1238
|
-
var videoEnabled = forceVideo || !callFeed.isVideoMuted() && !_this13.remoteOnHold;
|
1239
|
-
logger.log("Call ".concat(_this13.callId, " updateLocalUsermediaStream() running (streamId=").concat(stream.id, ", audio=").concat(audioEnabled, ", video=").concat(videoEnabled, ")"));
|
1240
|
-
setTracksEnabled(stream.getAudioTracks(), audioEnabled);
|
1241
|
-
setTracksEnabled(stream.getVideoTracks(), videoEnabled);
|
1242
|
-
|
1243
|
-
// We want to keep the same stream id, so we replace the tracks rather
|
1244
|
-
// than the whole stream.
|
1245
|
-
|
1246
|
-
// Firstly, we replace the tracks in our localUsermediaStream.
|
1247
|
-
for (var track of _this13.localUsermediaStream.getTracks()) {
|
1248
|
-
_this13.localUsermediaStream.removeTrack(track);
|
1249
|
-
track.stop();
|
1250
|
-
}
|
1251
|
-
for (var _track2 of stream.getTracks()) {
|
1252
|
-
_this13.localUsermediaStream.addTrack(_track2);
|
1253
|
-
}
|
1254
|
-
|
1255
|
-
// Then replace the old tracks, if possible.
|
1256
|
-
var _loop2 = function* _loop2() {
|
1257
|
-
var tKey = getTransceiverKey(SDPStreamMetadataPurpose.Usermedia, _track3.kind);
|
1258
|
-
var transceiver = _this13.transceivers.get(tKey);
|
1259
|
-
var oldSender = transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender;
|
1260
|
-
var added = false;
|
1261
|
-
if (oldSender) {
|
1262
|
-
try {
|
1263
|
-
logger.info("Call ".concat(_this13.callId, " updateLocalUsermediaStream() replacing track (id=").concat(_track3.id, ", kind=").concat(_track3.kind, ", streamId=").concat(stream.id, ", streamPurpose=").concat(callFeed.purpose, ")"));
|
1264
|
-
yield oldSender.replaceTrack(_track3);
|
1265
|
-
// Set the direction to indicate we're going to be sending.
|
1266
|
-
// This is only necessary in the cases where we're upgrading
|
1267
|
-
// the call to video after downgrading it.
|
1268
|
-
transceiver.direction = transceiver.direction === "inactive" ? "sendonly" : "sendrecv";
|
1269
|
-
added = true;
|
1270
|
-
} catch (error) {
|
1271
|
-
logger.warn("Call ".concat(_this13.callId, " updateLocalUsermediaStream() replaceTrack failed: adding new transceiver instead"), error);
|
1272
|
-
}
|
1273
|
-
}
|
1274
|
-
if (!added) {
|
1275
|
-
logger.info("Call ".concat(_this13.callId, " updateLocalUsermediaStream() adding track to peer connection (id=").concat(_track3.id, ", kind=").concat(_track3.kind, ", streamId=").concat(stream.id, ", streamPurpose=").concat(callFeed.purpose, ")"));
|
1276
|
-
var newSender = _this13.peerConn.addTrack(_track3, _this13.localUsermediaStream);
|
1277
|
-
var newTransceiver = _this13.peerConn.getTransceivers().find(t => t.sender === newSender);
|
1278
|
-
if (newTransceiver) {
|
1279
|
-
_this13.transceivers.set(tKey, newTransceiver);
|
1280
|
-
} else {
|
1281
|
-
logger.warn("Call ".concat(_this13.callId, " updateLocalUsermediaStream() couldn't find matching transceiver for newly added track!"));
|
1282
|
-
}
|
1283
|
-
}
|
1284
|
-
};
|
1285
|
-
for (var _track3 of stream.getTracks()) {
|
1286
|
-
yield* _loop2();
|
1287
|
-
}
|
1288
|
-
})();
|
1289
|
-
}
|
1290
|
-
|
1291
|
-
/**
|
1292
|
-
* Set whether our outbound video should be muted or not.
|
1293
|
-
* @param muted - True to mute the outbound video.
|
1294
|
-
* @returns the new mute state
|
1295
|
-
*/
|
1296
|
-
setLocalVideoMuted(muted) {
|
1297
|
-
var _this14 = this;
|
1298
|
-
return _asyncToGenerator(function* () {
|
1299
|
-
var _this14$localUsermedi2;
|
1300
|
-
logger.log("Call ".concat(_this14.callId, " setLocalVideoMuted() running ").concat(muted));
|
1301
|
-
|
1302
|
-
// if we were still thinking about stopping and removing the video
|
1303
|
-
// track: don't, because we want it back.
|
1304
|
-
if (!muted && _this14.stopVideoTrackTimer !== undefined) {
|
1305
|
-
clearTimeout(_this14.stopVideoTrackTimer);
|
1306
|
-
_this14.stopVideoTrackTimer = undefined;
|
1307
|
-
}
|
1308
|
-
if (!(yield _this14.client.getMediaHandler().hasVideoDevice())) {
|
1309
|
-
return _this14.isLocalVideoMuted();
|
1310
|
-
}
|
1311
|
-
if (!_this14.hasUserMediaVideoSender && !muted) {
|
1312
|
-
var _this14$localUsermedi;
|
1313
|
-
(_this14$localUsermedi = _this14.localUsermediaFeed) === null || _this14$localUsermedi === void 0 || _this14$localUsermedi.setAudioVideoMuted(null, muted);
|
1314
|
-
yield _this14.upgradeCall(false, true);
|
1315
|
-
return _this14.isLocalVideoMuted();
|
1316
|
-
}
|
1317
|
-
|
1318
|
-
// we may not have a video track - if not, re-request usermedia
|
1319
|
-
if (!muted && _this14.localUsermediaStream.getVideoTracks().length === 0) {
|
1320
|
-
var stream = yield _this14.client.getMediaHandler().getUserMediaStream(true, true);
|
1321
|
-
yield _this14.updateLocalUsermediaStream(stream);
|
1322
|
-
}
|
1323
|
-
(_this14$localUsermedi2 = _this14.localUsermediaFeed) === null || _this14$localUsermedi2 === void 0 || _this14$localUsermedi2.setAudioVideoMuted(null, muted);
|
1324
|
-
_this14.updateMuteStatus();
|
1325
|
-
yield _this14.sendMetadataUpdate();
|
1326
|
-
|
1327
|
-
// if we're muting video, set a timeout to stop & remove the video track so we release
|
1328
|
-
// the camera. We wait a short time to do this because when we disable a track, WebRTC
|
1329
|
-
// will send black video for it. If we just stop and remove it straight away, the video
|
1330
|
-
// will just freeze which means that when we unmute video, the other side will briefly
|
1331
|
-
// get a static frame of us from before we muted. This way, the still frame is just black.
|
1332
|
-
// A very small delay is not always enough so the theory here is that it needs to be long
|
1333
|
-
// enough for WebRTC to encode a frame: 120ms should be long enough even if we're only
|
1334
|
-
// doing 10fps.
|
1335
|
-
if (muted) {
|
1336
|
-
_this14.stopVideoTrackTimer = setTimeout(() => {
|
1337
|
-
for (var t of _this14.localUsermediaStream.getVideoTracks()) {
|
1338
|
-
t.stop();
|
1339
|
-
_this14.localUsermediaStream.removeTrack(t);
|
1340
|
-
}
|
1341
|
-
}, 120);
|
1342
|
-
}
|
1343
|
-
return _this14.isLocalVideoMuted();
|
1344
|
-
})();
|
1345
|
-
}
|
1346
|
-
|
1347
|
-
/**
|
1348
|
-
* Check if local video is muted.
|
1349
|
-
*
|
1350
|
-
* If there are multiple video tracks, <i>all</i> of the tracks need to be muted
|
1351
|
-
* for this to return true. This means if there are no video tracks, this will
|
1352
|
-
* return true.
|
1353
|
-
* @returns True if the local preview video is muted, else false
|
1354
|
-
* (including if the call is not set up yet).
|
1355
|
-
*/
|
1356
|
-
isLocalVideoMuted() {
|
1357
|
-
var _this$localUsermediaF2, _this$localUsermediaF3;
|
1358
|
-
return (_this$localUsermediaF2 = (_this$localUsermediaF3 = this.localUsermediaFeed) === null || _this$localUsermediaF3 === void 0 ? void 0 : _this$localUsermediaF3.isVideoMuted()) !== null && _this$localUsermediaF2 !== void 0 ? _this$localUsermediaF2 : false;
|
1359
|
-
}
|
1360
|
-
|
1361
|
-
/**
|
1362
|
-
* Set whether the microphone should be muted or not.
|
1363
|
-
* @param muted - True to mute the mic.
|
1364
|
-
* @returns the new mute state
|
1365
|
-
*/
|
1366
|
-
setMicrophoneMuted(muted) {
|
1367
|
-
var _this15 = this;
|
1368
|
-
return _asyncToGenerator(function* () {
|
1369
|
-
var _this15$localUsermedi;
|
1370
|
-
logger.log("Call ".concat(_this15.callId, " setMicrophoneMuted() running ").concat(muted));
|
1371
|
-
if (!(yield _this15.client.getMediaHandler().hasAudioDevice())) {
|
1372
|
-
return _this15.isMicrophoneMuted();
|
1373
|
-
}
|
1374
|
-
if (!muted && (!_this15.hasUserMediaAudioSender || !_this15.hasLocalUserMediaAudioTrack)) {
|
1375
|
-
yield _this15.upgradeCall(true, false);
|
1376
|
-
return _this15.isMicrophoneMuted();
|
1377
|
-
}
|
1378
|
-
(_this15$localUsermedi = _this15.localUsermediaFeed) === null || _this15$localUsermedi === void 0 || _this15$localUsermedi.setAudioVideoMuted(muted, null);
|
1379
|
-
_this15.updateMuteStatus();
|
1380
|
-
yield _this15.sendMetadataUpdate();
|
1381
|
-
return _this15.isMicrophoneMuted();
|
1382
|
-
})();
|
1383
|
-
}
|
1384
|
-
|
1385
|
-
/**
|
1386
|
-
* Check if the microphone is muted.
|
1387
|
-
*
|
1388
|
-
* If there are multiple audio tracks, <i>all</i> of the tracks need to be muted
|
1389
|
-
* for this to return true. This means if there are no audio tracks, this will
|
1390
|
-
* return true.
|
1391
|
-
* @returns True if the mic is muted, else false (including if the call
|
1392
|
-
* is not set up yet).
|
1393
|
-
*/
|
1394
|
-
isMicrophoneMuted() {
|
1395
|
-
var _this$localUsermediaF4, _this$localUsermediaF5;
|
1396
|
-
return (_this$localUsermediaF4 = (_this$localUsermediaF5 = this.localUsermediaFeed) === null || _this$localUsermediaF5 === void 0 ? void 0 : _this$localUsermediaF5.isAudioMuted()) !== null && _this$localUsermediaF4 !== void 0 ? _this$localUsermediaF4 : false;
|
1397
|
-
}
|
1398
|
-
|
1399
|
-
/**
|
1400
|
-
* @returns true if we have put the party on the other side of the call on hold
|
1401
|
-
* (that is, we are signalling to them that we are not listening)
|
1402
|
-
*/
|
1403
|
-
isRemoteOnHold() {
|
1404
|
-
return this.remoteOnHold;
|
1405
|
-
}
|
1406
|
-
setRemoteOnHold(onHold) {
|
1407
|
-
if (this.isRemoteOnHold() === onHold) return;
|
1408
|
-
this.remoteOnHold = onHold;
|
1409
|
-
for (var transceiver of this.peerConn.getTransceivers()) {
|
1410
|
-
// We don't send hold music or anything so we're not actually
|
1411
|
-
// sending anything, but sendrecv is fairly standard for hold and
|
1412
|
-
// it makes it a lot easier to figure out who's put who on hold.
|
1413
|
-
transceiver.direction = onHold ? "sendonly" : "sendrecv";
|
1414
|
-
}
|
1415
|
-
this.updateMuteStatus();
|
1416
|
-
this.sendMetadataUpdate();
|
1417
|
-
this.emit(CallEvent.RemoteHoldUnhold, this.remoteOnHold, this);
|
1418
|
-
}
|
1419
|
-
|
1420
|
-
/**
|
1421
|
-
* Indicates whether we are 'on hold' to the remote party (ie. if true,
|
1422
|
-
* they cannot hear us).
|
1423
|
-
* @returns true if the other party has put us on hold
|
1424
|
-
*/
|
1425
|
-
isLocalOnHold() {
|
1426
|
-
if (this.state !== CallState.Connected) return false;
|
1427
|
-
var callOnHold = true;
|
1428
|
-
|
1429
|
-
// We consider a call to be on hold only if *all* the tracks are on hold
|
1430
|
-
// (is this the right thing to do?)
|
1431
|
-
for (var transceiver of this.peerConn.getTransceivers()) {
|
1432
|
-
var trackOnHold = ["inactive", "recvonly"].includes(transceiver.currentDirection);
|
1433
|
-
if (!trackOnHold) callOnHold = false;
|
1434
|
-
}
|
1435
|
-
return callOnHold;
|
1436
|
-
}
|
1437
|
-
|
1438
|
-
/**
|
1439
|
-
* Sends a DTMF digit to the other party
|
1440
|
-
* @param digit - The digit (nb. string - '#' and '*' are dtmf too)
|
1441
|
-
*/
|
1442
|
-
sendDtmfDigit(digit) {
|
1443
|
-
for (var sender of this.peerConn.getSenders()) {
|
1444
|
-
var _sender$track;
|
1445
|
-
if (((_sender$track = sender.track) === null || _sender$track === void 0 ? void 0 : _sender$track.kind) === "audio" && sender.dtmf) {
|
1446
|
-
sender.dtmf.insertDTMF(digit);
|
1447
|
-
return;
|
1448
|
-
}
|
1449
|
-
}
|
1450
|
-
throw new Error("Unable to find a track to send DTMF on");
|
1451
|
-
}
|
1452
|
-
updateMuteStatus() {
|
1453
|
-
var micShouldBeMuted = this.isMicrophoneMuted() || this.remoteOnHold;
|
1454
|
-
var vidShouldBeMuted = this.isLocalVideoMuted() || this.remoteOnHold;
|
1455
|
-
logger.log("Call ".concat(this.callId, " updateMuteStatus stream ").concat(this.localUsermediaStream.id, " micShouldBeMuted ").concat(micShouldBeMuted, " vidShouldBeMuted ").concat(vidShouldBeMuted));
|
1456
|
-
setTracksEnabled(this.localUsermediaStream.getAudioTracks(), !micShouldBeMuted);
|
1457
|
-
setTracksEnabled(this.localUsermediaStream.getVideoTracks(), !vidShouldBeMuted);
|
1458
|
-
}
|
1459
|
-
sendMetadataUpdate() {
|
1460
|
-
var _this16 = this;
|
1461
|
-
return _asyncToGenerator(function* () {
|
1462
|
-
yield _this16.sendVoipEvent(EventType.CallSDPStreamMetadataChangedPrefix, {
|
1463
|
-
[SDPStreamMetadataKey]: _this16.getLocalSDPStreamMetadata()
|
1464
|
-
});
|
1465
|
-
})();
|
1466
|
-
}
|
1467
|
-
gotCallFeedsForInvite(callFeeds) {
|
1468
|
-
var requestScreenshareFeed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
1469
|
-
if (this.successor) {
|
1470
|
-
this.successor.queueGotCallFeedsForAnswer(callFeeds);
|
1471
|
-
return;
|
1472
|
-
}
|
1473
|
-
if (this.callHasEnded()) {
|
1474
|
-
this.stopAllMedia();
|
1475
|
-
return;
|
1476
|
-
}
|
1477
|
-
for (var feed of callFeeds) {
|
1478
|
-
this.pushLocalFeed(feed);
|
1479
|
-
}
|
1480
|
-
if (requestScreenshareFeed) {
|
1481
|
-
this.peerConn.addTransceiver("video", {
|
1482
|
-
direction: "recvonly"
|
1483
|
-
});
|
1484
|
-
}
|
1485
|
-
this.state = CallState.CreateOffer;
|
1486
|
-
logger.debug("Call ".concat(this.callId, " gotUserMediaForInvite() run"));
|
1487
|
-
// Now we wait for the negotiationneeded event
|
1488
|
-
}
|
1489
|
-
sendAnswer() {
|
1490
|
-
var _this17 = this;
|
1491
|
-
return _asyncToGenerator(function* () {
|
1492
|
-
var answerContent = {
|
1493
|
-
answer: {
|
1494
|
-
sdp: _this17.peerConn.localDescription.sdp,
|
1495
|
-
// type is now deprecated as of Matrix VoIP v1, but
|
1496
|
-
// required to still be sent for backwards compat
|
1497
|
-
type: _this17.peerConn.localDescription.type
|
1498
|
-
},
|
1499
|
-
[SDPStreamMetadataKey]: _this17.getLocalSDPStreamMetadata(true)
|
1500
|
-
};
|
1501
|
-
answerContent.capabilities = {
|
1502
|
-
"m.call.transferee": _this17.client.supportsCallTransfer,
|
1503
|
-
"m.call.dtmf": false
|
1504
|
-
};
|
1505
|
-
|
1506
|
-
// We have just taken the local description from the peerConn which will
|
1507
|
-
// contain all the local candidates added so far, so we can discard any candidates
|
1508
|
-
// we had queued up because they'll be in the answer.
|
1509
|
-
var discardCount = _this17.discardDuplicateCandidates();
|
1510
|
-
logger.info("Call ".concat(_this17.callId, " sendAnswer() discarding ").concat(discardCount, " candidates that will be sent in answer"));
|
1511
|
-
try {
|
1512
|
-
yield _this17.sendVoipEvent(EventType.CallAnswer, answerContent);
|
1513
|
-
// If this isn't the first time we've tried to send the answer,
|
1514
|
-
// we may have candidates queued up, so send them now.
|
1515
|
-
_this17.inviteOrAnswerSent = true;
|
1516
|
-
} catch (error) {
|
1517
|
-
// We've failed to answer: back to the ringing state
|
1518
|
-
_this17.state = CallState.Ringing;
|
1519
|
-
if (error instanceof MatrixError && error.event) _this17.client.cancelPendingEvent(error.event);
|
1520
|
-
var code = CallErrorCode.SendAnswer;
|
1521
|
-
var message = "Failed to send answer";
|
1522
|
-
if (error.name == "UnknownDeviceError") {
|
1523
|
-
code = CallErrorCode.UnknownDevices;
|
1524
|
-
message = "Unknown devices present in the room";
|
1525
|
-
}
|
1526
|
-
_this17.emit(CallEvent.Error, new CallError(code, message, error), _this17);
|
1527
|
-
throw error;
|
1528
|
-
}
|
1529
|
-
|
1530
|
-
// error handler re-throws so this won't happen on error, but
|
1531
|
-
// we don't want the same error handling on the candidate queue
|
1532
|
-
_this17.sendCandidateQueue();
|
1533
|
-
})();
|
1534
|
-
}
|
1535
|
-
queueGotCallFeedsForAnswer(callFeeds) {
|
1536
|
-
// Ensure only one negotiate/answer event is being processed at a time.
|
1537
|
-
if (this.responsePromiseChain) {
|
1538
|
-
this.responsePromiseChain = this.responsePromiseChain.then(() => this.gotCallFeedsForAnswer(callFeeds));
|
1539
|
-
} else {
|
1540
|
-
this.responsePromiseChain = this.gotCallFeedsForAnswer(callFeeds);
|
1541
|
-
}
|
1542
|
-
}
|
1543
|
-
|
1544
|
-
// Enables DTX (discontinuous transmission) on the given session to reduce
|
1545
|
-
// bandwidth when transmitting silence
|
1546
|
-
mungeSdp(description, mods) {
|
1547
|
-
// The only way to enable DTX at this time is through SDP munging
|
1548
|
-
var sdp = parseSdp(description.sdp);
|
1549
|
-
sdp.media.forEach(media => {
|
1550
|
-
var payloadTypeToCodecMap = new Map();
|
1551
|
-
var codecToPayloadTypeMap = new Map();
|
1552
|
-
for (var rtp of media.rtp) {
|
1553
|
-
payloadTypeToCodecMap.set(rtp.payload, rtp.codec);
|
1554
|
-
codecToPayloadTypeMap.set(rtp.codec, rtp.payload);
|
1555
|
-
}
|
1556
|
-
for (var mod of mods) {
|
1557
|
-
if (mod.mediaType !== media.type) continue;
|
1558
|
-
if (!codecToPayloadTypeMap.has(mod.codec)) {
|
1559
|
-
logger.info("Call ".concat(this.callId, " mungeSdp() ignoring SDP modifications for ").concat(mod.codec, " as it's not present."));
|
1560
|
-
continue;
|
1561
|
-
}
|
1562
|
-
var extraConfig = [];
|
1563
|
-
if (mod.enableDtx !== undefined) {
|
1564
|
-
extraConfig.push("usedtx=".concat(mod.enableDtx ? "1" : "0"));
|
1565
|
-
}
|
1566
|
-
if (mod.maxAverageBitrate !== undefined) {
|
1567
|
-
extraConfig.push("maxaveragebitrate=".concat(mod.maxAverageBitrate));
|
1568
|
-
}
|
1569
|
-
var found = false;
|
1570
|
-
for (var fmtp of media.fmtp) {
|
1571
|
-
if (payloadTypeToCodecMap.get(fmtp.payload) === mod.codec) {
|
1572
|
-
found = true;
|
1573
|
-
fmtp.config += ";" + extraConfig.join(";");
|
1574
|
-
}
|
1575
|
-
}
|
1576
|
-
if (!found) {
|
1577
|
-
media.fmtp.push({
|
1578
|
-
payload: codecToPayloadTypeMap.get(mod.codec),
|
1579
|
-
config: extraConfig.join(";")
|
1580
|
-
});
|
1581
|
-
}
|
1582
|
-
}
|
1583
|
-
});
|
1584
|
-
description.sdp = writeSdp(sdp);
|
1585
|
-
}
|
1586
|
-
createOffer() {
|
1587
|
-
var _this18 = this;
|
1588
|
-
return _asyncToGenerator(function* () {
|
1589
|
-
var offer = yield _this18.peerConn.createOffer();
|
1590
|
-
_this18.mungeSdp(offer, getCodecParamMods(_this18.isPtt));
|
1591
|
-
return offer;
|
1592
|
-
})();
|
1593
|
-
}
|
1594
|
-
createAnswer() {
|
1595
|
-
var _this19 = this;
|
1596
|
-
return _asyncToGenerator(function* () {
|
1597
|
-
var answer = yield _this19.peerConn.createAnswer();
|
1598
|
-
_this19.mungeSdp(answer, getCodecParamMods(_this19.isPtt));
|
1599
|
-
return answer;
|
1600
|
-
})();
|
1601
|
-
}
|
1602
|
-
gotCallFeedsForAnswer(callFeeds) {
|
1603
|
-
var _this20 = this;
|
1604
|
-
return _asyncToGenerator(function* () {
|
1605
|
-
if (_this20.callHasEnded()) return;
|
1606
|
-
_this20.waitForLocalAVStream = false;
|
1607
|
-
for (var feed of callFeeds) {
|
1608
|
-
_this20.pushLocalFeed(feed);
|
1609
|
-
}
|
1610
|
-
_this20.state = CallState.CreateAnswer;
|
1611
|
-
var answer;
|
1612
|
-
try {
|
1613
|
-
_this20.getRidOfRTXCodecs();
|
1614
|
-
answer = yield _this20.createAnswer();
|
1615
|
-
} catch (err) {
|
1616
|
-
logger.debug("Call ".concat(_this20.callId, " gotCallFeedsForAnswer() failed to create answer: "), err);
|
1617
|
-
_this20.terminate(CallParty.Local, CallErrorCode.CreateAnswer, true);
|
1618
|
-
return;
|
1619
|
-
}
|
1620
|
-
try {
|
1621
|
-
yield _this20.peerConn.setLocalDescription(answer);
|
1622
|
-
|
1623
|
-
// make sure we're still going
|
1624
|
-
if (_this20.callHasEnded()) return;
|
1625
|
-
_this20.state = CallState.Connecting;
|
1626
|
-
|
1627
|
-
// Allow a short time for initial candidates to be gathered
|
1628
|
-
yield new Promise(resolve => {
|
1629
|
-
setTimeout(resolve, 200);
|
1630
|
-
});
|
1631
|
-
|
1632
|
-
// make sure the call hasn't ended before we continue
|
1633
|
-
if (_this20.callHasEnded()) return;
|
1634
|
-
_this20.sendAnswer();
|
1635
|
-
} catch (err) {
|
1636
|
-
logger.debug("Call ".concat(_this20.callId, " gotCallFeedsForAnswer() error setting local description!"), err);
|
1637
|
-
_this20.terminate(CallParty.Local, CallErrorCode.SetLocalDescription, true);
|
1638
|
-
return;
|
1639
|
-
}
|
1640
|
-
})();
|
1641
|
-
}
|
1642
|
-
onRemoteIceCandidatesReceived(ev) {
|
1643
|
-
var _this21 = this;
|
1644
|
-
return _asyncToGenerator(function* () {
|
1645
|
-
if (_this21.callHasEnded()) {
|
1646
|
-
//debuglog("Ignoring remote ICE candidate because call has ended");
|
1647
|
-
return;
|
1648
|
-
}
|
1649
|
-
var content = ev.getContent();
|
1650
|
-
var candidates = content.candidates;
|
1651
|
-
if (!candidates) {
|
1652
|
-
logger.info("Call ".concat(_this21.callId, " onRemoteIceCandidatesReceived() ignoring candidates event with no candidates!"));
|
1653
|
-
return;
|
1654
|
-
}
|
1655
|
-
var fromPartyId = content.version === 0 ? null : content.party_id || null;
|
1656
|
-
if (_this21.opponentPartyId === undefined) {
|
1657
|
-
// we haven't picked an opponent yet so save the candidates
|
1658
|
-
if (fromPartyId) {
|
1659
|
-
logger.info("Call ".concat(_this21.callId, " onRemoteIceCandidatesReceived() buffering ").concat(candidates.length, " candidates until we pick an opponent"));
|
1660
|
-
var bufferedCandidates = _this21.remoteCandidateBuffer.get(fromPartyId) || [];
|
1661
|
-
bufferedCandidates.push(...candidates);
|
1662
|
-
_this21.remoteCandidateBuffer.set(fromPartyId, bufferedCandidates);
|
1663
|
-
}
|
1664
|
-
return;
|
1665
|
-
}
|
1666
|
-
if (!_this21.partyIdMatches(content)) {
|
1667
|
-
logger.info("Call ".concat(_this21.callId, " onRemoteIceCandidatesReceived() ignoring candidates from party ID ").concat(content.party_id, ": we have chosen party ID ").concat(_this21.opponentPartyId));
|
1668
|
-
return;
|
1669
|
-
}
|
1670
|
-
yield _this21.addIceCandidates(candidates);
|
1671
|
-
})();
|
1672
|
-
}
|
1673
|
-
|
1674
|
-
/**
|
1675
|
-
* Used by MatrixClient.
|
1676
|
-
*/
|
1677
|
-
onAnswerReceived(event) {
|
1678
|
-
var _this22 = this;
|
1679
|
-
return _asyncToGenerator(function* () {
|
1680
|
-
var content = event.getContent();
|
1681
|
-
logger.debug("Call ".concat(_this22.callId, " onAnswerReceived() running (hangupParty=").concat(content.party_id, ")"));
|
1682
|
-
if (_this22.callHasEnded()) {
|
1683
|
-
logger.debug("Call ".concat(_this22.callId, " onAnswerReceived() ignoring answer because call has ended"));
|
1684
|
-
return;
|
1685
|
-
}
|
1686
|
-
if (_this22.opponentPartyId !== undefined) {
|
1687
|
-
logger.info("Call ".concat(_this22.callId, " onAnswerReceived() ignoring answer from party ID ").concat(content.party_id, ": we already have an answer/reject from ").concat(_this22.opponentPartyId));
|
1688
|
-
return;
|
1689
|
-
}
|
1690
|
-
_this22.chooseOpponent(event);
|
1691
|
-
yield _this22.addBufferedIceCandidates();
|
1692
|
-
_this22.state = CallState.Connecting;
|
1693
|
-
var sdpStreamMetadata = content[SDPStreamMetadataKey];
|
1694
|
-
if (sdpStreamMetadata) {
|
1695
|
-
_this22.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
1696
|
-
} else {
|
1697
|
-
logger.warn("Call ".concat(_this22.callId, " onAnswerReceived() did not get any SDPStreamMetadata! Can not send/receive multiple streams"));
|
1698
|
-
}
|
1699
|
-
try {
|
1700
|
-
_this22.isSettingRemoteAnswerPending = true;
|
1701
|
-
yield _this22.peerConn.setRemoteDescription(content.answer);
|
1702
|
-
_this22.isSettingRemoteAnswerPending = false;
|
1703
|
-
logger.debug("Call ".concat(_this22.callId, " onAnswerReceived() set remote description: ").concat(content.answer.type));
|
1704
|
-
} catch (e) {
|
1705
|
-
_this22.isSettingRemoteAnswerPending = false;
|
1706
|
-
logger.debug("Call ".concat(_this22.callId, " onAnswerReceived() failed to set remote description"), e);
|
1707
|
-
_this22.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false);
|
1708
|
-
return;
|
1709
|
-
}
|
1710
|
-
|
1711
|
-
// If the answer we selected has a party_id, send a select_answer event
|
1712
|
-
// We do this after setting the remote description since otherwise we'd block
|
1713
|
-
// call setup on it
|
1714
|
-
if (_this22.opponentPartyId !== null) {
|
1715
|
-
try {
|
1716
|
-
yield _this22.sendVoipEvent(EventType.CallSelectAnswer, {
|
1717
|
-
selected_party_id: _this22.opponentPartyId
|
1718
|
-
});
|
1719
|
-
} catch (err) {
|
1720
|
-
// This isn't fatal, and will just mean that if another party has raced to answer
|
1721
|
-
// the call, they won't know they got rejected, so we carry on & don't retry.
|
1722
|
-
logger.warn("Call ".concat(_this22.callId, " onAnswerReceived() failed to send select_answer event"), err);
|
1723
|
-
}
|
1724
|
-
}
|
1725
|
-
})();
|
1726
|
-
}
|
1727
|
-
onSelectAnswerReceived(event) {
|
1728
|
-
var _this23 = this;
|
1729
|
-
return _asyncToGenerator(function* () {
|
1730
|
-
if (_this23.direction !== CallDirection.Inbound) {
|
1731
|
-
logger.warn("Call ".concat(_this23.callId, " onSelectAnswerReceived() got select_answer for an outbound call: ignoring"));
|
1732
|
-
return;
|
1733
|
-
}
|
1734
|
-
var selectedPartyId = event.getContent().selected_party_id;
|
1735
|
-
if (selectedPartyId === undefined || selectedPartyId === null) {
|
1736
|
-
logger.warn("Call ".concat(_this23.callId, " onSelectAnswerReceived() got nonsensical select_answer with null/undefined selected_party_id: ignoring"));
|
1737
|
-
return;
|
1738
|
-
}
|
1739
|
-
if (selectedPartyId !== _this23.ourPartyId) {
|
1740
|
-
logger.info("Call ".concat(_this23.callId, " onSelectAnswerReceived() got select_answer for party ID ").concat(selectedPartyId, ": we are party ID ").concat(_this23.ourPartyId, "."));
|
1741
|
-
// The other party has picked somebody else's answer
|
1742
|
-
yield _this23.terminate(CallParty.Remote, CallErrorCode.AnsweredElsewhere, true);
|
1743
|
-
}
|
1744
|
-
})();
|
1745
|
-
}
|
1746
|
-
onNegotiateReceived(event) {
|
1747
|
-
var _this24 = this;
|
1748
|
-
return _asyncToGenerator(function* () {
|
1749
|
-
var content = event.getContent();
|
1750
|
-
var description = content.description;
|
1751
|
-
if (!description || !description.sdp || !description.type) {
|
1752
|
-
logger.info("Call ".concat(_this24.callId, " onNegotiateReceived() ignoring invalid m.call.negotiate event"));
|
1753
|
-
return;
|
1754
|
-
}
|
1755
|
-
// Politeness always follows the direction of the call: in a glare situation,
|
1756
|
-
// we pick either the inbound or outbound call, so one side will always be
|
1757
|
-
// inbound and one outbound
|
1758
|
-
var polite = _this24.direction === CallDirection.Inbound;
|
1759
|
-
|
1760
|
-
// Here we follow the perfect negotiation logic from
|
1761
|
-
// https://w3c.github.io/webrtc-pc/#perfect-negotiation-example
|
1762
|
-
var readyForOffer = !_this24.makingOffer && (_this24.peerConn.signalingState === "stable" || _this24.isSettingRemoteAnswerPending);
|
1763
|
-
var offerCollision = description.type === "offer" && !readyForOffer;
|
1764
|
-
_this24.ignoreOffer = !polite && offerCollision;
|
1765
|
-
if (_this24.ignoreOffer) {
|
1766
|
-
logger.info("Call ".concat(_this24.callId, " onNegotiateReceived() ignoring colliding negotiate event because we're impolite"));
|
1767
|
-
return;
|
1768
|
-
}
|
1769
|
-
var prevLocalOnHold = _this24.isLocalOnHold();
|
1770
|
-
var sdpStreamMetadata = content[SDPStreamMetadataKey];
|
1771
|
-
if (sdpStreamMetadata) {
|
1772
|
-
_this24.updateRemoteSDPStreamMetadata(sdpStreamMetadata);
|
1773
|
-
} else {
|
1774
|
-
logger.warn("Call ".concat(_this24.callId, " onNegotiateReceived() received negotiation event without SDPStreamMetadata!"));
|
1775
|
-
}
|
1776
|
-
try {
|
1777
|
-
_this24.isSettingRemoteAnswerPending = description.type == "answer";
|
1778
|
-
yield _this24.peerConn.setRemoteDescription(description); // SRD rolls back as needed
|
1779
|
-
_this24.isSettingRemoteAnswerPending = false;
|
1780
|
-
logger.debug("Call ".concat(_this24.callId, " onNegotiateReceived() set remote description: ").concat(description.type));
|
1781
|
-
if (description.type === "offer") {
|
1782
|
-
var _localDescription;
|
1783
|
-
var answer;
|
1784
|
-
try {
|
1785
|
-
_this24.getRidOfRTXCodecs();
|
1786
|
-
answer = yield _this24.createAnswer();
|
1787
|
-
} catch (err) {
|
1788
|
-
logger.debug("Call ".concat(_this24.callId, " onNegotiateReceived() failed to create answer: "), err);
|
1789
|
-
_this24.terminate(CallParty.Local, CallErrorCode.CreateAnswer, true);
|
1790
|
-
return;
|
1791
|
-
}
|
1792
|
-
yield _this24.peerConn.setLocalDescription(answer);
|
1793
|
-
logger.debug("Call ".concat(_this24.callId, " onNegotiateReceived() create an answer"));
|
1794
|
-
_this24.sendVoipEvent(EventType.CallNegotiate, {
|
1795
|
-
lifetime: CALL_TIMEOUT_MS,
|
1796
|
-
description: (_localDescription = _this24.peerConn.localDescription) === null || _localDescription === void 0 ? void 0 : _localDescription.toJSON(),
|
1797
|
-
[SDPStreamMetadataKey]: _this24.getLocalSDPStreamMetadata(true)
|
1798
|
-
});
|
1799
|
-
}
|
1800
|
-
} catch (err) {
|
1801
|
-
_this24.isSettingRemoteAnswerPending = false;
|
1802
|
-
logger.warn("Call ".concat(_this24.callId, " onNegotiateReceived() failed to complete negotiation"), err);
|
1803
|
-
}
|
1804
|
-
var newLocalOnHold = _this24.isLocalOnHold();
|
1805
|
-
if (prevLocalOnHold !== newLocalOnHold) {
|
1806
|
-
_this24.emit(CallEvent.LocalHoldUnhold, newLocalOnHold, _this24);
|
1807
|
-
// also this one for backwards compat
|
1808
|
-
_this24.emit(CallEvent.HoldUnhold, newLocalOnHold);
|
1809
|
-
}
|
1810
|
-
})();
|
1811
|
-
}
|
1812
|
-
updateRemoteSDPStreamMetadata(metadata) {
|
1813
|
-
this.remoteSDPStreamMetadata = recursivelyAssign(this.remoteSDPStreamMetadata || {}, metadata, true);
|
1814
|
-
for (var feed of this.getRemoteFeeds()) {
|
1815
|
-
var _streamId;
|
1816
|
-
var streamId = feed.stream.id;
|
1817
|
-
var _metadata = this.remoteSDPStreamMetadata[streamId];
|
1818
|
-
feed.setAudioVideoMuted(_metadata === null || _metadata === void 0 ? void 0 : _metadata.audio_muted, _metadata === null || _metadata === void 0 ? void 0 : _metadata.video_muted);
|
1819
|
-
feed.purpose = (_streamId = this.remoteSDPStreamMetadata[streamId]) === null || _streamId === void 0 ? void 0 : _streamId.purpose;
|
1820
|
-
}
|
1821
|
-
}
|
1822
|
-
onSDPStreamMetadataChangedReceived(event) {
|
1823
|
-
var content = event.getContent();
|
1824
|
-
var metadata = content[SDPStreamMetadataKey];
|
1825
|
-
this.updateRemoteSDPStreamMetadata(metadata);
|
1826
|
-
}
|
1827
|
-
onAssertedIdentityReceived(event) {
|
1828
|
-
var _this25 = this;
|
1829
|
-
return _asyncToGenerator(function* () {
|
1830
|
-
var content = event.getContent();
|
1831
|
-
if (!content.asserted_identity) return;
|
1832
|
-
_this25.remoteAssertedIdentity = {
|
1833
|
-
id: content.asserted_identity.id,
|
1834
|
-
displayName: content.asserted_identity.display_name
|
1835
|
-
};
|
1836
|
-
_this25.emit(CallEvent.AssertedIdentityChanged, _this25);
|
1837
|
-
})();
|
1838
|
-
}
|
1839
|
-
callHasEnded() {
|
1840
|
-
// This exists as workaround to typescript trying to be clever and erroring
|
1841
|
-
// when putting if (this.state === CallState.Ended) return; twice in the same
|
1842
|
-
// function, even though that function is async.
|
1843
|
-
return this.state === CallState.Ended;
|
1844
|
-
}
|
1845
|
-
queueGotLocalOffer() {
|
1846
|
-
// Ensure only one negotiate/answer event is being processed at a time.
|
1847
|
-
if (this.responsePromiseChain) {
|
1848
|
-
this.responsePromiseChain = this.responsePromiseChain.then(() => this.wrappedGotLocalOffer());
|
1849
|
-
} else {
|
1850
|
-
this.responsePromiseChain = this.wrappedGotLocalOffer();
|
1851
|
-
}
|
1852
|
-
}
|
1853
|
-
wrappedGotLocalOffer() {
|
1854
|
-
var _this26 = this;
|
1855
|
-
return _asyncToGenerator(function* () {
|
1856
|
-
_this26.makingOffer = true;
|
1857
|
-
try {
|
1858
|
-
// XXX: in what situations do we believe gotLocalOffer actually throws? It appears
|
1859
|
-
// to handle most of its exceptions itself and terminate the call. I'm not entirely
|
1860
|
-
// sure it would ever throw, so I can't add a test for these lines.
|
1861
|
-
// Also the tense is different between "gotLocalOffer" and "getLocalOfferFailed" so
|
1862
|
-
// it's not entirely clear whether getLocalOfferFailed is just misnamed or whether
|
1863
|
-
// they've been cross-polinated somehow at some point.
|
1864
|
-
yield _this26.gotLocalOffer();
|
1865
|
-
} catch (e) {
|
1866
|
-
_this26.getLocalOfferFailed(e);
|
1867
|
-
return;
|
1868
|
-
} finally {
|
1869
|
-
_this26.makingOffer = false;
|
1870
|
-
}
|
1871
|
-
})();
|
1872
|
-
}
|
1873
|
-
gotLocalOffer() {
|
1874
|
-
var _this27 = this;
|
1875
|
-
return _asyncToGenerator(function* () {
|
1876
|
-
logger.debug("Call ".concat(_this27.callId, " gotLocalOffer() running"));
|
1877
|
-
if (_this27.callHasEnded()) {
|
1878
|
-
logger.debug("Call ".concat(_this27.callId, " gotLocalOffer() ignoring newly created offer because the call has ended\""));
|
1879
|
-
return;
|
1880
|
-
}
|
1881
|
-
var offer;
|
1882
|
-
try {
|
1883
|
-
_this27.getRidOfRTXCodecs();
|
1884
|
-
offer = yield _this27.createOffer();
|
1885
|
-
} catch (err) {
|
1886
|
-
logger.debug("Call ".concat(_this27.callId, " gotLocalOffer() failed to create offer: "), err);
|
1887
|
-
_this27.terminate(CallParty.Local, CallErrorCode.CreateOffer, true);
|
1888
|
-
return;
|
1889
|
-
}
|
1890
|
-
try {
|
1891
|
-
yield _this27.peerConn.setLocalDescription(offer);
|
1892
|
-
} catch (err) {
|
1893
|
-
logger.debug("Call ".concat(_this27.callId, " gotLocalOffer() error setting local description!"), err);
|
1894
|
-
_this27.terminate(CallParty.Local, CallErrorCode.SetLocalDescription, true);
|
1895
|
-
return;
|
1896
|
-
}
|
1897
|
-
if (_this27.peerConn.iceGatheringState === "gathering") {
|
1898
|
-
// Allow a short time for initial candidates to be gathered
|
1899
|
-
yield new Promise(resolve => {
|
1900
|
-
setTimeout(resolve, 200);
|
1901
|
-
});
|
1902
|
-
}
|
1903
|
-
if (_this27.callHasEnded()) return;
|
1904
|
-
var eventType = _this27.state === CallState.CreateOffer ? EventType.CallInvite : EventType.CallNegotiate;
|
1905
|
-
var content = {
|
1906
|
-
lifetime: CALL_TIMEOUT_MS
|
1907
|
-
};
|
1908
|
-
if (eventType === EventType.CallInvite && _this27.invitee) {
|
1909
|
-
content.invitee = _this27.invitee;
|
1910
|
-
}
|
1911
|
-
|
1912
|
-
// clunky because TypeScript can't follow the types through if we use an expression as the key
|
1913
|
-
if (_this27.state === CallState.CreateOffer) {
|
1914
|
-
var _localDescription2;
|
1915
|
-
content.offer = (_localDescription2 = _this27.peerConn.localDescription) === null || _localDescription2 === void 0 ? void 0 : _localDescription2.toJSON();
|
1916
|
-
} else {
|
1917
|
-
var _localDescription3;
|
1918
|
-
content.description = (_localDescription3 = _this27.peerConn.localDescription) === null || _localDescription3 === void 0 ? void 0 : _localDescription3.toJSON();
|
1919
|
-
}
|
1920
|
-
content.capabilities = {
|
1921
|
-
"m.call.transferee": _this27.client.supportsCallTransfer,
|
1922
|
-
"m.call.dtmf": false
|
1923
|
-
};
|
1924
|
-
content[SDPStreamMetadataKey] = _this27.getLocalSDPStreamMetadata(true);
|
1925
|
-
|
1926
|
-
// Get rid of any candidates waiting to be sent: they'll be included in the local
|
1927
|
-
// description we just got and will send in the offer.
|
1928
|
-
var discardCount = _this27.discardDuplicateCandidates();
|
1929
|
-
logger.info("Call ".concat(_this27.callId, " gotLocalOffer() discarding ").concat(discardCount, " candidates that will be sent in offer"));
|
1930
|
-
try {
|
1931
|
-
yield _this27.sendVoipEvent(eventType, content);
|
1932
|
-
} catch (error) {
|
1933
|
-
logger.error("Call ".concat(_this27.callId, " gotLocalOffer() failed to send invite"), error);
|
1934
|
-
if (error instanceof MatrixError && error.event) _this27.client.cancelPendingEvent(error.event);
|
1935
|
-
var code = CallErrorCode.SignallingFailed;
|
1936
|
-
var message = "Signalling failed";
|
1937
|
-
if (_this27.state === CallState.CreateOffer) {
|
1938
|
-
code = CallErrorCode.SendInvite;
|
1939
|
-
message = "Failed to send invite";
|
1940
|
-
}
|
1941
|
-
if (error.name == "UnknownDeviceError") {
|
1942
|
-
code = CallErrorCode.UnknownDevices;
|
1943
|
-
message = "Unknown devices present in the room";
|
1944
|
-
}
|
1945
|
-
_this27.emit(CallEvent.Error, new CallError(code, message, error), _this27);
|
1946
|
-
_this27.terminate(CallParty.Local, code, false);
|
1947
|
-
|
1948
|
-
// no need to carry on & send the candidate queue, but we also
|
1949
|
-
// don't want to rethrow the error
|
1950
|
-
return;
|
1951
|
-
}
|
1952
|
-
_this27.sendCandidateQueue();
|
1953
|
-
if (_this27.state === CallState.CreateOffer) {
|
1954
|
-
_this27.inviteOrAnswerSent = true;
|
1955
|
-
_this27.state = CallState.InviteSent;
|
1956
|
-
_this27.inviteTimeout = setTimeout(() => {
|
1957
|
-
_this27.inviteTimeout = undefined;
|
1958
|
-
if (_this27.state === CallState.InviteSent) {
|
1959
|
-
_this27.hangup(CallErrorCode.InviteTimeout, false);
|
1960
|
-
}
|
1961
|
-
}, CALL_TIMEOUT_MS);
|
1962
|
-
}
|
1963
|
-
})();
|
1964
|
-
}
|
1965
|
-
/**
|
1966
|
-
* This method removes all video/rtx codecs from screensharing video
|
1967
|
-
* transceivers. This is necessary since they can cause problems. Without
|
1968
|
-
* this the following steps should produce an error:
|
1969
|
-
* Chromium calls Firefox
|
1970
|
-
* Firefox answers
|
1971
|
-
* Firefox starts screen-sharing
|
1972
|
-
* Chromium starts screen-sharing
|
1973
|
-
* Call crashes for Chromium with:
|
1974
|
-
* [96685:23:0518/162603.933321:ERROR:webrtc_video_engine.cc(3296)] RTX codec (PT=97) mapped to PT=96 which is not in the codec list.
|
1975
|
-
* [96685:23:0518/162603.933377:ERROR:webrtc_video_engine.cc(1171)] GetChangedRecvParameters called without any video codecs.
|
1976
|
-
* [96685:23:0518/162603.933430:ERROR:sdp_offer_answer.cc(4302)] Failed to set local video description recv parameters for m-section with mid='2'. (INVALID_PARAMETER)
|
1977
|
-
*/
|
1978
|
-
getRidOfRTXCodecs() {
|
1979
|
-
// RTCRtpReceiver.getCapabilities and RTCRtpSender.getCapabilities don't seem to be supported on FF before v113
|
1980
|
-
if (!RTCRtpReceiver.getCapabilities || !RTCRtpSender.getCapabilities) return;
|
1981
|
-
var screenshareVideoTransceiver = this.transceivers.get(getTransceiverKey(SDPStreamMetadataPurpose.Screenshare, "video"));
|
1982
|
-
|
1983
|
-
// setCodecPreferences isn't supported on FF (as of v113)
|
1984
|
-
if (!screenshareVideoTransceiver || !screenshareVideoTransceiver.setCodecPreferences) return;
|
1985
|
-
var recvCodecs = RTCRtpReceiver.getCapabilities("video").codecs;
|
1986
|
-
var sendCodecs = RTCRtpSender.getCapabilities("video").codecs;
|
1987
|
-
var codecs = [];
|
1988
|
-
for (var codec of [...recvCodecs, ...sendCodecs]) {
|
1989
|
-
if (codec.mimeType !== "video/rtx") {
|
1990
|
-
codecs.push(codec);
|
1991
|
-
try {
|
1992
|
-
screenshareVideoTransceiver.setCodecPreferences(codecs);
|
1993
|
-
} catch (e) {
|
1994
|
-
// Specifically, Chrome around version 125 and Electron 30 (which is Chromium 124) return an H.264 codec in
|
1995
|
-
// the sender's capabilities but throw when you try to set it. Hence... this mess.
|
1996
|
-
// Specifically, that codec is:
|
1997
|
-
// {
|
1998
|
-
// clockRate: 90000,
|
1999
|
-
// mimeType: "video/H264",
|
2000
|
-
// sdpFmtpLine: "level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=640034",
|
2001
|
-
// }
|
2002
|
-
logger.info("Working around buggy WebRTC impl: claimed to support codec but threw when setting codec preferences", codec, e);
|
2003
|
-
codecs.pop();
|
2004
|
-
}
|
2005
|
-
}
|
2006
|
-
}
|
2007
|
-
}
|
2008
|
-
/**
|
2009
|
-
* @internal
|
2010
|
-
*/
|
2011
|
-
sendVoipEvent(eventType, content) {
|
2012
|
-
var _this28 = this;
|
2013
|
-
return _asyncToGenerator(function* () {
|
2014
|
-
var realContent = _objectSpread(_objectSpread({}, content), {}, {
|
2015
|
-
version: VOIP_PROTO_VERSION,
|
2016
|
-
call_id: _this28.callId,
|
2017
|
-
party_id: _this28.ourPartyId,
|
2018
|
-
conf_id: _this28.groupCallId
|
2019
|
-
});
|
2020
|
-
if (_this28.opponentDeviceId) {
|
2021
|
-
var _this28$getOpponentMe;
|
2022
|
-
var toDeviceSeq = _this28.toDeviceSeq++;
|
2023
|
-
var _content = _objectSpread(_objectSpread({}, realContent), {}, {
|
2024
|
-
device_id: _this28.client.deviceId,
|
2025
|
-
sender_session_id: _this28.client.getSessionId(),
|
2026
|
-
dest_session_id: _this28.opponentSessionId,
|
2027
|
-
seq: toDeviceSeq,
|
2028
|
-
[ToDeviceMessageId]: uuidv4()
|
2029
|
-
});
|
2030
|
-
_this28.emit(CallEvent.SendVoipEvent, {
|
2031
|
-
type: "toDevice",
|
2032
|
-
eventType,
|
2033
|
-
userId: _this28.invitee || ((_this28$getOpponentMe = _this28.getOpponentMember()) === null || _this28$getOpponentMe === void 0 ? void 0 : _this28$getOpponentMe.userId),
|
2034
|
-
opponentDeviceId: _this28.opponentDeviceId,
|
2035
|
-
content: _content
|
2036
|
-
}, _this28);
|
2037
|
-
var userId = _this28.invitee || _this28.getOpponentMember().userId;
|
2038
|
-
if (_this28.client.getUseE2eForGroupCall()) {
|
2039
|
-
if (!_this28.opponentDeviceInfo) {
|
2040
|
-
logger.warn("Call ".concat(_this28.callId, " sendVoipEvent() failed: we do not have opponentDeviceInfo"));
|
2041
|
-
return;
|
2042
|
-
}
|
2043
|
-
yield _this28.client.encryptAndSendToDevices([{
|
2044
|
-
userId,
|
2045
|
-
deviceInfo: _this28.opponentDeviceInfo
|
2046
|
-
}], {
|
2047
|
-
type: eventType,
|
2048
|
-
content: _content
|
2049
|
-
});
|
2050
|
-
} else {
|
2051
|
-
yield _this28.client.sendToDevice(eventType, new Map([[userId, new Map([[_this28.opponentDeviceId, _content]])]]));
|
2052
|
-
}
|
2053
|
-
} else {
|
2054
|
-
var _this28$getOpponentMe2;
|
2055
|
-
_this28.emit(CallEvent.SendVoipEvent, {
|
2056
|
-
type: "sendEvent",
|
2057
|
-
eventType,
|
2058
|
-
roomId: _this28.roomId,
|
2059
|
-
content: realContent,
|
2060
|
-
userId: _this28.invitee || ((_this28$getOpponentMe2 = _this28.getOpponentMember()) === null || _this28$getOpponentMe2 === void 0 ? void 0 : _this28$getOpponentMe2.userId)
|
2061
|
-
}, _this28);
|
2062
|
-
yield _this28.client.sendEvent(_this28.roomId, eventType, realContent);
|
2063
|
-
}
|
2064
|
-
})();
|
2065
|
-
}
|
2066
|
-
|
2067
|
-
/**
|
2068
|
-
* Queue a candidate to be sent
|
2069
|
-
* @param content - The candidate to queue up, or null if candidates have finished being generated
|
2070
|
-
* and end-of-candidates should be signalled
|
2071
|
-
*/
|
2072
|
-
queueCandidate(content) {
|
2073
|
-
// We partially de-trickle candidates by waiting for `delay` before sending them
|
2074
|
-
// amalgamated, in order to avoid sending too many m.call.candidates events and hitting
|
2075
|
-
// rate limits in Matrix.
|
2076
|
-
// In practice, it'd be better to remove rate limits for m.call.*
|
2077
|
-
|
2078
|
-
// N.B. this deliberately lets you queue and send blank candidates, which MSC2746
|
2079
|
-
// currently proposes as the way to indicate that candidate gathering is complete.
|
2080
|
-
// This will hopefully be changed to an explicit rather than implicit notification
|
2081
|
-
// shortly.
|
2082
|
-
if (content) {
|
2083
|
-
this.candidateSendQueue.push(content);
|
2084
|
-
} else {
|
2085
|
-
this.candidatesEnded = true;
|
2086
|
-
}
|
2087
|
-
|
2088
|
-
// Don't send the ICE candidates yet if the call is in the ringing state: this
|
2089
|
-
// means we tried to pick (ie. started generating candidates) and then failed to
|
2090
|
-
// send the answer and went back to the ringing state. Queue up the candidates
|
2091
|
-
// to send if we successfully send the answer.
|
2092
|
-
// Equally don't send if we haven't yet sent the answer because we can send the
|
2093
|
-
// first batch of candidates along with the answer
|
2094
|
-
if (this.state === CallState.Ringing || !this.inviteOrAnswerSent) return;
|
2095
|
-
|
2096
|
-
// MSC2746 recommends these values (can be quite long when calling because the
|
2097
|
-
// callee will need a while to answer the call)
|
2098
|
-
var delay = this.direction === CallDirection.Inbound ? 500 : 2000;
|
2099
|
-
if (this.candidateSendTries === 0) {
|
2100
|
-
setTimeout(() => {
|
2101
|
-
this.sendCandidateQueue();
|
2102
|
-
}, delay);
|
2103
|
-
}
|
2104
|
-
}
|
2105
|
-
|
2106
|
-
// Discard all non-end-of-candidates messages
|
2107
|
-
// Return the number of candidate messages that were discarded.
|
2108
|
-
// Call this method before sending an invite or answer message
|
2109
|
-
discardDuplicateCandidates() {
|
2110
|
-
var discardCount = 0;
|
2111
|
-
var newQueue = [];
|
2112
|
-
for (var i = 0; i < this.candidateSendQueue.length; i++) {
|
2113
|
-
var candidate = this.candidateSendQueue[i];
|
2114
|
-
if (candidate.candidate === "") {
|
2115
|
-
newQueue.push(candidate);
|
2116
|
-
} else {
|
2117
|
-
discardCount++;
|
2118
|
-
}
|
2119
|
-
}
|
2120
|
-
this.candidateSendQueue = newQueue;
|
2121
|
-
return discardCount;
|
2122
|
-
}
|
2123
|
-
|
2124
|
-
/*
|
2125
|
-
* Transfers this call to another user
|
2126
|
-
*/
|
2127
|
-
transfer(targetUserId) {
|
2128
|
-
var _this29 = this;
|
2129
|
-
return _asyncToGenerator(function* () {
|
2130
|
-
// Fetch the target user's global profile info: their room avatar / displayname
|
2131
|
-
// could be different in whatever room we share with them.
|
2132
|
-
var profileInfo = yield _this29.client.getProfileInfo(targetUserId);
|
2133
|
-
var replacementId = genCallID();
|
2134
|
-
var body = {
|
2135
|
-
replacement_id: genCallID(),
|
2136
|
-
target_user: {
|
2137
|
-
id: targetUserId,
|
2138
|
-
display_name: profileInfo.displayname,
|
2139
|
-
avatar_url: profileInfo.avatar_url
|
2140
|
-
},
|
2141
|
-
create_call: replacementId
|
2142
|
-
};
|
2143
|
-
yield _this29.sendVoipEvent(EventType.CallReplaces, body);
|
2144
|
-
yield _this29.terminate(CallParty.Local, CallErrorCode.Transferred, true);
|
2145
|
-
})();
|
2146
|
-
}
|
2147
|
-
|
2148
|
-
/*
|
2149
|
-
* Transfers this call to the target call, effectively 'joining' the
|
2150
|
-
* two calls (so the remote parties on each call are connected together).
|
2151
|
-
*/
|
2152
|
-
transferToCall(transferTargetCall) {
|
2153
|
-
var _this30 = this;
|
2154
|
-
return _asyncToGenerator(function* () {
|
2155
|
-
var _transferTargetCall$g, _this30$getOpponentMe;
|
2156
|
-
var targetUserId = (_transferTargetCall$g = transferTargetCall.getOpponentMember()) === null || _transferTargetCall$g === void 0 ? void 0 : _transferTargetCall$g.userId;
|
2157
|
-
var targetProfileInfo = targetUserId ? yield _this30.client.getProfileInfo(targetUserId) : undefined;
|
2158
|
-
var opponentUserId = (_this30$getOpponentMe = _this30.getOpponentMember()) === null || _this30$getOpponentMe === void 0 ? void 0 : _this30$getOpponentMe.userId;
|
2159
|
-
var transfereeProfileInfo = opponentUserId ? yield _this30.client.getProfileInfo(opponentUserId) : undefined;
|
2160
|
-
var newCallId = genCallID();
|
2161
|
-
var bodyToTransferTarget = {
|
2162
|
-
// the replacements on each side have their own ID, and it's distinct from the
|
2163
|
-
// ID of the new call (but we can use the same function to generate it)
|
2164
|
-
replacement_id: genCallID(),
|
2165
|
-
target_user: {
|
2166
|
-
id: opponentUserId,
|
2167
|
-
display_name: transfereeProfileInfo === null || transfereeProfileInfo === void 0 ? void 0 : transfereeProfileInfo.displayname,
|
2168
|
-
avatar_url: transfereeProfileInfo === null || transfereeProfileInfo === void 0 ? void 0 : transfereeProfileInfo.avatar_url
|
2169
|
-
},
|
2170
|
-
await_call: newCallId
|
2171
|
-
};
|
2172
|
-
yield transferTargetCall.sendVoipEvent(EventType.CallReplaces, bodyToTransferTarget);
|
2173
|
-
var bodyToTransferee = {
|
2174
|
-
replacement_id: genCallID(),
|
2175
|
-
target_user: {
|
2176
|
-
id: targetUserId,
|
2177
|
-
display_name: targetProfileInfo === null || targetProfileInfo === void 0 ? void 0 : targetProfileInfo.displayname,
|
2178
|
-
avatar_url: targetProfileInfo === null || targetProfileInfo === void 0 ? void 0 : targetProfileInfo.avatar_url
|
2179
|
-
},
|
2180
|
-
create_call: newCallId
|
2181
|
-
};
|
2182
|
-
yield _this30.sendVoipEvent(EventType.CallReplaces, bodyToTransferee);
|
2183
|
-
yield _this30.terminate(CallParty.Local, CallErrorCode.Transferred, true);
|
2184
|
-
yield transferTargetCall.terminate(CallParty.Local, CallErrorCode.Transferred, true);
|
2185
|
-
})();
|
2186
|
-
}
|
2187
|
-
terminate(hangupParty, hangupReason, shouldEmit) {
|
2188
|
-
var _this31 = this;
|
2189
|
-
return _asyncToGenerator(function* () {
|
2190
|
-
var _this31$stats;
|
2191
|
-
if (_this31.callHasEnded()) return;
|
2192
|
-
_this31.hangupParty = hangupParty;
|
2193
|
-
_this31.hangupReason = hangupReason;
|
2194
|
-
_this31.state = CallState.Ended;
|
2195
|
-
if (_this31.inviteTimeout) {
|
2196
|
-
clearTimeout(_this31.inviteTimeout);
|
2197
|
-
_this31.inviteTimeout = undefined;
|
2198
|
-
}
|
2199
|
-
if (_this31.iceDisconnectedTimeout !== undefined) {
|
2200
|
-
clearTimeout(_this31.iceDisconnectedTimeout);
|
2201
|
-
_this31.iceDisconnectedTimeout = undefined;
|
2202
|
-
}
|
2203
|
-
if (_this31.callLengthInterval) {
|
2204
|
-
clearInterval(_this31.callLengthInterval);
|
2205
|
-
_this31.callLengthInterval = undefined;
|
2206
|
-
}
|
2207
|
-
if (_this31.stopVideoTrackTimer !== undefined) {
|
2208
|
-
clearTimeout(_this31.stopVideoTrackTimer);
|
2209
|
-
_this31.stopVideoTrackTimer = undefined;
|
2210
|
-
}
|
2211
|
-
for (var [stream, listener] of _this31.removeTrackListeners) {
|
2212
|
-
stream.removeEventListener("removetrack", listener);
|
2213
|
-
}
|
2214
|
-
_this31.removeTrackListeners.clear();
|
2215
|
-
_this31.callStatsAtEnd = yield _this31.collectCallStats();
|
2216
|
-
|
2217
|
-
// Order is important here: first we stopAllMedia() and only then we can deleteAllFeeds()
|
2218
|
-
_this31.stopAllMedia();
|
2219
|
-
_this31.deleteAllFeeds();
|
2220
|
-
if (_this31.peerConn && _this31.peerConn.signalingState !== "closed") {
|
2221
|
-
_this31.peerConn.close();
|
2222
|
-
}
|
2223
|
-
(_this31$stats = _this31.stats) === null || _this31$stats === void 0 || _this31$stats.removeStatsReportGatherer(_this31.callId);
|
2224
|
-
if (shouldEmit) {
|
2225
|
-
_this31.emit(CallEvent.Hangup, _this31);
|
2226
|
-
}
|
2227
|
-
_this31.client.callEventHandler.calls.delete(_this31.callId);
|
2228
|
-
})();
|
2229
|
-
}
|
2230
|
-
stopAllMedia() {
|
2231
|
-
logger.debug("Call ".concat(this.callId, " stopAllMedia() running"));
|
2232
|
-
for (var feed of this.feeds) {
|
2233
|
-
// Slightly awkward as local feed need to go via the correct method on
|
2234
|
-
// the MediaHandler so they get removed from MediaHandler (remote tracks
|
2235
|
-
// don't)
|
2236
|
-
// NB. We clone local streams when passing them to individual calls in a group
|
2237
|
-
// call, so we can (and should) stop the clones once we no longer need them:
|
2238
|
-
// the other clones will continue fine.
|
2239
|
-
if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Usermedia) {
|
2240
|
-
this.client.getMediaHandler().stopUserMediaStream(feed.stream);
|
2241
|
-
} else if (feed.isLocal() && feed.purpose === SDPStreamMetadataPurpose.Screenshare) {
|
2242
|
-
this.client.getMediaHandler().stopScreensharingStream(feed.stream);
|
2243
|
-
} else if (!feed.isLocal()) {
|
2244
|
-
logger.debug("Call ".concat(this.callId, " stopAllMedia() stopping stream (streamId=").concat(feed.stream.id, ")"));
|
2245
|
-
for (var track of feed.stream.getTracks()) {
|
2246
|
-
track.stop();
|
2247
|
-
}
|
2248
|
-
}
|
2249
|
-
}
|
2250
|
-
}
|
2251
|
-
checkForErrorListener() {
|
2252
|
-
if (this.listeners(EventEmitterEvents.Error).length === 0) {
|
2253
|
-
throw new Error("You MUST attach an error listener using call.on('error', function() {})");
|
2254
|
-
}
|
2255
|
-
}
|
2256
|
-
sendCandidateQueue() {
|
2257
|
-
var _this32 = this;
|
2258
|
-
return _asyncToGenerator(function* () {
|
2259
|
-
if (_this32.candidateSendQueue.length === 0 || _this32.callHasEnded()) {
|
2260
|
-
return;
|
2261
|
-
}
|
2262
|
-
var candidates = _this32.candidateSendQueue;
|
2263
|
-
_this32.candidateSendQueue = [];
|
2264
|
-
++_this32.candidateSendTries;
|
2265
|
-
var content = {
|
2266
|
-
candidates: candidates.map(candidate => candidate.toJSON())
|
2267
|
-
};
|
2268
|
-
if (_this32.candidatesEnded) {
|
2269
|
-
// If there are no more candidates, signal this by adding an empty string candidate
|
2270
|
-
content.candidates.push({
|
2271
|
-
candidate: ""
|
2272
|
-
});
|
2273
|
-
}
|
2274
|
-
logger.debug("Call ".concat(_this32.callId, " sendCandidateQueue() attempting to send ").concat(candidates.length, " candidates"));
|
2275
|
-
try {
|
2276
|
-
yield _this32.sendVoipEvent(EventType.CallCandidates, content);
|
2277
|
-
// reset our retry count if we have successfully sent our candidates
|
2278
|
-
// otherwise queueCandidate() will refuse to try to flush the queue
|
2279
|
-
_this32.candidateSendTries = 0;
|
2280
|
-
|
2281
|
-
// Try to send candidates again just in case we received more candidates while sending.
|
2282
|
-
_this32.sendCandidateQueue();
|
2283
|
-
} catch (error) {
|
2284
|
-
// don't retry this event: we'll send another one later as we might
|
2285
|
-
// have more candidates by then.
|
2286
|
-
if (error instanceof MatrixError && error.event) _this32.client.cancelPendingEvent(error.event);
|
2287
|
-
|
2288
|
-
// put all the candidates we failed to send back in the queue
|
2289
|
-
_this32.candidateSendQueue.push(...candidates);
|
2290
|
-
if (_this32.candidateSendTries > 5) {
|
2291
|
-
logger.debug("Call ".concat(_this32.callId, " sendCandidateQueue() failed to send candidates on attempt ").concat(_this32.candidateSendTries, ". Giving up on this call."), error);
|
2292
|
-
var code = CallErrorCode.SignallingFailed;
|
2293
|
-
var message = "Signalling failed";
|
2294
|
-
_this32.emit(CallEvent.Error, new CallError(code, message, error), _this32);
|
2295
|
-
_this32.hangup(code, false);
|
2296
|
-
return;
|
2297
|
-
}
|
2298
|
-
var delayMs = 500 * Math.pow(2, _this32.candidateSendTries);
|
2299
|
-
++_this32.candidateSendTries;
|
2300
|
-
logger.debug("Call ".concat(_this32.callId, " sendCandidateQueue() failed to send candidates. Retrying in ").concat(delayMs, "ms"), error);
|
2301
|
-
setTimeout(() => {
|
2302
|
-
_this32.sendCandidateQueue();
|
2303
|
-
}, delayMs);
|
2304
|
-
}
|
2305
|
-
})();
|
2306
|
-
}
|
2307
|
-
|
2308
|
-
/**
|
2309
|
-
* Place a call to this room.
|
2310
|
-
* @throws if you have not specified a listener for 'error' events.
|
2311
|
-
* @throws if have passed audio=false.
|
2312
|
-
*/
|
2313
|
-
placeCall(audio, video) {
|
2314
|
-
var _this33 = this;
|
2315
|
-
return _asyncToGenerator(function* () {
|
2316
|
-
if (!audio) {
|
2317
|
-
throw new Error("You CANNOT start a call without audio");
|
2318
|
-
}
|
2319
|
-
_this33.state = CallState.WaitLocalMedia;
|
2320
|
-
var callFeed;
|
2321
|
-
try {
|
2322
|
-
var _this33$client$getDev;
|
2323
|
-
var stream = yield _this33.client.getMediaHandler().getUserMediaStream(audio, video);
|
2324
|
-
|
2325
|
-
// make sure all the tracks are enabled (same as pushNewLocalFeed -
|
2326
|
-
// we probably ought to just have one code path for adding streams)
|
2327
|
-
setTracksEnabled(stream.getAudioTracks(), true);
|
2328
|
-
setTracksEnabled(stream.getVideoTracks(), true);
|
2329
|
-
callFeed = new CallFeed({
|
2330
|
-
client: _this33.client,
|
2331
|
-
roomId: _this33.roomId,
|
2332
|
-
userId: _this33.client.getUserId(),
|
2333
|
-
deviceId: (_this33$client$getDev = _this33.client.getDeviceId()) !== null && _this33$client$getDev !== void 0 ? _this33$client$getDev : undefined,
|
2334
|
-
stream,
|
2335
|
-
purpose: SDPStreamMetadataPurpose.Usermedia,
|
2336
|
-
audioMuted: false,
|
2337
|
-
videoMuted: false
|
2338
|
-
});
|
2339
|
-
} catch (e) {
|
2340
|
-
_this33.getUserMediaFailed(e);
|
2341
|
-
return;
|
2342
|
-
}
|
2343
|
-
try {
|
2344
|
-
yield _this33.placeCallWithCallFeeds([callFeed]);
|
2345
|
-
} catch (e) {
|
2346
|
-
_this33.placeCallFailed(e);
|
2347
|
-
return;
|
2348
|
-
}
|
2349
|
-
})();
|
2350
|
-
}
|
2351
|
-
|
2352
|
-
/**
|
2353
|
-
* Place a call to this room with call feed.
|
2354
|
-
* @param callFeeds - to use
|
2355
|
-
* @throws if you have not specified a listener for 'error' events.
|
2356
|
-
* @throws if have passed audio=false.
|
2357
|
-
*/
|
2358
|
-
placeCallWithCallFeeds(callFeeds) {
|
2359
|
-
var _arguments2 = arguments,
|
2360
|
-
_this34 = this;
|
2361
|
-
return _asyncToGenerator(function* () {
|
2362
|
-
var requestScreenshareFeed = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : false;
|
2363
|
-
_this34.checkForErrorListener();
|
2364
|
-
_this34.direction = CallDirection.Outbound;
|
2365
|
-
yield _this34.initOpponentCrypto();
|
2366
|
-
|
2367
|
-
// XXX Find a better way to do this
|
2368
|
-
_this34.client.callEventHandler.calls.set(_this34.callId, _this34);
|
2369
|
-
|
2370
|
-
// make sure we have valid turn creds. Unless something's gone wrong, it should
|
2371
|
-
// poll and keep the credentials valid so this should be instant.
|
2372
|
-
var haveTurnCreds = yield _this34.client.checkTurnServers();
|
2373
|
-
if (!haveTurnCreds) {
|
2374
|
-
logger.warn("Call ".concat(_this34.callId, " placeCallWithCallFeeds() failed to get TURN credentials! Proceeding with call anyway..."));
|
2375
|
-
}
|
2376
|
-
|
2377
|
-
// create the peer connection now so it can be gathering candidates while we get user
|
2378
|
-
// media (assuming a candidate pool size is configured)
|
2379
|
-
_this34.peerConn = _this34.createPeerConnection();
|
2380
|
-
_this34.emit(CallEvent.PeerConnectionCreated, _this34.peerConn, _this34);
|
2381
|
-
_this34.gotCallFeedsForInvite(callFeeds, requestScreenshareFeed);
|
2382
|
-
})();
|
2383
|
-
}
|
2384
|
-
createPeerConnection() {
|
2385
|
-
var _this$stats;
|
2386
|
-
var pc = new window.RTCPeerConnection({
|
2387
|
-
iceTransportPolicy: this.forceTURN ? "relay" : undefined,
|
2388
|
-
iceServers: this.turnServers.length ? this.turnServers : undefined,
|
2389
|
-
iceCandidatePoolSize: this.client.iceCandidatePoolSize,
|
2390
|
-
bundlePolicy: "max-bundle"
|
2391
|
-
});
|
2392
|
-
|
2393
|
-
// 'connectionstatechange' would be better, but firefox doesn't implement that.
|
2394
|
-
pc.addEventListener("iceconnectionstatechange", this.onIceConnectionStateChanged);
|
2395
|
-
pc.addEventListener("signalingstatechange", this.onSignallingStateChanged);
|
2396
|
-
pc.addEventListener("icecandidate", this.gotLocalIceCandidate);
|
2397
|
-
pc.addEventListener("icegatheringstatechange", this.onIceGatheringStateChange);
|
2398
|
-
pc.addEventListener("track", this.onTrack);
|
2399
|
-
pc.addEventListener("negotiationneeded", this.onNegotiationNeeded);
|
2400
|
-
pc.addEventListener("datachannel", this.onDataChannel);
|
2401
|
-
var opponentMember = this.getOpponentMember();
|
2402
|
-
var opponentMemberId = opponentMember ? opponentMember.userId : "unknown";
|
2403
|
-
(_this$stats = this.stats) === null || _this$stats === void 0 || _this$stats.addStatsReportGatherer(this.callId, opponentMemberId, pc);
|
2404
|
-
return pc;
|
2405
|
-
}
|
2406
|
-
partyIdMatches(msg) {
|
2407
|
-
// They must either match or both be absent (in which case opponentPartyId will be null)
|
2408
|
-
// Also we ignore party IDs on the invite/offer if the version is 0, so we must do the same
|
2409
|
-
// here and use null if the version is 0 (woe betide any opponent sending messages in the
|
2410
|
-
// same call with different versions)
|
2411
|
-
var msgPartyId = msg.version === 0 ? null : msg.party_id || null;
|
2412
|
-
return msgPartyId === this.opponentPartyId;
|
2413
|
-
}
|
2414
|
-
|
2415
|
-
// Commits to an opponent for the call
|
2416
|
-
// ev: An invite or answer event
|
2417
|
-
chooseOpponent(ev) {
|
2418
|
-
var _getMember;
|
2419
|
-
// I choo-choo-choose you
|
2420
|
-
var msg = ev.getContent();
|
2421
|
-
logger.debug("Call ".concat(this.callId, " chooseOpponent() running (partyId=").concat(msg.party_id, ")"));
|
2422
|
-
this.opponentVersion = msg.version;
|
2423
|
-
if (this.opponentVersion === 0) {
|
2424
|
-
// set to null to indicate that we've chosen an opponent, but because
|
2425
|
-
// they're v0 they have no party ID (even if they sent one, we're ignoring it)
|
2426
|
-
this.opponentPartyId = null;
|
2427
|
-
} else {
|
2428
|
-
// set to their party ID, or if they're naughty and didn't send one despite
|
2429
|
-
// not being v0, set it to null to indicate we picked an opponent with no
|
2430
|
-
// party ID
|
2431
|
-
this.opponentPartyId = msg.party_id || null;
|
2432
|
-
}
|
2433
|
-
this.opponentCaps = msg.capabilities || {};
|
2434
|
-
this.opponentMember = (_getMember = this.client.getRoom(this.roomId).getMember(ev.getSender())) !== null && _getMember !== void 0 ? _getMember : undefined;
|
2435
|
-
if (this.opponentMember) {
|
2436
|
-
var _this$stats2;
|
2437
|
-
(_this$stats2 = this.stats) === null || _this$stats2 === void 0 || _this$stats2.updateOpponentMember(this.callId, this.opponentMember.userId);
|
2438
|
-
}
|
2439
|
-
}
|
2440
|
-
addBufferedIceCandidates() {
|
2441
|
-
var _this35 = this;
|
2442
|
-
return _asyncToGenerator(function* () {
|
2443
|
-
var bufferedCandidates = _this35.remoteCandidateBuffer.get(_this35.opponentPartyId);
|
2444
|
-
if (bufferedCandidates) {
|
2445
|
-
logger.info("Call ".concat(_this35.callId, " addBufferedIceCandidates() adding ").concat(bufferedCandidates.length, " buffered candidates for opponent ").concat(_this35.opponentPartyId));
|
2446
|
-
yield _this35.addIceCandidates(bufferedCandidates);
|
2447
|
-
}
|
2448
|
-
_this35.remoteCandidateBuffer.clear();
|
2449
|
-
})();
|
2450
|
-
}
|
2451
|
-
addIceCandidates(candidates) {
|
2452
|
-
var _this36 = this;
|
2453
|
-
return _asyncToGenerator(function* () {
|
2454
|
-
for (var candidate of candidates) {
|
2455
|
-
if ((candidate.sdpMid === null || candidate.sdpMid === undefined) && (candidate.sdpMLineIndex === null || candidate.sdpMLineIndex === undefined)) {
|
2456
|
-
logger.debug("Call ".concat(_this36.callId, " addIceCandidates() got remote ICE end-of-candidates"));
|
2457
|
-
} else {
|
2458
|
-
logger.debug("Call ".concat(_this36.callId, " addIceCandidates() got remote ICE candidate (sdpMid=").concat(candidate.sdpMid, ", candidate=").concat(candidate.candidate, ")"));
|
2459
|
-
}
|
2460
|
-
try {
|
2461
|
-
yield _this36.peerConn.addIceCandidate(candidate);
|
2462
|
-
} catch (err) {
|
2463
|
-
if (!_this36.ignoreOffer) {
|
2464
|
-
logger.info("Call ".concat(_this36.callId, " addIceCandidates() failed to add remote ICE candidate"), err);
|
2465
|
-
} else {
|
2466
|
-
logger.debug("Call ".concat(_this36.callId, " addIceCandidates() failed to add remote ICE candidate because ignoring offer"), err);
|
2467
|
-
}
|
2468
|
-
}
|
2469
|
-
}
|
2470
|
-
})();
|
2471
|
-
}
|
2472
|
-
get hasPeerConnection() {
|
2473
|
-
return Boolean(this.peerConn);
|
2474
|
-
}
|
2475
|
-
initStats(stats) {
|
2476
|
-
var peerId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "unknown";
|
2477
|
-
this.stats = stats;
|
2478
|
-
this.stats.start();
|
2479
|
-
}
|
2480
|
-
}
|
2481
|
-
export function setTracksEnabled(tracks, enabled) {
|
2482
|
-
for (var track of tracks) {
|
2483
|
-
track.enabled = enabled;
|
2484
|
-
}
|
2485
|
-
}
|
2486
|
-
export function supportsMatrixCall() {
|
2487
|
-
// typeof prevents Node from erroring on an undefined reference
|
2488
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
2489
|
-
// NB. We don't log here as apps try to create a call object as a test for
|
2490
|
-
// whether calls are supported, so we shouldn't fill the logs up.
|
2491
|
-
return false;
|
2492
|
-
}
|
2493
|
-
|
2494
|
-
// Firefox throws on so little as accessing the RTCPeerConnection when operating in a secure mode.
|
2495
|
-
// There's some information at https://bugzilla.mozilla.org/show_bug.cgi?id=1542616 though the concern
|
2496
|
-
// is that the browser throwing a SecurityError will brick the client creation process.
|
2497
|
-
try {
|
2498
|
-
var supported = Boolean(window.RTCPeerConnection || window.RTCSessionDescription || window.RTCIceCandidate || navigator.mediaDevices);
|
2499
|
-
if (!supported) {
|
2500
|
-
/* istanbul ignore if */ // Adds a lot of noise to test runs, so disable logging there.
|
2501
|
-
if (process.env.NODE_ENV !== "test") {
|
2502
|
-
logger.error("WebRTC is not supported in this browser / environment");
|
2503
|
-
}
|
2504
|
-
return false;
|
2505
|
-
}
|
2506
|
-
} catch (e) {
|
2507
|
-
logger.error("Exception thrown when trying to access WebRTC", e);
|
2508
|
-
return false;
|
2509
|
-
}
|
2510
|
-
return true;
|
2511
|
-
}
|
2512
|
-
|
2513
|
-
/**
|
2514
|
-
* DEPRECATED
|
2515
|
-
* Use client.createCall()
|
2516
|
-
*
|
2517
|
-
* Create a new Matrix call for the browser.
|
2518
|
-
* @param client - The client instance to use.
|
2519
|
-
* @param roomId - The room the call is in.
|
2520
|
-
* @param options - DEPRECATED optional options map.
|
2521
|
-
* @returns the call or null if the browser doesn't support calling.
|
2522
|
-
*/
|
2523
|
-
export function createNewMatrixCall(client, roomId, options) {
|
2524
|
-
if (!supportsMatrixCall()) return null;
|
2525
|
-
var optionsForceTURN = options ? options.forceTURN : false;
|
2526
|
-
var opts = {
|
2527
|
-
client: client,
|
2528
|
-
roomId: roomId,
|
2529
|
-
invitee: options === null || options === void 0 ? void 0 : options.invitee,
|
2530
|
-
turnServers: client.getTurnServers(),
|
2531
|
-
// call level options
|
2532
|
-
forceTURN: client.forceTURN || optionsForceTURN,
|
2533
|
-
opponentDeviceId: options === null || options === void 0 ? void 0 : options.opponentDeviceId,
|
2534
|
-
opponentSessionId: options === null || options === void 0 ? void 0 : options.opponentSessionId,
|
2535
|
-
groupCallId: options === null || options === void 0 ? void 0 : options.groupCallId
|
2536
|
-
};
|
2537
|
-
var call = new MatrixCall(opts);
|
2538
|
-
client.reEmitter.reEmit(call, Object.values(CallEvent));
|
2539
|
-
return call;
|
2540
|
-
}
|
2541
|
-
//# sourceMappingURL=call.js.map
|