vani-meeting-client-native 0.4.7-beta3 → 0.4.8-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -97,7 +97,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
97
97
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
98
98
|
};
|
|
99
99
|
import { Track, TrackKind } from "../model/Track";
|
|
100
|
-
import { WebrtcMessageType } from "../websocket-handler/WebsocketHandler";
|
|
100
|
+
import { WebrtcMessageType, } from "../websocket-handler/WebsocketHandler";
|
|
101
101
|
import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
|
|
102
102
|
import { LogLevel } from "../model/MeetingStartRequest";
|
|
103
103
|
import { DynamicLibHelper } from "../utility/DynamicLibHelper";
|
|
@@ -107,14 +107,14 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
107
107
|
__extends(WebrtcHandler, _super);
|
|
108
108
|
function WebrtcHandler() {
|
|
109
109
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
110
|
-
_this.dynamicLibHelper =
|
|
110
|
+
_this.dynamicLibHelper = new DynamicLibHelper();
|
|
111
111
|
_this.rtcPeerConnections = [];
|
|
112
112
|
_this.adaptationManager = null;
|
|
113
113
|
_this.addTransceiverifRequired = function (peerConnection) { return __awaiter(_this, void 0, void 0, function () {
|
|
114
114
|
var kinds, kinds_1, kinds_1_1, eachKind;
|
|
115
115
|
var e_1, _a;
|
|
116
116
|
return __generator(this, function (_b) {
|
|
117
|
-
kinds = [
|
|
117
|
+
kinds = ["audio", "video"];
|
|
118
118
|
try {
|
|
119
119
|
for (kinds_1 = __values(kinds), kinds_1_1 = kinds_1.next(); !kinds_1_1.done; kinds_1_1 = kinds_1.next()) {
|
|
120
120
|
eachKind = kinds_1_1.value;
|
|
@@ -128,6 +128,12 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
128
128
|
}
|
|
129
129
|
finally { if (e_1) throw e_1.error; }
|
|
130
130
|
}
|
|
131
|
+
this.printLogIfRequired("no of transiver", peerConnection.rtcPeerConnection
|
|
132
|
+
.getTransceivers());
|
|
133
|
+
if (peerConnection.rtcPeerConnection
|
|
134
|
+
.getTransceivers().length === 0) {
|
|
135
|
+
peerConnection.rtcPeerConnection.createDataChannel("test");
|
|
136
|
+
}
|
|
131
137
|
return [2 /*return*/];
|
|
132
138
|
});
|
|
133
139
|
}); };
|
|
@@ -139,7 +145,9 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
139
145
|
return __generator(this, function (_c) {
|
|
140
146
|
switch (_c.label) {
|
|
141
147
|
case 0:
|
|
142
|
-
transceiver = peerConnection.rtcPeerConnection
|
|
148
|
+
transceiver = peerConnection.rtcPeerConnection
|
|
149
|
+
.getTransceivers()
|
|
150
|
+
.find(function (t) { var _a, _b; return ((_b = (_a = t === null || t === void 0 ? void 0 : t.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === eachKind; });
|
|
143
151
|
if (!!transceiver) return [3 /*break*/, 1];
|
|
144
152
|
this.printLogIfRequired("addTransceiverifRequired", eachKind);
|
|
145
153
|
realTrack = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getAllSelfTracks().find(function (t) { var _a; return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) === eachKind; });
|
|
@@ -147,21 +155,21 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
147
155
|
if (realTrack && realTrack.track) {
|
|
148
156
|
this.printLogIfRequired("addTransceiverifRequired track real", eachKind, realTrack.track);
|
|
149
157
|
// newTransceiver = await peerConnection.rtcPeerConnection.addTrack(realTrack.track)
|
|
150
|
-
if (realTrack.track.kind ===
|
|
158
|
+
if (realTrack.track.kind === "audio") {
|
|
151
159
|
newTransceiver = peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, {
|
|
152
|
-
direction:
|
|
160
|
+
direction: "sendonly",
|
|
153
161
|
sendEncodings: [
|
|
154
162
|
{
|
|
155
163
|
maxBitrate: 32000,
|
|
156
|
-
priority:
|
|
157
|
-
networkPriority:
|
|
158
|
-
}
|
|
159
|
-
]
|
|
164
|
+
priority: "high",
|
|
165
|
+
networkPriority: "high",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
160
168
|
});
|
|
161
169
|
}
|
|
162
|
-
else if (realTrack.track.kind ===
|
|
170
|
+
else if (realTrack.track.kind === "video") {
|
|
163
171
|
newTransceiver = peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, {
|
|
164
|
-
direction:
|
|
172
|
+
direction: "sendonly",
|
|
165
173
|
});
|
|
166
174
|
}
|
|
167
175
|
// newTransceiver = await peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, { direction: "sendrecv" })
|
|
@@ -171,8 +179,10 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
171
179
|
// this.printLogIfRequired("addTransceiverifRequired track fake",eachKind)
|
|
172
180
|
// newTransceiver = await peerConnection.rtcPeerConnection.addTransceiver(eachKind, { direction: "sendrecv" })
|
|
173
181
|
}
|
|
174
|
-
if (eachKind ===
|
|
175
|
-
transceiver = peerConnection.rtcPeerConnection
|
|
182
|
+
if (eachKind === "audio") {
|
|
183
|
+
transceiver = peerConnection.rtcPeerConnection
|
|
184
|
+
.getTransceivers()
|
|
185
|
+
.find(function (t) { var _a, _b; return ((_b = (_a = t === null || t === void 0 ? void 0 : t.sender) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === eachKind; });
|
|
176
186
|
if (transceiver) {
|
|
177
187
|
this.applyAudioPriority(transceiver);
|
|
178
188
|
}
|
|
@@ -187,7 +197,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
187
197
|
return [4 /*yield*/, transceiver.sender.replaceTrack(realTrack.track)];
|
|
188
198
|
case 2:
|
|
189
199
|
_c.sent();
|
|
190
|
-
if (eachKind ===
|
|
200
|
+
if (eachKind === "audio") {
|
|
191
201
|
this.applyAudioPriority(transceiver);
|
|
192
202
|
// this.setOpusParams(newTransceiver);
|
|
193
203
|
}
|
|
@@ -209,19 +219,26 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
209
219
|
selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
210
220
|
this.printLogIfRequired("checkIfCanSendOffer", selfParticpant, (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isStartAndSetupWithServerCalled);
|
|
211
221
|
this.printLogIfRequired("checkIfCanSendOffer REMOTE", participant);
|
|
212
|
-
if (!selfParticpant.isStartMeetingCalled &&
|
|
222
|
+
if (!selfParticpant.isStartMeetingCalled &&
|
|
223
|
+
!((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.isStartAndSetupWithServerCalled)) {
|
|
213
224
|
return [2 /*return*/];
|
|
214
225
|
}
|
|
215
|
-
if (!(selfParticpant.userId !== participant.userId &&
|
|
226
|
+
if (!(selfParticpant.userId !== participant.userId &&
|
|
227
|
+
(negotiationId ||
|
|
228
|
+
!selfParticpant.getPeerConnections().has(participant.userId)))) return [3 /*break*/, 5];
|
|
216
229
|
isOfferInitParticipant = this.isOfferInitParticipant(participant);
|
|
217
230
|
this.printLogIfRequired("Check if Can Send Offer", isOfferInitParticipant, shouldForceFullyCreateOffer);
|
|
218
231
|
if (!(!isOfferInitParticipant || shouldForceFullyCreateOffer)) return [3 /*break*/, 5];
|
|
219
232
|
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
|
|
220
|
-
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
233
|
+
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
234
|
+
? peerConnectionObject.rtcPeerConnection
|
|
235
|
+
: this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
221
236
|
if (!peerConnection) return [3 /*break*/, 5];
|
|
222
237
|
this.rtcPeerConnections.push(peerConnection);
|
|
223
238
|
peerConnectionObject.isCreatingOffer = true;
|
|
224
|
-
if (negotiationId &&
|
|
239
|
+
if (negotiationId &&
|
|
240
|
+
peerConnectionObject.opertionalNegotiationId &&
|
|
241
|
+
peerConnectionObject.opertionalNegotiationId === negotiationId) {
|
|
225
242
|
return [2 /*return*/];
|
|
226
243
|
}
|
|
227
244
|
peerConnectionObject.opertionalNegotiationId = negotiationId;
|
|
@@ -237,7 +254,9 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
237
254
|
if (shouldRestartIce) {
|
|
238
255
|
peerConnection.restartIce();
|
|
239
256
|
}
|
|
240
|
-
return [4 /*yield*/, peerConnection.createOffer({
|
|
257
|
+
return [4 /*yield*/, peerConnection.createOffer({
|
|
258
|
+
iceRestart: shouldRestartIce,
|
|
259
|
+
})];
|
|
241
260
|
case 3:
|
|
242
261
|
offer = _c.sent();
|
|
243
262
|
mungedOffer = {
|
|
@@ -275,17 +294,22 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
275
294
|
return [2 /*return*/];
|
|
276
295
|
}
|
|
277
296
|
this.printLogIfRequired("Send Offer loop", mungedOffer, participant);
|
|
278
|
-
messageJson = {
|
|
297
|
+
messageJson = {
|
|
298
|
+
to: participant.userId,
|
|
299
|
+
type: WebrtcMessageType.SendOffer,
|
|
300
|
+
data: mungedOffer,
|
|
301
|
+
};
|
|
279
302
|
this.sendWebrtcMessage(messageJson);
|
|
280
303
|
if (peerConnectionObject.remoteAnswer || count > 20) {
|
|
281
304
|
return [2 /*return*/];
|
|
282
305
|
}
|
|
283
|
-
if (peerConnectionObject.rtcPeerConnection &&
|
|
306
|
+
if (peerConnectionObject.rtcPeerConnection &&
|
|
307
|
+
peerConnectionObject.rtcPeerConnection.connectionState === "closed") {
|
|
284
308
|
return [2 /*return*/];
|
|
285
309
|
}
|
|
286
310
|
setTimeout(function () {
|
|
287
311
|
_this.printLogIfRequired("loopSendOffer ");
|
|
288
|
-
_this.loopSendOffer(peerConnectionObject, participant, mungedOffer,
|
|
312
|
+
_this.loopSendOffer(peerConnectionObject, participant, mungedOffer, count + 1);
|
|
289
313
|
}, 3000);
|
|
290
314
|
return [2 /*return*/];
|
|
291
315
|
});
|
|
@@ -310,21 +334,32 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
310
334
|
if (peerConnectionObject) {
|
|
311
335
|
peerConnectionObject.remoteOffer = data.sdp;
|
|
312
336
|
}
|
|
313
|
-
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
337
|
+
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
338
|
+
? peerConnectionObject.rtcPeerConnection
|
|
339
|
+
: this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
314
340
|
if (!peerConnection) return [3 /*break*/, 6];
|
|
315
341
|
this.rtcPeerConnections.push(peerConnection);
|
|
316
342
|
peerConnectionObject.rtcPeerConnection = peerConnection;
|
|
317
|
-
if (peerConnectionObject.opertionalNegotiationId &&
|
|
343
|
+
if (peerConnectionObject.opertionalNegotiationId &&
|
|
344
|
+
peerConnectionObject.negotiationId &&
|
|
345
|
+
peerConnectionObject.opertionalNegotiationId ===
|
|
346
|
+
peerConnectionObject.negotiationId) {
|
|
318
347
|
peerConnectionObject.negotiationId = undefined;
|
|
319
348
|
peerConnectionObject.isNegotiationNeeded = false;
|
|
320
349
|
}
|
|
321
350
|
return [4 /*yield*/, this.subToConnectionState(participant)];
|
|
322
351
|
case 1:
|
|
323
352
|
_b.sent();
|
|
324
|
-
return [4 /*yield*/, peerConnection.setRemoteDescription({
|
|
353
|
+
return [4 /*yield*/, peerConnection.setRemoteDescription({
|
|
354
|
+
type: "offer",
|
|
355
|
+
sdp: peerConnectionObject.remoteOffer,
|
|
356
|
+
})];
|
|
325
357
|
case 2:
|
|
326
358
|
_b.sent();
|
|
327
|
-
this.printLogIfRequired("On New Offer setRemoteDescription", {
|
|
359
|
+
this.printLogIfRequired("On New Offer setRemoteDescription", {
|
|
360
|
+
type: "offer",
|
|
361
|
+
sdp: peerConnectionObject.remoteOffer,
|
|
362
|
+
});
|
|
328
363
|
this.printLogIfRequired("REMOTE SDP", (_a = peerConnection.remoteDescription) === null || _a === void 0 ? void 0 : _a.sdp);
|
|
329
364
|
return [4 /*yield*/, this.addTransceiverifRequired(peerConnectionObject)];
|
|
330
365
|
case 3:
|
|
@@ -343,7 +378,11 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
343
378
|
this.printLogIfRequired("On New Offer setLocalDescription", mungedAnswer);
|
|
344
379
|
peerConnectionObject.answer = mungedAnswer;
|
|
345
380
|
console.log("answer", mungedAnswer);
|
|
346
|
-
messageJson = {
|
|
381
|
+
messageJson = {
|
|
382
|
+
to: participant.userId,
|
|
383
|
+
type: WebrtcMessageType.SendAnswer,
|
|
384
|
+
data: mungedAnswer,
|
|
385
|
+
};
|
|
347
386
|
this.sendWebrtcMessage(messageJson);
|
|
348
387
|
peerConnectionObject.opertionalNegotiationId = undefined;
|
|
349
388
|
_b.label = 6;
|
|
@@ -362,7 +401,10 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
362
401
|
participant = data.sender;
|
|
363
402
|
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
|
|
364
403
|
this.printLogIfRequired("On New Answer peerConnectionObject", peerConnectionObject);
|
|
365
|
-
if (peerConnectionObject.opertionalNegotiationId &&
|
|
404
|
+
if (peerConnectionObject.opertionalNegotiationId &&
|
|
405
|
+
peerConnectionObject.negotiationId &&
|
|
406
|
+
peerConnectionObject.opertionalNegotiationId ===
|
|
407
|
+
peerConnectionObject.negotiationId) {
|
|
366
408
|
peerConnectionObject.negotiationId = undefined;
|
|
367
409
|
peerConnectionObject.opertionalNegotiationId = undefined;
|
|
368
410
|
peerConnectionObject.isNegotiationNeeded = false;
|
|
@@ -371,17 +413,25 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
371
413
|
if (peerConnectionObject) {
|
|
372
414
|
peerConnectionObject.remoteAnswer = data.sdp;
|
|
373
415
|
}
|
|
374
|
-
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
416
|
+
peerConnection = peerConnectionObject.rtcPeerConnection
|
|
417
|
+
? peerConnectionObject.rtcPeerConnection
|
|
418
|
+
: this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
|
|
375
419
|
if (!peerConnection) return [3 /*break*/, 3];
|
|
376
|
-
if (!(peerConnection.signalingState ===
|
|
377
|
-
return [4 /*yield*/, peerConnection.setRemoteDescription({
|
|
420
|
+
if (!(peerConnection.signalingState === "have-local-offer")) return [3 /*break*/, 2];
|
|
421
|
+
return [4 /*yield*/, peerConnection.setRemoteDescription({
|
|
422
|
+
type: "answer",
|
|
423
|
+
sdp: peerConnectionObject.remoteAnswer,
|
|
424
|
+
})];
|
|
378
425
|
case 1:
|
|
379
426
|
_b.sent();
|
|
380
427
|
_b.label = 2;
|
|
381
428
|
case 2:
|
|
382
429
|
peerConnectionObject.isRtcRestartIceInProgess = false;
|
|
383
430
|
this.printLogIfRequired("REMOTE SDP", (_a = peerConnection.remoteDescription) === null || _a === void 0 ? void 0 : _a.sdp);
|
|
384
|
-
this.printLogIfRequired("On New Answer setRemoteDescription", {
|
|
431
|
+
this.printLogIfRequired("On New Answer setRemoteDescription", {
|
|
432
|
+
type: "answer",
|
|
433
|
+
sdp: peerConnectionObject.remoteAnswer,
|
|
434
|
+
});
|
|
385
435
|
_b.label = 3;
|
|
386
436
|
case 3: return [2 /*return*/];
|
|
387
437
|
}
|
|
@@ -477,19 +527,24 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
477
527
|
return [2 /*return*/];
|
|
478
528
|
}
|
|
479
529
|
rtcConnection = peerConnectionObject.rtcPeerConnection;
|
|
480
|
-
if (!rtcConnection ||
|
|
530
|
+
if (!rtcConnection ||
|
|
531
|
+
peerConnectionObject.isRtcRestartIceInProgess ||
|
|
532
|
+
count > 12 ||
|
|
533
|
+
(rtcConnection.connectionState !== "failed" &&
|
|
534
|
+
rtcConnection.connectionState !== "disconnected")) {
|
|
481
535
|
return [2 /*return*/];
|
|
482
536
|
}
|
|
483
537
|
if ((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isWebScoketConnected()) {
|
|
484
538
|
rtcConnection.restartIce();
|
|
485
539
|
peerConnectionObject.isRtcRestartIceInProgess = true;
|
|
486
540
|
peerConnectionObject.isNegotiationNeeded = true;
|
|
487
|
-
peerConnectionObject.negotiationId =
|
|
541
|
+
peerConnectionObject.negotiationId =
|
|
542
|
+
new Date().getTime() + "_" + (Math.floor(Math.random() * 100) + 1);
|
|
488
543
|
this.onNegotiationNeeded(remoteParticipant, true);
|
|
489
544
|
}
|
|
490
545
|
else {
|
|
491
546
|
setTimeout(function () {
|
|
492
|
-
_this.onRTCConnectionChanged(remoteParticipant,
|
|
547
|
+
_this.onRTCConnectionChanged(remoteParticipant, count + 1);
|
|
493
548
|
}, 4000);
|
|
494
549
|
}
|
|
495
550
|
return [2 /*return*/];
|
|
@@ -507,23 +562,30 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
507
562
|
}
|
|
508
563
|
peerConnectionObject.isSubDone = true;
|
|
509
564
|
rtcConnection = peerConnectionObject.rtcPeerConnection;
|
|
510
|
-
rtcConnection.addEventListener(
|
|
565
|
+
rtcConnection.addEventListener("icecandidate", function (event) {
|
|
511
566
|
if (event.candidate && event.candidate !== null) {
|
|
512
567
|
_this.printLogIfRequired("icecandidate", event.candidate, remoteParticipant);
|
|
513
568
|
var sdpMid = event.candidate.sdpMid;
|
|
514
569
|
var sdpMLineIndex = event.candidate.sdpMLineIndex;
|
|
515
|
-
var messageJson = {
|
|
516
|
-
|
|
570
|
+
var messageJson = {
|
|
571
|
+
to: remoteParticipant.userId,
|
|
572
|
+
type: WebrtcMessageType.IceCandidate,
|
|
573
|
+
data: {
|
|
574
|
+
sdpMid: sdpMid,
|
|
575
|
+
sdpMLineIndex: sdpMLineIndex,
|
|
576
|
+
candidate: event.candidate,
|
|
577
|
+
},
|
|
578
|
+
};
|
|
517
579
|
_this.sendWebrtcMessage(messageJson);
|
|
518
580
|
}
|
|
519
581
|
});
|
|
520
|
-
rtcConnection.addEventListener(
|
|
582
|
+
rtcConnection.addEventListener("iceconnectionstatechange", function (event) {
|
|
521
583
|
_this.printLogIfRequired("iceconnectionstatechange", rtcConnection.iceConnectionState, event, remoteParticipant);
|
|
522
584
|
});
|
|
523
|
-
rtcConnection.addEventListener(
|
|
585
|
+
rtcConnection.addEventListener("connectionstatechange", function (event) {
|
|
524
586
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
525
587
|
_this.printLogIfRequired("connectionstatechange", peerConnectionObject.userId, rtcConnection.connectionState);
|
|
526
|
-
if (rtcConnection.connectionState ===
|
|
588
|
+
if (rtcConnection.connectionState === "connected") {
|
|
527
589
|
var participant = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.participantByUserId(peerConnectionObject.userId);
|
|
528
590
|
_this.printLogIfRequired("connected", participant, peerConnectionObject.userId);
|
|
529
591
|
if (participant) {
|
|
@@ -543,10 +605,10 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
543
605
|
// if(eachReciver && eachReciver.track){
|
|
544
606
|
// const streamTrack = eachReciver.track
|
|
545
607
|
// this.onNewTrack(streamTrack,remoteParticipant)
|
|
546
|
-
// }
|
|
608
|
+
// }
|
|
547
609
|
// })
|
|
548
610
|
}
|
|
549
|
-
else if (rtcConnection.connectionState ===
|
|
611
|
+
else if (rtcConnection.connectionState === "disconnected") {
|
|
550
612
|
var participant = (_e = _this.communicationHandler) === null || _e === void 0 ? void 0 : _e.participantByUserId(peerConnectionObject.userId);
|
|
551
613
|
_this.printLogIfRequired("disconnected", participant, peerConnectionObject.userId);
|
|
552
614
|
if (participant) {
|
|
@@ -556,7 +618,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
556
618
|
_this.onRTCConnectionChanged(remoteParticipant);
|
|
557
619
|
}, 4000);
|
|
558
620
|
}
|
|
559
|
-
else if (rtcConnection.connectionState ===
|
|
621
|
+
else if (rtcConnection.connectionState === "failed") {
|
|
560
622
|
var participant = (_g = _this.communicationHandler) === null || _g === void 0 ? void 0 : _g.participantByUserId(peerConnectionObject.userId);
|
|
561
623
|
_this.printLogIfRequired("failed", participant, peerConnectionObject.userId);
|
|
562
624
|
if (participant) {
|
|
@@ -565,12 +627,13 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
565
627
|
_this.onRTCConnectionChanged(remoteParticipant);
|
|
566
628
|
}
|
|
567
629
|
});
|
|
568
|
-
rtcConnection.addEventListener(
|
|
630
|
+
rtcConnection.addEventListener("signalingstatechange", function (event) {
|
|
569
631
|
var _a;
|
|
570
632
|
_this.printLogIfRequired("signalingstatechange", event, rtcConnection.signalingState);
|
|
571
633
|
var selfParticpant = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
|
|
572
634
|
var innerPeerConnectionObject = selfParticpant === null || selfParticpant === void 0 ? void 0 : selfParticpant.isPeerConnectionsViaUserIdPresent(remoteParticipant.userId);
|
|
573
|
-
if (innerPeerConnectionObject &&
|
|
635
|
+
if (innerPeerConnectionObject &&
|
|
636
|
+
rtcConnection.signalingState === "stable") {
|
|
574
637
|
innerPeerConnectionObject.isCreatingOffer = false;
|
|
575
638
|
if (innerPeerConnectionObject.isNegotiationNeeded) {
|
|
576
639
|
_this.onNegotiationNeeded(remoteParticipant, false, 0, true);
|
|
@@ -586,18 +649,23 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
586
649
|
// this.printLogIfRequired("New Remote Track",track)
|
|
587
650
|
// }
|
|
588
651
|
// })
|
|
589
|
-
rtcConnection.addEventListener(
|
|
590
|
-
var _a;
|
|
652
|
+
rtcConnection.addEventListener("negotiationneeded", function (event) {
|
|
653
|
+
var _a, _b;
|
|
591
654
|
_this.printLogIfRequired("negotiationneeded", rtcConnection.signalingState, remoteParticipant, peerConnectionObject);
|
|
592
655
|
var selfParticpant = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
|
|
593
656
|
var innerPeerConnectionObject = selfParticpant === null || selfParticpant === void 0 ? void 0 : selfParticpant.isPeerConnectionsViaUserIdPresent(remoteParticipant.userId);
|
|
594
|
-
|
|
657
|
+
var remoteUser = (_b = _this.communicationHandler) === null || _b === void 0 ? void 0 : _b.participantByUserId(remoteParticipant.userId);
|
|
658
|
+
if (!remoteUser &&
|
|
659
|
+
(!innerPeerConnectionObject ||
|
|
660
|
+
(!innerPeerConnectionObject.offer &&
|
|
661
|
+
!innerPeerConnectionObject.answer))) {
|
|
595
662
|
_this.printLogIfRequired("negotiationneeded ignored", rtcConnection.signalingState, remoteParticipant, innerPeerConnectionObject, __spreadArray([], __read(selfParticpant.getPeerConnections().entries()), false));
|
|
596
663
|
return;
|
|
597
664
|
}
|
|
598
665
|
innerPeerConnectionObject.isNegotiationNeeded = true;
|
|
599
|
-
innerPeerConnectionObject.negotiationId =
|
|
600
|
-
|
|
666
|
+
innerPeerConnectionObject.negotiationId =
|
|
667
|
+
new Date().getTime() + "_" + (Math.floor(Math.random() * 100) + 1);
|
|
668
|
+
if (rtcConnection.signalingState === "stable") {
|
|
601
669
|
_this.onNegotiationNeeded(remoteParticipant, false, 0, true);
|
|
602
670
|
}
|
|
603
671
|
});
|
|
@@ -633,7 +701,11 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
633
701
|
isOfferInitParticipant = this.isOfferInitParticipant(remoteParticipant);
|
|
634
702
|
selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
635
703
|
peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(remoteParticipant.userId, this.meetingStartRequest);
|
|
636
|
-
if (peerConnectionObject &&
|
|
704
|
+
if (peerConnectionObject &&
|
|
705
|
+
shouldRestartIce &&
|
|
706
|
+
peerConnectionObject.rtcPeerConnection &&
|
|
707
|
+
peerConnectionObject.rtcPeerConnection.connectionState === "connected") {
|
|
708
|
+
this.printLogIfRequired("onNegotiationNeeded return", remoteParticipant, shouldRestartIce, peerConnectionObject);
|
|
637
709
|
return [2 /*return*/];
|
|
638
710
|
}
|
|
639
711
|
// if(shouldIgnoreAllOldOpetionalNego){
|
|
@@ -643,7 +715,10 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
643
715
|
// this.printLogIfRequired("shouldForceFullyCreateOffer ",peerConnectionObject,peerConnectionObject.isNegotiationNeeded,peerConnectionObject.opertionalNegotiationId,count)
|
|
644
716
|
// }
|
|
645
717
|
// else
|
|
646
|
-
if (!peerConnectionObject ||
|
|
718
|
+
if (!peerConnectionObject ||
|
|
719
|
+
!peerConnectionObject.isNegotiationNeeded ||
|
|
720
|
+
peerConnectionObject.opertionalNegotiationId ||
|
|
721
|
+
count > 15) {
|
|
647
722
|
this.printLogIfRequired("onNegotiationNeeded exit", peerConnectionObject, peerConnectionObject.isNegotiationNeeded, peerConnectionObject.opertionalNegotiationId, count);
|
|
648
723
|
return [2 /*return*/];
|
|
649
724
|
}
|
|
@@ -659,24 +734,38 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
659
734
|
case 2:
|
|
660
735
|
setTimeout(function () {
|
|
661
736
|
_this.printLogIfRequired("onNegotiationNeeded setTimeout 525");
|
|
662
|
-
_this.onNegotiationNeeded(remoteParticipant, shouldRestartIce,
|
|
737
|
+
_this.onNegotiationNeeded(remoteParticipant, shouldRestartIce, count + 1, shouldForceFullyCreateOffer);
|
|
663
738
|
}, 5000);
|
|
664
739
|
_d.label = 3;
|
|
665
740
|
case 3: return [3 /*break*/, 6];
|
|
666
741
|
case 4:
|
|
667
|
-
isVideoAdded = ((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.getAllSelfTracks().find(function (eachTrack) {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
742
|
+
isVideoAdded = ((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.getAllSelfTracks().find(function (eachTrack) {
|
|
743
|
+
return eachTrack.trackKind === TrackKind.Video && eachTrack.track;
|
|
744
|
+
}))
|
|
745
|
+
? true
|
|
746
|
+
: false;
|
|
747
|
+
isAudioAdded = ((_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.getAllSelfTracks().find(function (eachTrack) {
|
|
748
|
+
return eachTrack.trackKind === TrackKind.Audio && eachTrack.track;
|
|
749
|
+
}))
|
|
750
|
+
? true
|
|
751
|
+
: false;
|
|
752
|
+
messageJson = {
|
|
753
|
+
to: remoteParticipant.userId,
|
|
754
|
+
type: WebrtcMessageType.NegotiationNeeded,
|
|
755
|
+
data: {
|
|
756
|
+
negotiationId: peerConnectionObject.negotiationId,
|
|
757
|
+
shouldRestartIce: shouldRestartIce,
|
|
758
|
+
isVideoAdded: isVideoAdded,
|
|
759
|
+
isAudioAdded: isAudioAdded,
|
|
760
|
+
},
|
|
761
|
+
};
|
|
673
762
|
return [4 /*yield*/, this.sendWebrtcMessage(messageJson)];
|
|
674
763
|
case 5:
|
|
675
764
|
_d.sent();
|
|
676
765
|
this.printLogIfRequired("ask remote negogitation ", messageJson);
|
|
677
766
|
setTimeout(function () {
|
|
678
767
|
_this.printLogIfRequired("onNegotiationNeeded setTimeout 542");
|
|
679
|
-
_this.onNegotiationNeeded(remoteParticipant, shouldRestartIce,
|
|
768
|
+
_this.onNegotiationNeeded(remoteParticipant, shouldRestartIce, count + 1, shouldForceFullyCreateOffer);
|
|
680
769
|
}, 5000);
|
|
681
770
|
_d.label = 6;
|
|
682
771
|
case 6: return [2 /*return*/];
|
|
@@ -729,7 +818,9 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
729
818
|
selfParticpant = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
|
|
730
819
|
if (selfParticpant) {
|
|
731
820
|
peerConnection = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
|
|
732
|
-
if (peerConnection &&
|
|
821
|
+
if (peerConnection &&
|
|
822
|
+
peerConnection.rtcPeerConnection &&
|
|
823
|
+
peerConnection.rtcPeerConnection.signalingState === "stable") {
|
|
733
824
|
this.printLogIfRequired("Send Track", participant);
|
|
734
825
|
this.addTransceiverToEachTrackKind(track.track.kind, peerConnection, true);
|
|
735
826
|
// let transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(t => t && t.sender && t.sender.track && t.sender.track.kind && t.sender.track.kind === track.track.kind)
|
|
@@ -777,15 +868,19 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
777
868
|
optionalParams[_i - 1] = arguments[_i];
|
|
778
869
|
}
|
|
779
870
|
if (optionalParams && optionalParams.length > 0) {
|
|
780
|
-
_this.meetingStartRequest &&
|
|
871
|
+
_this.meetingStartRequest &&
|
|
872
|
+
_this.meetingStartRequest.logLevel === LogLevel.Debug &&
|
|
873
|
+
console.log("Webrtc-" + message, optionalParams);
|
|
781
874
|
}
|
|
782
875
|
else {
|
|
783
|
-
_this.meetingStartRequest &&
|
|
876
|
+
_this.meetingStartRequest &&
|
|
877
|
+
_this.meetingStartRequest.logLevel === LogLevel.Debug &&
|
|
878
|
+
console.log("Webrtc-" + message);
|
|
784
879
|
}
|
|
785
880
|
};
|
|
786
881
|
_this.setOpusSdpParams = function (sdp) {
|
|
787
882
|
var _a;
|
|
788
|
-
var lines = sdp.split(
|
|
883
|
+
var lines = sdp.split("\r\n");
|
|
789
884
|
var opusLine = lines.find(function (l) { return /a=rtpmap:\d+ opus/i.test(l); });
|
|
790
885
|
if (!opusLine)
|
|
791
886
|
return sdp;
|
|
@@ -805,7 +900,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
805
900
|
lines.splice(rtpmapIdx + 1, 0, fmtpLine);
|
|
806
901
|
}
|
|
807
902
|
// a=mid injection removed — was corrupting SDP
|
|
808
|
-
return lines.join(
|
|
903
|
+
return lines.join("\r\n");
|
|
809
904
|
};
|
|
810
905
|
_this.setOpusParams = function (transceiver) {
|
|
811
906
|
if (transceiver === null || transceiver === void 0 ? void 0 : transceiver.sender) {
|
|
@@ -820,21 +915,17 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
820
915
|
if (!params.encodings || params.encodings.length === 0) {
|
|
821
916
|
params.encodings = [{}];
|
|
822
917
|
}
|
|
823
|
-
params.encodings[0] = __assign(__assign({}, params.encodings[0]), { maxBitrate: 32000, networkPriority:
|
|
918
|
+
params.encodings[0] = __assign(__assign({}, params.encodings[0]), { maxBitrate: 32000, networkPriority: "high", priority: "high" });
|
|
824
919
|
sender.setParameters(params).catch(console.error);
|
|
825
920
|
};
|
|
826
921
|
_this.applyAudioPriority = function (transceiver) {
|
|
827
922
|
var _a, _b;
|
|
828
923
|
// Codec preference — Opus first
|
|
829
|
-
var capabilities = (_a = RTCRtpSender.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(RTCRtpSender,
|
|
924
|
+
var capabilities = (_a = RTCRtpSender.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(RTCRtpSender, "audio");
|
|
830
925
|
if (!(capabilities === null || capabilities === void 0 ? void 0 : capabilities.codecs))
|
|
831
926
|
return;
|
|
832
|
-
var opus = capabilities.codecs.filter(function (c) {
|
|
833
|
-
|
|
834
|
-
});
|
|
835
|
-
var rest = capabilities.codecs.filter(function (c) {
|
|
836
|
-
return c.mimeType.toLowerCase() !== 'audio/opus';
|
|
837
|
-
});
|
|
927
|
+
var opus = capabilities.codecs.filter(function (c) { return c.mimeType.toLowerCase() === "audio/opus"; });
|
|
928
|
+
var rest = capabilities.codecs.filter(function (c) { return c.mimeType.toLowerCase() !== "audio/opus"; });
|
|
838
929
|
transceiver.setCodecPreferences(__spreadArray(__spreadArray([], __read(opus), false), __read(rest), false));
|
|
839
930
|
// maxBitrate only — priority/networkPriority already set at addTransceiver
|
|
840
931
|
var params = transceiver.sender.getParameters();
|
|
@@ -846,7 +937,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
846
937
|
_this.onNewTrack = function (track, receiver, transceiver, remoteParticipant) { return __awaiter(_this, void 0, void 0, function () {
|
|
847
938
|
var kind;
|
|
848
939
|
return __generator(this, function (_a) {
|
|
849
|
-
kind = track.kind.toLowerCase() ===
|
|
940
|
+
kind = track.kind.toLowerCase() === "audio" ? TrackKind.Audio : TrackKind.Video;
|
|
850
941
|
this.registerTrack(track, remoteParticipant, kind);
|
|
851
942
|
return [2 /*return*/];
|
|
852
943
|
});
|
|
@@ -867,7 +958,11 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
867
958
|
}
|
|
868
959
|
track.onended = function () {
|
|
869
960
|
var _a, _b;
|
|
870
|
-
var existing = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getAllTracks().find(function (t) {
|
|
961
|
+
var existing = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getAllTracks().find(function (t) {
|
|
962
|
+
var _a, _b;
|
|
963
|
+
return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) === track.kind &&
|
|
964
|
+
((_b = t.participant) === null || _b === void 0 ? void 0 : _b.userId) === participant.userId;
|
|
965
|
+
});
|
|
871
966
|
if (existing)
|
|
872
967
|
(_b = _this.communicationHandler) === null || _b === void 0 ? void 0 : _b.removeTrack(existing);
|
|
873
968
|
};
|
|
@@ -884,7 +979,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
884
979
|
stillPhantom = _a.sent();
|
|
885
980
|
this.printLogIfRequired("stillPhantom", kind);
|
|
886
981
|
if (!stillPhantom) {
|
|
887
|
-
this.printLogIfRequired(
|
|
982
|
+
this.printLogIfRequired("Real track arrived for", kind);
|
|
888
983
|
this.registerTrack(transceiver.receiver.track, participant, kind);
|
|
889
984
|
}
|
|
890
985
|
else {
|
|
@@ -915,7 +1010,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
915
1010
|
try {
|
|
916
1011
|
for (_a = __values(stats.values()), _b = _a.next(); !_b.done; _b = _a.next()) {
|
|
917
1012
|
report = _b.value;
|
|
918
|
-
if (report.type ===
|
|
1013
|
+
if (report.type === "inbound-rtp") {
|
|
919
1014
|
return [2 /*return*/, ((_d = report.bytesReceived) !== null && _d !== void 0 ? _d : 0) === 0];
|
|
920
1015
|
}
|
|
921
1016
|
}
|
|
@@ -1023,8 +1118,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
1023
1118
|
}
|
|
1024
1119
|
}
|
|
1025
1120
|
}
|
|
1026
|
-
catch (err) {
|
|
1027
|
-
}
|
|
1121
|
+
catch (err) { }
|
|
1028
1122
|
return [2 /*return*/];
|
|
1029
1123
|
});
|
|
1030
1124
|
});
|
|
@@ -1058,19 +1152,24 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
1058
1152
|
var _a, _b;
|
|
1059
1153
|
return (_b = (_a = _this.communicationHandler
|
|
1060
1154
|
.getAllSelfTracks()
|
|
1061
|
-
.find(function (t) { var _a; return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) ===
|
|
1155
|
+
.find(function (t) { var _a; return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) === "video"; })) === null || _a === void 0 ? void 0 : _a.track) !== null && _b !== void 0 ? _b : null;
|
|
1062
1156
|
}, function (profile) {
|
|
1063
|
-
_this.printLogIfRequired(
|
|
1157
|
+
_this.printLogIfRequired("Network profile", profile);
|
|
1064
1158
|
// Show UI banner: 'poor connection' / 'video paused' etc.
|
|
1065
1159
|
}, (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.deviceTier);
|
|
1066
1160
|
this.adaptationManager.start();
|
|
1067
1161
|
}
|
|
1068
1162
|
}
|
|
1069
|
-
catch (err) {
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
this.
|
|
1163
|
+
catch (err) { }
|
|
1164
|
+
this.meetingStartRequest &&
|
|
1165
|
+
this.meetingStartRequest.logLevel === LogLevel.Debug &&
|
|
1166
|
+
this.printLogIfRequired(" Init", this.communicationHandler.getAllParticipants());
|
|
1167
|
+
this.meetingStartRequest &&
|
|
1168
|
+
this.meetingStartRequest.logLevel === LogLevel.Debug &&
|
|
1169
|
+
this.printLogIfRequired("Webrtc Init");
|
|
1170
|
+
this.communicationHandler
|
|
1171
|
+
.getAllParticipants()
|
|
1172
|
+
.forEach(function (eachParticiapant) {
|
|
1074
1173
|
_this.onUserJoined(eachParticiapant);
|
|
1075
1174
|
});
|
|
1076
1175
|
return [2 /*return*/];
|
|
@@ -1126,11 +1225,9 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
1126
1225
|
}
|
|
1127
1226
|
};
|
|
1128
1227
|
WebrtcHandler.prototype.createDataChannel = function () {
|
|
1129
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1130
|
-
return
|
|
1131
|
-
|
|
1132
|
-
});
|
|
1133
|
-
});
|
|
1228
|
+
return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
1229
|
+
return [2 /*return*/];
|
|
1230
|
+
}); });
|
|
1134
1231
|
};
|
|
1135
1232
|
WebrtcHandler.prototype.sendMessageViaDataChannel = function (messagePayload) {
|
|
1136
1233
|
// throw new Error('Method not implemented.');
|
|
@@ -1176,7 +1273,9 @@ var WebrtcHandler = /** @class */ (function (_super) {
|
|
|
1176
1273
|
var selfParticpant = this.communicationHandler.getSelfParticipant();
|
|
1177
1274
|
var peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(remoteUserId, this.meetingStartRequest);
|
|
1178
1275
|
if (peerConnectionObject && peerConnectionObject.rtcPeerConnection) {
|
|
1179
|
-
peerConnectionObject.rtcPeerConnection
|
|
1276
|
+
peerConnectionObject.rtcPeerConnection
|
|
1277
|
+
.getTransceivers()
|
|
1278
|
+
.forEach(function (transceiver) {
|
|
1180
1279
|
var _a;
|
|
1181
1280
|
if ((_a = transceiver.receiver) === null || _a === void 0 ? void 0 : _a.track) {
|
|
1182
1281
|
_this.onNewTrack(transceiver.receiver.track, transceiver.receiver, transceiver, participant);
|