vani-meeting-client-native 0.3.7-beta8 → 0.3.9

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.
@@ -43,6 +43,7 @@ export declare class MeetingHandler {
43
43
  getConsumerForTrack(track: Track): void;
44
44
  participantByUserId(userId: string): Participant | undefined;
45
45
  updateParticipantData(participant: Participant): Participant | undefined;
46
+ updateParticipantUserData(participant: Participant): Participant | undefined;
46
47
  getUpdatedParticipantsListFromServer(): void;
47
48
  getAllParticipants(): Participant[];
48
49
  getAllTracks(): Track[];
@@ -201,23 +201,29 @@ var MeetingHandler = /** @class */ (function () {
201
201
  if (shouldAddTrackImmediately === void 0) { shouldAddTrackImmediately = true; }
202
202
  return __awaiter(this, void 0, void 0, function () {
203
203
  return __generator(this, function (_c) {
204
- if (!this.meetingStartRequest) {
205
- log.error("meetingStartRequestObject not found");
206
- return [2 /*return*/, false];
207
- }
208
- if ((((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.isMobileApp) && !this.reactNativeWebrtcPlugin) || ((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.isReady()) === false) {
209
- log.error("Init method not called");
210
- return [2 /*return*/];
211
- }
212
- if (!this.userMediaHandler) {
213
- this.userMediaHandler = new UserMediaHandler(this.meetingStartRequest, this.communicationHandler);
214
- }
215
- if (isVideoRequired === false && isAudioRequired === false) {
216
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startLocalStream return");
217
- return [2 /*return*/];
204
+ switch (_c.label) {
205
+ case 0:
206
+ if (!this.meetingStartRequest) {
207
+ log.error("meetingStartRequestObject not found");
208
+ return [2 /*return*/, false];
209
+ }
210
+ if ((((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.isMobileApp) && !this.reactNativeWebrtcPlugin) || ((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.isReady()) === false) {
211
+ log.error("Init method not called");
212
+ return [2 /*return*/];
213
+ }
214
+ if (!this.userMediaHandler) {
215
+ this.userMediaHandler = new UserMediaHandler(this.meetingStartRequest, this.communicationHandler);
216
+ }
217
+ if (isVideoRequired === false && isAudioRequired === false) {
218
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startLocalStream return");
219
+ return [2 /*return*/];
220
+ }
221
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startLocalStream starting");
222
+ return [4 /*yield*/, this.userMediaHandler.startLocalStream(isVideoRequired, isAudioRequired, shouldAddTrackImmediately, userMediaPayload)];
223
+ case 1:
224
+ _c.sent();
225
+ return [2 /*return*/, true];
218
226
  }
219
- this.userMediaHandler.startLocalStream(isVideoRequired, isAudioRequired, shouldAddTrackImmediately, userMediaPayload);
220
- return [2 /*return*/, true];
221
227
  });
222
228
  });
223
229
  };
@@ -408,6 +414,19 @@ var MeetingHandler = /** @class */ (function () {
408
414
  }
409
415
  return oldParticipant;
410
416
  };
417
+ MeetingHandler.prototype.updateParticipantUserData = function (participant) {
418
+ var _a, _b;
419
+ if (this.meetingStartRequest && participant.userId === ((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.userId)) {
420
+ this.meetingStartRequest.userData = participant.userData;
421
+ }
422
+ var oldParticipant = this.participantByUserId(participant.userId);
423
+ if (oldParticipant) {
424
+ oldParticipant.userData = participant.userData;
425
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("updateParticipantUserData", oldParticipant);
426
+ (_b = this.websocketCallHandler) === null || _b === void 0 ? void 0 : _b.sendSocketMessage(WebSocketBasicEvents.UpdateParticipantData, oldParticipant);
427
+ }
428
+ return oldParticipant;
429
+ };
411
430
  MeetingHandler.prototype.getUpdatedParticipantsListFromServer = function () {
412
431
  var _a;
413
432
  (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.downloadParticipantsData();
@@ -86,9 +86,15 @@ var CommunicationHandler = /** @class */ (function () {
86
86
  var _a;
87
87
  return __generator(this, function (_b) {
88
88
  if (participantData && participantData.userId && participantData.userId !== this.getSelfParticipant().userId) {
89
- participant = this.addParticipantIfNotExist(participantData, true);
89
+ participant = this.participantByUserId(participantData.userId);
90
+ if (!participant) {
91
+ participant = this.addParticipantIfNotExist(participantData, true);
92
+ }
90
93
  participant.isStartMeetingCalled = true;
91
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onStartParticipantMeetingCalled", participant);
94
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug
95
+ && console.log(" webrtc onStartParticipantMeetingCalled", participant);
96
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug
97
+ && console.log(" webrtc isStartMeetingCalled onStartParticipantMeetingCalled", participant.isStartMeetingCalled);
92
98
  (_a = this.videoCallHandler) === null || _a === void 0 ? void 0 : _a.onParticipantStartMeetingCalled(participant);
93
99
  }
94
100
  return [2 /*return*/];
@@ -234,7 +240,7 @@ var CommunicationHandler = /** @class */ (function () {
234
240
  if (participant) {
235
241
  participant.isVideoEnable = data.message.participant.isVideoEnable;
236
242
  participant.isAudioEnable = data.message.participant.isAudioEnable;
237
- this.refetchTrackForParticipant(participant);
243
+ // this.refetchTrackForParticipant(participant)
238
244
  this.emitMessageToSource(VaniEvent.OnAudioVideoStatusUpdated, participant);
239
245
  }
240
246
  }
@@ -585,7 +591,7 @@ var CommunicationHandler = /** @class */ (function () {
585
591
  log.warn("WEB SOCKET NOT CONNECTED");
586
592
  return false;
587
593
  }
588
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onStartAndSetupWithServerCalled");
594
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("webrtc onStartAndSetupWithServerCalled client");
589
595
  this.isStartAndSetupWithServerCalled = true;
590
596
  var data = { user: (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.userId };
591
597
  var startMeetingCalled = { message: data, type: WebSocketBasicEvents.OnStartMeetingCalled, to: (_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.roomId };
@@ -33,6 +33,8 @@ export declare enum VaniEvent {
33
33
  OnNotReachable = "notReachable",
34
34
  OnReconectionTimeout = "reconectionTimeout",
35
35
  OnReconecting = "reconecting",
36
+ WebrtcReconecting = "WebrtcReconecting",
37
+ WebrtcReconected = "WebrtcReconected",
36
38
  OnUserOnFoundWhileReconnect = "onUserOnFoundWhileReconnect",
37
39
  OnNewPingFromServer = "OnNewPingFromServer",
38
40
  OnConsumerScoreChange = "OnConsumerScoreChange",
@@ -61,6 +63,8 @@ interface VaniConnectionEvents {
61
63
  [VaniEvent.OnParticipantDataUpdated]: (participants: Participant) => any;
62
64
  [VaniEvent.OnMeetingStartTime]: (time: string) => any;
63
65
  [VaniEvent.OnNewPingFromServer]: () => any;
66
+ [VaniEvent.WebrtcReconected]: (participant: Participant) => any;
67
+ [VaniEvent.WebrtcReconecting]: (participant: Participant) => any;
64
68
  [VaniEvent.OnOldMessages]: (messages: MessagePayload[]) => any;
65
69
  [VaniEvent.OnNewChatMessageReceived]: (message: MessagePayload) => any;
66
70
  [VaniEvent.OnSpeakerChanged]: (participant: Participant) => any;
@@ -31,6 +31,8 @@ export var VaniEvent;
31
31
  VaniEvent["OnNotReachable"] = "notReachable";
32
32
  VaniEvent["OnReconectionTimeout"] = "reconectionTimeout";
33
33
  VaniEvent["OnReconecting"] = "reconecting";
34
+ VaniEvent["WebrtcReconecting"] = "WebrtcReconecting";
35
+ VaniEvent["WebrtcReconected"] = "WebrtcReconected";
34
36
  VaniEvent["OnUserOnFoundWhileReconnect"] = "onUserOnFoundWhileReconnect";
35
37
  VaniEvent["OnNewPingFromServer"] = "OnNewPingFromServer";
36
38
  VaniEvent["OnConsumerScoreChange"] = "OnConsumerScoreChange";
@@ -25,6 +25,7 @@ var Participant = /** @class */ (function () {
25
25
  this.getPeerConnectionsViaUserId = function (userId, meetingStartRequest) {
26
26
  if (!_this.getPeerConnections().has(userId)) {
27
27
  var peerConnection = new PeerConnection();
28
+ peerConnection.userId = userId;
28
29
  if (!peerConnection.rtcPeerConnection) {
29
30
  peerConnection.rtcPeerConnection = new DynamicLibHelper().getRTCPeerConnection(meetingStartRequest);
30
31
  }
@@ -1,6 +1,7 @@
1
1
  export declare class PeerConnection {
2
2
  rtcPeerConnection: any;
3
3
  offer: any;
4
+ isCreatingOffer: boolean;
4
5
  remoteOffer: any;
5
6
  answer: any;
6
7
  remoteAnswer: any;
@@ -214,7 +214,7 @@ var UserMediaHandler = /** @class */ (function (_super) {
214
214
  return __generator(this, function (_b) {
215
215
  switch (_b.label) {
216
216
  case 0:
217
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startLocalStream ", isVideoRequired, isVideoRequired);
217
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startLocalStream ", isVideoRequired, isAudioRequired);
218
218
  if (isVideoRequired === false && isAudioRequired === false) {
219
219
  this.isVideoAudioFetchInProgress = false;
220
220
  (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnPermissionApproved, {});
@@ -283,7 +283,8 @@ var UserMediaHandler = /** @class */ (function (_super) {
283
283
  UserMediaHandler.prototype.startCapturingStream = function (isVideoRequired, isAudioRequired, shouldAddTrackImmediately, userMediaPayload) {
284
284
  var _this = this;
285
285
  var _a, _b, _c, _d, _e;
286
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startCapturingStream called", isVideoRequired, isVideoRequired);
286
+ this.isVideoAudioFetchInProgress = true;
287
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("startCapturingStream called", isVideoRequired, isAudioRequired);
287
288
  if (!userMediaPayload) {
288
289
  userMediaPayload = {};
289
290
  }
@@ -310,6 +311,9 @@ var UserMediaHandler = /** @class */ (function (_super) {
310
311
  userMediaPayload.video.facingMode = this.cameraFacingMode;
311
312
  }
312
313
  }
314
+ else {
315
+ userMediaPayload.video = undefined;
316
+ }
313
317
  if (isAudioRequired) {
314
318
  var oldTrack = (_d = this.communicationHandler) === null || _d === void 0 ? void 0 : _d.getSelfTrackByType(TrackKind.Audio);
315
319
  if (oldTrack && oldTrack.track) {
@@ -327,7 +331,10 @@ var UserMediaHandler = /** @class */ (function (_super) {
327
331
  }
328
332
  }
329
333
  }
330
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log(userMediaPayload);
334
+ else {
335
+ userMediaPayload.audio = undefined;
336
+ }
337
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("userMediaPayload", userMediaPayload);
331
338
  (new DynamicLibHelper()).getMediaDevicesVariable(this.meetingStartRequest).getUserMedia(userMediaPayload)
332
339
  .then(function (stream) {
333
340
  _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("On Got Stream", stream);
@@ -358,6 +365,7 @@ var UserMediaHandler = /** @class */ (function (_super) {
358
365
  var permissionApprovedFor, data, audioPause, data, audioPause;
359
366
  var _this = this;
360
367
  return __generator(this, function (_f) {
368
+ this.isVideoAudioFetchInProgress = false;
361
369
  try {
362
370
  if (stream && stream.getVideoTracks()) {
363
371
  stream.getVideoTracks().forEach(function (eachMediaTrack) {
@@ -196,7 +196,6 @@ var MediaAdaptationManager = /** @class */ (function () {
196
196
  this.start();
197
197
  if (this.tickCount < 4)
198
198
  return [2 /*return*/];
199
- console.log("On Tick Webrtc");
200
199
  return [4 /*yield*/, this.collectStats()];
201
200
  case 1:
202
201
  stats = _a.sent();
@@ -13,7 +13,9 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
13
13
  pauseIncomingTrack(track: Track): void;
14
14
  onSocketMessage(websocketCallHandler: WebSocketMessageBody): void;
15
15
  addTransceiverifRequired: (peerConnection: PeerConnection) => Promise<void>;
16
+ addTransceiverToEachTrackKind: (eachKind: string, peerConnection: PeerConnection, shouldReplaceIfExist?: boolean) => Promise<void>;
16
17
  private checkIfCanSendOffer;
18
+ loopSendOffer: (peerConnectionObject: PeerConnection, participant: Participant, mungedOffer: any, count?: number) => Promise<void>;
17
19
  onNewOffer: (data: {
18
20
  sdp: string;
19
21
  type: string;
@@ -28,6 +30,8 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
28
30
  sender: Participant;
29
31
  negotiationId: string;
30
32
  shouldRestartIce: boolean;
33
+ isVideoAdded: boolean;
34
+ isAudioAdded: boolean;
31
35
  }) => Promise<void>;
32
36
  onIceCandidate: (data: {
33
37
  candidate: any;
@@ -36,7 +40,7 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
36
40
  }) => Promise<void>;
37
41
  onRTCConnectionChanged: (remoteParticipant: Participant, count?: number) => Promise<void>;
38
42
  subToConnectionState: (remoteParticipant: Participant) => Promise<void>;
39
- onNegotiationNeeded: (remoteParticipant: Participant, shouldRestartIce?: boolean, count?: number) => Promise<void>;
43
+ onNegotiationNeeded: (remoteParticipant: Participant, shouldRestartIce?: boolean, count?: number, shouldForceFullyCreateOffer?: boolean) => Promise<void>;
40
44
  onAllParticipants(participants: Participant[]): Promise<void>;
41
45
  onUserJoined(participant: Participant): Promise<void>;
42
46
  startSendTrackToPartiipant: (participant: Participant) => Promise<void>;
@@ -99,10 +99,10 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
99
99
  import { Track, TrackKind } from "../model/Track";
100
100
  import { WebrtcMessageType } from "../websocket-handler/WebsocketHandler";
101
101
  import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
102
- import log from 'loglevel';
103
102
  import { LogLevel } from "../model/MeetingStartRequest";
104
103
  import { DynamicLibHelper } from "../utility/DynamicLibHelper";
105
104
  import { MediaAdaptationManager } from "./MediaAdaptationManager";
105
+ import { VaniEvent } from "../model/Event";
106
106
  var WebrtcHandler = /** @class */ (function (_super) {
107
107
  __extends(WebrtcHandler, _super);
108
108
  function WebrtcHandler() {
@@ -111,102 +111,100 @@ var WebrtcHandler = /** @class */ (function (_super) {
111
111
  _this.rtcPeerConnections = [];
112
112
  _this.adaptationManager = null;
113
113
  _this.addTransceiverifRequired = function (peerConnection) { return __awaiter(_this, void 0, void 0, function () {
114
- var kinds, _loop_1, this_1, kinds_1, kinds_1_1, eachKind, e_1_1;
114
+ var kinds, kinds_1, kinds_1_1, eachKind;
115
115
  var e_1, _a;
116
- var _b;
117
- return __generator(this, function (_c) {
118
- switch (_c.label) {
119
- case 0:
120
- kinds = ['audio'];
121
- _loop_1 = function (eachKind) {
122
- var transceiver, realTrack, newTransceiver;
123
- return __generator(this, function (_d) {
124
- switch (_d.label) {
125
- case 0:
126
- transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(function (t) {
127
- var _a, _b, _c, _d, _e;
128
- 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 ||
129
- ((_d = (_c = t === null || t === void 0 ? void 0 : t.receiver) === null || _c === void 0 ? void 0 : _c.track) === null || _d === void 0 ? void 0 : _d.kind) === eachKind ||
130
- ((_e = t === null || t === void 0 ? void 0 : t.mid) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes(eachKind));
131
- });
132
- if (!!transceiver) return [3 /*break*/, 5];
133
- this_1.printLogIfRequired("addTransceiverifRequired", eachKind);
134
- realTrack = (_b = this_1.communicationHandler) === null || _b === void 0 ? void 0 : _b.getAllSelfTracks().find(function (t) { var _a; return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) === eachKind; });
135
- newTransceiver = void 0;
136
- if (!(realTrack && realTrack.track)) return [3 /*break*/, 2];
137
- this_1.printLogIfRequired("addTransceiverifRequired track real", eachKind, realTrack.track);
138
- return [4 /*yield*/, peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, { direction: "sendrecv" })];
139
- case 1:
140
- newTransceiver = _d.sent();
141
- return [3 /*break*/, 4];
142
- case 2:
143
- this_1.printLogIfRequired("addTransceiverifRequired track fake", eachKind);
144
- return [4 /*yield*/, peerConnection.rtcPeerConnection.addTransceiver(eachKind, { direction: "sendrecv" })];
145
- case 3:
146
- newTransceiver = _d.sent();
147
- _d.label = 4;
148
- case 4:
149
- if (eachKind === 'audio') {
150
- this_1.applyAudioPriority(newTransceiver);
151
- // this.setOpusParams(newTransceiver);
152
- }
153
- _d.label = 5;
154
- case 5: return [2 /*return*/];
155
- }
156
- });
157
- };
158
- this_1 = this;
159
- _c.label = 1;
160
- case 1:
161
- _c.trys.push([1, 6, 7, 8]);
162
- kinds_1 = __values(kinds), kinds_1_1 = kinds_1.next();
163
- _c.label = 2;
164
- case 2:
165
- if (!!kinds_1_1.done) return [3 /*break*/, 5];
116
+ return __generator(this, function (_b) {
117
+ kinds = ['audio', 'video'];
118
+ try {
119
+ for (kinds_1 = __values(kinds), kinds_1_1 = kinds_1.next(); !kinds_1_1.done; kinds_1_1 = kinds_1.next()) {
166
120
  eachKind = kinds_1_1.value;
167
- return [5 /*yield**/, _loop_1(eachKind)];
168
- case 3:
169
- _c.sent();
170
- _c.label = 4;
171
- case 4:
172
- kinds_1_1 = kinds_1.next();
173
- return [3 /*break*/, 2];
174
- case 5: return [3 /*break*/, 8];
175
- case 6:
176
- e_1_1 = _c.sent();
177
- e_1 = { error: e_1_1 };
178
- return [3 /*break*/, 8];
179
- case 7:
180
- try {
181
- if (kinds_1_1 && !kinds_1_1.done && (_a = kinds_1.return)) _a.call(kinds_1);
182
- }
183
- finally { if (e_1) throw e_1.error; }
184
- return [7 /*endfinally*/];
185
- case 8: return [2 /*return*/];
121
+ this.addTransceiverToEachTrackKind(eachKind, peerConnection);
122
+ }
123
+ }
124
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
125
+ finally {
126
+ try {
127
+ if (kinds_1_1 && !kinds_1_1.done && (_a = kinds_1.return)) _a.call(kinds_1);
128
+ }
129
+ finally { if (e_1) throw e_1.error; }
186
130
  }
131
+ return [2 /*return*/];
187
132
  });
188
133
  }); };
189
- _this.checkIfCanSendOffer = function (participant, negotiationId, shouldRestartIce) {
134
+ _this.addTransceiverToEachTrackKind = function (eachKind, peerConnection, shouldReplaceIfExist) {
135
+ if (shouldReplaceIfExist === void 0) { shouldReplaceIfExist = false; }
136
+ return __awaiter(_this, void 0, void 0, function () {
137
+ var transceiver, realTrack, newTransceiver, realTrack;
138
+ var _a, _b;
139
+ return __generator(this, function (_c) {
140
+ switch (_c.label) {
141
+ case 0:
142
+ transceiver = peerConnection.rtcPeerConnection.getTransceivers().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
+ if (!!transceiver) return [3 /*break*/, 3];
144
+ this.printLogIfRequired("addTransceiverifRequired", eachKind);
145
+ 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; });
146
+ newTransceiver = void 0;
147
+ if (!(realTrack && realTrack.track)) return [3 /*break*/, 2];
148
+ this.printLogIfRequired("addTransceiverifRequired track real", eachKind, realTrack.track);
149
+ return [4 /*yield*/, peerConnection.rtcPeerConnection.addTrack(realTrack.track)
150
+ // newTransceiver = await peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, { direction: "sendrecv" })
151
+ ];
152
+ case 1:
153
+ newTransceiver = _c.sent();
154
+ // newTransceiver = await peerConnection.rtcPeerConnection.addTransceiver(realTrack.track, { direction: "sendrecv" })
155
+ this.printLogIfRequired("addTransceiverifRequired track real end", eachKind, realTrack.track);
156
+ return [3 /*break*/, 2];
157
+ case 2:
158
+ if (eachKind === 'audio') {
159
+ transceiver = peerConnection.rtcPeerConnection.getTransceivers().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; });
160
+ if (transceiver) {
161
+ this.applyAudioPriority(transceiver);
162
+ }
163
+ // this.setOpusParams(newTransceiver);
164
+ }
165
+ return [3 /*break*/, 5];
166
+ case 3:
167
+ if (!shouldReplaceIfExist) return [3 /*break*/, 5];
168
+ realTrack = (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.getAllSelfTracks().find(function (t) { var _a; return ((_a = t.track) === null || _a === void 0 ? void 0 : _a.kind) === eachKind; });
169
+ if (!(realTrack && realTrack.track)) return [3 /*break*/, 5];
170
+ this.printLogIfRequired("transceiver.sender.", transceiver.sender, eachKind);
171
+ return [4 /*yield*/, transceiver.sender.replaceTrack(realTrack.track)];
172
+ case 4:
173
+ _c.sent();
174
+ if (eachKind === 'audio') {
175
+ this.applyAudioPriority(transceiver);
176
+ // this.setOpusParams(newTransceiver);
177
+ }
178
+ _c.label = 5;
179
+ case 5: return [2 /*return*/];
180
+ }
181
+ });
182
+ });
183
+ };
184
+ _this.checkIfCanSendOffer = function (participant, negotiationId, shouldRestartIce, shouldForceFullyCreateOffer) {
190
185
  if (shouldRestartIce === void 0) { shouldRestartIce = false; }
186
+ if (shouldForceFullyCreateOffer === void 0) { shouldForceFullyCreateOffer = false; }
191
187
  return __awaiter(_this, void 0, void 0, function () {
192
- var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer, mungedOffer, messageJson;
193
- var _a;
194
- return __generator(this, function (_b) {
195
- switch (_b.label) {
188
+ var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer, mungedOffer;
189
+ var _a, _b;
190
+ return __generator(this, function (_c) {
191
+ switch (_c.label) {
196
192
  case 0:
197
193
  selfParticpant = this.communicationHandler.getSelfParticipant();
198
- this.printLogIfRequired("checkIfCanSendOffer", selfParticpant);
199
- if (!selfParticpant.isStartMeetingCalled && !((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isStartAndSetupWithServerCalled)) {
194
+ this.printLogIfRequired("checkIfCanSendOffer", selfParticpant, (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isStartAndSetupWithServerCalled);
195
+ this.printLogIfRequired("checkIfCanSendOffer REMOTE", participant);
196
+ if (!selfParticpant.isStartMeetingCalled && !((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.isStartAndSetupWithServerCalled)) {
200
197
  return [2 /*return*/];
201
198
  }
202
199
  if (!(selfParticpant.userId !== participant.userId && (negotiationId || !selfParticpant.getPeerConnections().has(participant.userId)))) return [3 /*break*/, 5];
203
- this.printLogIfRequired("Check if Can Send Offer");
204
200
  isOfferInitParticipant = this.isOfferInitParticipant(participant);
205
- if (!!isOfferInitParticipant) return [3 /*break*/, 5];
201
+ this.printLogIfRequired("Check if Can Send Offer", isOfferInitParticipant, shouldForceFullyCreateOffer);
202
+ if (!(!isOfferInitParticipant || shouldForceFullyCreateOffer)) return [3 /*break*/, 5];
206
203
  peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
207
204
  peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
208
205
  if (!peerConnection) return [3 /*break*/, 5];
209
206
  this.rtcPeerConnections.push(peerConnection);
207
+ peerConnectionObject.isCreatingOffer = true;
210
208
  if (negotiationId && peerConnectionObject.opertionalNegotiationId && peerConnectionObject.opertionalNegotiationId === negotiationId) {
211
209
  return [2 /*return*/];
212
210
  }
@@ -214,40 +212,61 @@ var WebrtcHandler = /** @class */ (function (_super) {
214
212
  peerConnectionObject.rtcPeerConnection = peerConnection;
215
213
  return [4 /*yield*/, this.subToConnectionState(participant)];
216
214
  case 1:
217
- _b.sent();
218
- return [4 /*yield*/, this.addTransceiverifRequired(peerConnectionObject)
219
- // await this.startSendTrackToPartiipant(participant)
220
- ];
215
+ _c.sent();
216
+ return [4 /*yield*/, this.addTransceiverifRequired(peerConnectionObject)];
221
217
  case 2:
222
- _b.sent();
218
+ _c.sent();
219
+ this.printLogIfRequired("addTransceiverifRequired done ", selfParticpant, participant);
223
220
  // await this.startSendTrackToPartiipant(participant)
224
221
  if (shouldRestartIce) {
225
222
  peerConnection.restartIce();
226
223
  }
227
224
  return [4 /*yield*/, peerConnection.createOffer({ iceRestart: shouldRestartIce })];
228
225
  case 3:
229
- offer = _b.sent();
226
+ offer = _c.sent();
230
227
  mungedOffer = {
231
228
  type: offer.type,
232
229
  sdp: this.setOpusSdpParams(offer.sdp),
233
230
  };
234
231
  return [4 /*yield*/, peerConnection.setLocalDescription(mungedOffer)];
235
232
  case 4:
236
- _b.sent();
233
+ _c.sent();
237
234
  this.printLogIfRequired("On Offer setLocalDescription", mungedOffer);
238
235
  peerConnectionObject.offer = mungedOffer;
239
236
  // send offer to peer
240
- this.printLogIfRequired("Send Offer", mungedOffer);
241
- messageJson = { to: participant.userId, type: WebrtcMessageType.SendOffer, data: mungedOffer };
242
- this.sendWebrtcMessage(messageJson);
243
- _b.label = 5;
237
+ peerConnectionObject.remoteAnswer = undefined;
238
+ this.loopSendOffer(peerConnectionObject, participant, mungedOffer);
239
+ _c.label = 5;
244
240
  case 5: return [2 /*return*/];
245
241
  }
246
242
  });
247
243
  });
248
244
  };
245
+ _this.loopSendOffer = function (peerConnectionObject, participant, mungedOffer, count) {
246
+ if (count === void 0) { count = 0; }
247
+ return __awaiter(_this, void 0, void 0, function () {
248
+ var messageJson;
249
+ var _this = this;
250
+ return __generator(this, function (_a) {
251
+ this.printLogIfRequired("Send Offer", mungedOffer);
252
+ messageJson = { to: participant.userId, type: WebrtcMessageType.SendOffer, data: mungedOffer };
253
+ this.sendWebrtcMessage(messageJson);
254
+ if (peerConnectionObject.remoteAnswer || count > 20) {
255
+ return [2 /*return*/];
256
+ }
257
+ if (peerConnectionObject.rtcPeerConnection && peerConnectionObject.rtcPeerConnection.connectionState === 'closed') {
258
+ return [2 /*return*/];
259
+ }
260
+ setTimeout(function () {
261
+ _this.printLogIfRequired("loopSendOffer ");
262
+ _this.loopSendOffer(peerConnectionObject, participant, mungedOffer, (count + 1));
263
+ }, 3000);
264
+ return [2 /*return*/];
265
+ });
266
+ });
267
+ };
249
268
  _this.onNewOffer = function (data) { return __awaiter(_this, void 0, void 0, function () {
250
- var selfParticpant, participant, peerConnectionObject, peerConnection, answer, mungedAnswer, messageJson;
269
+ var selfParticpant, participant, peerConnectionObject, isOfferInitParticipant, peerConnection, answer, mungedAnswer, messageJson;
251
270
  var _a;
252
271
  return __generator(this, function (_b) {
253
272
  switch (_b.label) {
@@ -256,6 +275,12 @@ var WebrtcHandler = /** @class */ (function (_super) {
256
275
  selfParticpant = this.communicationHandler.getSelfParticipant();
257
276
  participant = data.sender;
258
277
  peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
278
+ if (peerConnectionObject.isCreatingOffer) {
279
+ isOfferInitParticipant = this.isOfferInitParticipant(participant);
280
+ if (isOfferInitParticipant) {
281
+ return [2 /*return*/];
282
+ }
283
+ }
259
284
  if (peerConnectionObject) {
260
285
  peerConnectionObject.remoteOffer = data.sdp;
261
286
  }
@@ -275,11 +300,10 @@ var WebrtcHandler = /** @class */ (function (_super) {
275
300
  _b.sent();
276
301
  this.printLogIfRequired("On New Offer setRemoteDescription", { type: 'offer', sdp: peerConnectionObject.remoteOffer });
277
302
  this.printLogIfRequired("REMOTE SDP", (_a = peerConnection.remoteDescription) === null || _a === void 0 ? void 0 : _a.sdp);
278
- return [4 /*yield*/, this.addTransceiverifRequired(peerConnectionObject)
279
- // await this.startSendTrackToPartiipant(participant)
280
- ];
303
+ return [4 /*yield*/, this.addTransceiverifRequired(peerConnectionObject)];
281
304
  case 3:
282
305
  _b.sent();
306
+ this.printLogIfRequired("addTransceiverifRequired done onNewOffer", selfParticpant, participant);
283
307
  return [4 /*yield*/, peerConnection.createAnswer()];
284
308
  case 4:
285
309
  answer = _b.sent();
@@ -339,17 +363,15 @@ var WebrtcHandler = /** @class */ (function (_super) {
339
363
  return __generator(this, function (_a) {
340
364
  switch (_a.label) {
341
365
  case 0:
342
- // if(peerConnectionObject.opertionalNegotiationId){
343
- // return
344
- // }
345
- this.printLogIfRequired("onRemoteNegotiationNeeded", data);
346
366
  selfParticpant = this.communicationHandler.getSelfParticipant();
347
367
  peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(data.sender.userId, this.meetingStartRequest);
368
+ this.printLogIfRequired("onRemoteNegotiationNeeded", peerConnectionObject, peerConnectionObject.opertionalNegotiationId);
348
369
  if (!peerConnectionObject || peerConnectionObject.opertionalNegotiationId) {
370
+ this.printLogIfRequired("onRemoteNegotiationNeeded exit", peerConnectionObject, peerConnectionObject.opertionalNegotiationId);
349
371
  return [2 /*return*/];
350
372
  }
351
373
  peerConnectionObject.negotiationId = data.negotiationId;
352
- return [4 /*yield*/, this.checkIfCanSendOffer(data.sender, data.negotiationId, data.shouldRestartIce)];
374
+ return [4 /*yield*/, this.checkIfCanSendOffer(data.sender, data.negotiationId, data.shouldRestartIce, true)];
353
375
  case 1:
354
376
  _a.sent();
355
377
  peerConnectionObject.opertionalNegotiationId = data.negotiationId;
@@ -470,11 +492,16 @@ var WebrtcHandler = /** @class */ (function (_super) {
470
492
  _this.printLogIfRequired("iceconnectionstatechange", rtcConnection.iceConnectionState, event, remoteParticipant);
471
493
  });
472
494
  rtcConnection.addEventListener('connectionstatechange', function (event) {
473
- var _a, _b;
474
- _this.printLogIfRequired("connectionstatechange", event, rtcConnection.connectionState);
495
+ var _a, _b, _c, _d, _e, _f, _g, _h;
496
+ _this.printLogIfRequired("connectionstatechange", peerConnectionObject.userId, rtcConnection.connectionState);
475
497
  if (rtcConnection.connectionState === 'connected') {
476
- (_a = _this.adaptationManager) === null || _a === void 0 ? void 0 : _a.applyToNewConnection(rtcConnection);
477
- (_b = _this.adaptationManager) === null || _b === void 0 ? void 0 : _b.start();
498
+ var participant = (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.participantByUserId(peerConnectionObject.userId);
499
+ _this.printLogIfRequired("connected", participant, peerConnectionObject.userId);
500
+ if (participant) {
501
+ (_b = _this.communicationHandler) === null || _b === void 0 ? void 0 : _b.emitMessageToSource(VaniEvent.WebrtcReconected, participant);
502
+ }
503
+ (_c = _this.adaptationManager) === null || _c === void 0 ? void 0 : _c.applyToNewConnection(rtcConnection);
504
+ (_d = _this.adaptationManager) === null || _d === void 0 ? void 0 : _d.start();
478
505
  _this.printLogIfRequired("On Connection Change", event, remoteParticipant);
479
506
  _this.printLogIfRequired("mobile track start");
480
507
  rtcConnection.getTransceivers().forEach(function (transceiver) {
@@ -491,19 +518,30 @@ var WebrtcHandler = /** @class */ (function (_super) {
491
518
  // })
492
519
  }
493
520
  else if (rtcConnection.connectionState === 'disconnected') {
521
+ var participant = (_e = _this.communicationHandler) === null || _e === void 0 ? void 0 : _e.participantByUserId(peerConnectionObject.userId);
522
+ _this.printLogIfRequired("disconnected", participant, peerConnectionObject.userId);
523
+ if (participant) {
524
+ (_f = _this.communicationHandler) === null || _f === void 0 ? void 0 : _f.emitMessageToSource(VaniEvent.WebrtcReconecting, participant);
525
+ }
494
526
  setTimeout(function () {
495
527
  _this.onRTCConnectionChanged(remoteParticipant);
496
528
  }, 4000);
497
529
  }
498
530
  else if (rtcConnection.connectionState === 'failed') {
531
+ var participant = (_g = _this.communicationHandler) === null || _g === void 0 ? void 0 : _g.participantByUserId(peerConnectionObject.userId);
532
+ _this.printLogIfRequired("failed", participant, peerConnectionObject.userId);
533
+ if (participant) {
534
+ (_h = _this.communicationHandler) === null || _h === void 0 ? void 0 : _h.emitMessageToSource(VaniEvent.WebrtcReconecting, participant);
535
+ }
499
536
  _this.onRTCConnectionChanged(remoteParticipant);
500
537
  }
501
538
  });
502
539
  rtcConnection.addEventListener('signalingstatechange', function (event) {
503
- _this.printLogIfRequired("signalingstatechange", event, rtcConnection.signalingstatechange);
504
- if (rtcConnection.signalingstatechange === 'stable') {
540
+ _this.printLogIfRequired("signalingstatechange", event, rtcConnection.signalingState);
541
+ if (rtcConnection.signalingState === 'stable') {
542
+ peerConnectionObject.isCreatingOffer = false;
505
543
  if (peerConnectionObject.isNegotiationNeeded) {
506
- _this.onNegotiationNeeded(remoteParticipant);
544
+ _this.onNegotiationNeeded(remoteParticipant, false, 0, true);
507
545
  }
508
546
  }
509
547
  });
@@ -525,7 +563,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
525
563
  peerConnectionObject.isNegotiationNeeded = true;
526
564
  peerConnectionObject.negotiationId = new Date().getTime() + "_" + (Math.floor(Math.random() * 100) + 1);
527
565
  if (rtcConnection.signalingState === 'stable') {
528
- _this.onNegotiationNeeded(remoteParticipant);
566
+ _this.onNegotiationNeeded(remoteParticipant, false, 0, true);
529
567
  }
530
568
  });
531
569
  rtcConnection.addEventListener("track", function (event) {
@@ -545,41 +583,68 @@ var WebrtcHandler = /** @class */ (function (_super) {
545
583
  return [2 /*return*/];
546
584
  });
547
585
  }); };
548
- _this.onNegotiationNeeded = function (remoteParticipant, shouldRestartIce, count) {
586
+ _this.onNegotiationNeeded = function (remoteParticipant, shouldRestartIce, count, shouldForceFullyCreateOffer) {
549
587
  if (shouldRestartIce === void 0) { shouldRestartIce = false; }
550
588
  if (count === void 0) { count = 0; }
589
+ if (shouldForceFullyCreateOffer === void 0) { shouldForceFullyCreateOffer = false; }
551
590
  return __awaiter(_this, void 0, void 0, function () {
552
- var isOfferInitParticipant, selfParticpant, peerConnectionObject, messageJson;
591
+ var isOfferInitParticipant, selfParticpant, peerConnectionObject, isVideoAdded, isAudioAdded, messageJson;
553
592
  var _this = this;
554
- return __generator(this, function (_a) {
555
- switch (_a.label) {
593
+ var _a, _b, _c;
594
+ return __generator(this, function (_d) {
595
+ switch (_d.label) {
556
596
  case 0:
557
- this.printLogIfRequired("onNegotiationNeeded started", remoteParticipant);
597
+ this.printLogIfRequired("onNegotiationNeeded started", remoteParticipant, count);
558
598
  isOfferInitParticipant = this.isOfferInitParticipant(remoteParticipant);
559
599
  selfParticpant = this.communicationHandler.getSelfParticipant();
560
600
  peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(remoteParticipant.userId, this.meetingStartRequest);
561
- if (!peerConnectionObject || !peerConnectionObject.isNegotiationNeeded || peerConnectionObject.opertionalNegotiationId || count > 8) {
601
+ if (peerConnectionObject && shouldRestartIce && peerConnectionObject.rtcPeerConnection && peerConnectionObject.rtcPeerConnection.connectionState === 'connected') {
602
+ return [2 /*return*/];
603
+ }
604
+ // if(shouldIgnoreAllOldOpetionalNego){
605
+ // peerConnectionObject.opertionalNegotiationId = undefined;
606
+ // }
607
+ // if(shouldIgnoreAllOldOpetionalNego && peerConnectionObject){
608
+ // this.printLogIfRequired("shouldForceFullyCreateOffer ",peerConnectionObject,peerConnectionObject.isNegotiationNeeded,peerConnectionObject.opertionalNegotiationId,count)
609
+ // }
610
+ // else
611
+ if (!peerConnectionObject || !peerConnectionObject.isNegotiationNeeded || peerConnectionObject.opertionalNegotiationId || count > 15) {
612
+ this.printLogIfRequired("onNegotiationNeeded exit", peerConnectionObject, peerConnectionObject.isNegotiationNeeded, peerConnectionObject.opertionalNegotiationId, count);
562
613
  return [2 /*return*/];
563
614
  }
564
- if (!!isOfferInitParticipant) return [3 /*break*/, 2];
565
- return [4 /*yield*/, this.checkIfCanSendOffer(remoteParticipant, peerConnectionObject.negotiationId, shouldRestartIce)];
615
+ if (!(!isOfferInitParticipant || shouldForceFullyCreateOffer)) return [3 /*break*/, 4];
616
+ if (!((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isWebScoketConnected())) return [3 /*break*/, 2];
617
+ this.printLogIfRequired("ask remote checkIfCanSendOffer ");
618
+ return [4 /*yield*/, this.checkIfCanSendOffer(remoteParticipant, peerConnectionObject.negotiationId, shouldRestartIce, shouldForceFullyCreateOffer)];
566
619
  case 1:
567
- _a.sent();
620
+ _d.sent();
568
621
  peerConnectionObject.isNegotiationNeeded = false;
569
622
  peerConnectionObject.isRtcRestartIceInProgess = false;
570
- return [3 /*break*/, 4];
623
+ return [3 /*break*/, 3];
571
624
  case 2:
572
- messageJson = { to: remoteParticipant.userId, type: WebrtcMessageType.NegotiationNeeded, data: { negotiationId: peerConnectionObject.negotiationId, shouldRestartIce: shouldRestartIce } };
573
- return [4 /*yield*/, this.sendWebrtcMessage(messageJson)];
574
- case 3:
575
- _a.sent();
576
625
  setTimeout(function () {
577
- _this.onNegotiationNeeded(remoteParticipant, shouldRestartIce, (count + 1));
626
+ _this.printLogIfRequired("onNegotiationNeeded setTimeout 525");
627
+ _this.onNegotiationNeeded(remoteParticipant, shouldRestartIce, (count + 1), shouldForceFullyCreateOffer);
578
628
  }, 5000);
579
- _a.label = 4;
629
+ _d.label = 3;
630
+ case 3: return [3 /*break*/, 6];
580
631
  case 4:
581
- peerConnectionObject.opertionalNegotiationId = peerConnectionObject.negotiationId;
582
- return [2 /*return*/];
632
+ isVideoAdded = ((_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.getAllSelfTracks().find(function (eachTrack) { return eachTrack.trackKind === TrackKind.Video && eachTrack.track; })) ? true : false;
633
+ isAudioAdded = ((_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.getAllSelfTracks().find(function (eachTrack) { return eachTrack.trackKind === TrackKind.Audio && eachTrack.track; })) ? true : false;
634
+ messageJson = { to: remoteParticipant.userId, type: WebrtcMessageType.NegotiationNeeded,
635
+ data: { negotiationId: peerConnectionObject.negotiationId, shouldRestartIce: shouldRestartIce,
636
+ isVideoAdded: isVideoAdded, isAudioAdded: isAudioAdded
637
+ } };
638
+ return [4 /*yield*/, this.sendWebrtcMessage(messageJson)];
639
+ case 5:
640
+ _d.sent();
641
+ this.printLogIfRequired("ask remote negogitation ", messageJson);
642
+ setTimeout(function () {
643
+ _this.printLogIfRequired("onNegotiationNeeded setTimeout 542");
644
+ _this.onNegotiationNeeded(remoteParticipant, shouldRestartIce, (count + 1), shouldForceFullyCreateOffer);
645
+ }, 5000);
646
+ _d.label = 6;
647
+ case 6: return [2 /*return*/];
583
648
  }
584
649
  });
585
650
  });
@@ -620,46 +685,44 @@ var WebrtcHandler = /** @class */ (function (_super) {
620
685
  });
621
686
  }); };
622
687
  _this.sendTrackToParticipant = function (track, participant) { return __awaiter(_this, void 0, void 0, function () {
623
- var selfParticpant, peerConnection, transceiver, sender_1, transceiver_1;
688
+ var selfParticpant, peerConnection;
624
689
  return __generator(this, function (_a) {
625
- switch (_a.label) {
626
- case 0:
627
- if (!track.track) {
628
- return [2 /*return*/];
629
- }
630
- selfParticpant = this.communicationHandler.getSelfParticipant();
631
- if (!selfParticpant) return [3 /*break*/, 4];
632
- peerConnection = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
633
- if (!(peerConnection && peerConnection.rtcPeerConnection)) return [3 /*break*/, 4];
690
+ if (!track.track) {
691
+ return [2 /*return*/];
692
+ }
693
+ selfParticpant = this.communicationHandler.getSelfParticipant();
694
+ if (selfParticpant) {
695
+ peerConnection = selfParticpant.getPeerConnectionsViaUserId(participant.userId, this.meetingStartRequest);
696
+ if (peerConnection && peerConnection.rtcPeerConnection && peerConnection.rtcPeerConnection.signalingState === 'stable') {
634
697
  this.printLogIfRequired("Send Track", participant);
635
- transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(function (t) { return t && t.sender && t.sender.track && t.sender.track.kind && t.sender.track.kind === track.track.kind; });
636
- if (!transceiver) {
637
- transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(function (t) { var _a, _b; return ((_b = (_a = t === null || t === void 0 ? void 0 : t.receiver) === null || _a === void 0 ? void 0 : _a.track) === null || _b === void 0 ? void 0 : _b.kind) === track.track.kind; });
638
- }
639
- if (!transceiver) return [3 /*break*/, 2];
640
- this.printLogIfRequired("Replace track", participant, track);
641
- return [4 /*yield*/, transceiver.sender.replaceTrack(track.track)];
642
- case 1:
643
- _a.sent();
644
- if (track.track.kind === 'audio' && transceiver && transceiver.sender) {
645
- // ✅ addTrack returns the sender directly
646
- this.applyAudioPriority(transceiver);
647
- // this.setOpusParamsForSender(transceiver.sender);
648
- }
649
- return [3 /*break*/, 4];
650
- case 2:
651
- this.printLogIfRequired("Send add track - reaplce track not found", participant, track);
652
- return [4 /*yield*/, peerConnection.rtcPeerConnection.addTrack(track.track)];
653
- case 3:
654
- sender_1 = _a.sent();
655
- if (track.track.kind === 'audio') {
656
- transceiver_1 = peerConnection.rtcPeerConnection.getTransceivers().find(function (t) { return t.sender === sender_1; });
657
- this.applyAudioPriority(transceiver_1);
658
- // this.setOpusParamsForSender(sender);
659
- }
660
- _a.label = 4;
661
- case 4: return [2 /*return*/];
698
+ this.addTransceiverToEachTrackKind(track.track.kind, peerConnection, true);
699
+ // let transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(t => t && t.sender && t.sender.track && t.sender.track.kind && t.sender.track.kind === track.track.kind)
700
+ // // if(!transceiver){
701
+ // // transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(t => t?.receiver?.track?.kind === track.track.kind)
702
+ // // }
703
+ // if(transceiver){
704
+ // this.printLogIfRequired("Replace track",participant,track)
705
+ // await transceiver.sender.replaceTrack(track.track)
706
+ // if (track.track.kind === 'audio' && transceiver && transceiver.sender) {
707
+ // // addTrack returns the sender directly
708
+ // this.applyAudioPriority(transceiver);
709
+ // // this.setOpusParamsForSender(transceiver.sender);
710
+ // }
711
+ // }
712
+ // else{
713
+ // this.printLogIfRequired("Send add track - reaplce track not found",participant,track)
714
+ // const sender = await peerConnection.rtcPeerConnection.addTrack(track.track)
715
+ // if (track.track.kind === 'audio') {
716
+ // // ✅ addTrack returns the sender directly
717
+ // const transceiver = peerConnection.rtcPeerConnection.getTransceivers().find(t => t.sender === sender);
718
+ // this.applyAudioPriority(transceiver);
719
+ // // this.setOpusParamsForSender(sender);
720
+ // }
721
+ // }
722
+ // peerConnection.rtcPeerConnection.addStream(new MediaStream([track.track]))
723
+ }
662
724
  }
725
+ return [2 /*return*/];
663
726
  });
664
727
  }); };
665
728
  _this.sendWebrtcMessage = function (data) {
@@ -726,6 +789,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
726
789
  };
727
790
  _this.applyAudioPriority = function (transceiver) {
728
791
  var _a, _b;
792
+ // return;
729
793
  // ✅ 1. Codec preference — Opus first
730
794
  var capabilities = (_a = RTCRtpSender.getCapabilities) === null || _a === void 0 ? void 0 : _a.call(RTCRtpSender, 'audio');
731
795
  if (capabilities === null || capabilities === void 0 ? void 0 : capabilities.codecs) {
@@ -745,19 +809,13 @@ var WebrtcHandler = /** @class */ (function (_super) {
745
809
  transceiver.sender.setParameters(params).catch(console.error);
746
810
  };
747
811
  _this.onNewTrack = function (track, receiver, transceiver, remoteParticipant) { return __awaiter(_this, void 0, void 0, function () {
748
- var kind, t, t;
749
- var _a, _b;
750
- return __generator(this, function (_c) {
812
+ var kind, t;
813
+ var _a;
814
+ return __generator(this, function (_b) {
751
815
  this.printLogIfRequired('ontrack fired', track.kind, track.id);
752
816
  kind = track.kind.toLowerCase() === 'audio' ? TrackKind.Audio : TrackKind.Video;
753
- if (remoteParticipant && remoteParticipant.isVideoEnable && kind === TrackKind.Video) {
754
- t = new Track(remoteParticipant, false, kind, track);
755
- (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.addUpdateRemoteTrack(t, remoteParticipant, true);
756
- }
757
- else if (remoteParticipant && remoteParticipant.isAudioEnable && kind === TrackKind.Audio) {
758
- t = new Track(remoteParticipant, false, kind, track);
759
- (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.addUpdateRemoteTrack(t, remoteParticipant, true);
760
- }
817
+ t = new Track(remoteParticipant, false, kind, track);
818
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.addUpdateRemoteTrack(t, remoteParticipant, true);
761
819
  return [2 /*return*/];
762
820
  });
763
821
  }); };
@@ -919,11 +977,17 @@ var WebrtcHandler = /** @class */ (function (_super) {
919
977
  WebrtcHandler.prototype.onUserJoined = function (participant) {
920
978
  return __awaiter(this, void 0, void 0, function () {
921
979
  return __generator(this, function (_a) {
922
- this.printLogIfRequired("onUserJoined", participant);
923
- if (participant.isStartMeetingCalled) {
924
- this.checkIfCanSendOffer(participant);
980
+ switch (_a.label) {
981
+ case 0:
982
+ this.printLogIfRequired("onUserJoined", participant);
983
+ if (!participant.isStartMeetingCalled) return [3 /*break*/, 2];
984
+ this.printLogIfRequired("onUserJoined INSIDE", participant);
985
+ return [4 /*yield*/, this.checkIfCanSendOffer(participant)];
986
+ case 1:
987
+ _a.sent();
988
+ _a.label = 2;
989
+ case 2: return [2 /*return*/];
925
990
  }
926
- return [2 /*return*/];
927
991
  });
928
992
  });
929
993
  };
@@ -942,7 +1006,8 @@ var WebrtcHandler = /** @class */ (function (_super) {
942
1006
  // Show UI banner: 'poor connection' / 'video paused' etc.
943
1007
  }, (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.deviceTier);
944
1008
  this.adaptationManager.start();
945
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Webrtc Init");
1009
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && this.printLogIfRequired(" Init", this.communicationHandler.getAllParticipants());
1010
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && this.printLogIfRequired("Webrtc Init");
946
1011
  this.communicationHandler.getAllParticipants().forEach(function (eachParticiapant) {
947
1012
  _this.onUserJoined(eachParticiapant);
948
1013
  });
@@ -951,7 +1016,18 @@ var WebrtcHandler = /** @class */ (function (_super) {
951
1016
  });
952
1017
  };
953
1018
  WebrtcHandler.prototype.onReconnect = function () {
954
- throw new Error("Method not implemented.");
1019
+ // // const selfParticpant = this.communicationHandler.getSelfParticipant()
1020
+ // // if(selfParticpant){
1021
+ // // selfParticpant.getPeerConnections().forEach((peerConnection, eachUserId)=>{
1022
+ // // if(peerConnection && peerConnection.rtcPeerConnection && (peerConnection.rtcPeerConnection.connectionState === 'disconnected' || peerConnection.rtcPeerConnection.connectionState === 'failed') ){
1023
+ // // const participant = this.communicationHandler?.participantByUserId(eachUserId)
1024
+ // // if(participant){
1025
+ // // this.onNegotiationNeeded(participant,true,0,false,true)
1026
+ // // }
1027
+ // // }
1028
+ // // })
1029
+ // }
1030
+ return;
955
1031
  };
956
1032
  WebrtcHandler.prototype.stopTrack = function (track) {
957
1033
  if (track.track) {
@@ -15,6 +15,7 @@ export declare enum WebSocketBasicEvents {
15
15
  OnVideoUnblockRequest = "videoUnblock",
16
16
  OnAudioBlockRequest = "audioBlock",
17
17
  OnVideoBlockRequest = "videoBlock",
18
+ UpdateParticipantData = "UpdateParticipantData",
18
19
  UpdateParticipant = "updateParticipant",
19
20
  OnParticipantUpdated = "participantUpdated",
20
21
  OnNewJoinee = "newJoinee",
@@ -70,6 +70,7 @@ export var WebSocketBasicEvents;
70
70
  WebSocketBasicEvents["OnVideoUnblockRequest"] = "videoUnblock";
71
71
  WebSocketBasicEvents["OnAudioBlockRequest"] = "audioBlock";
72
72
  WebSocketBasicEvents["OnVideoBlockRequest"] = "videoBlock";
73
+ WebSocketBasicEvents["UpdateParticipantData"] = "UpdateParticipantData";
73
74
  WebSocketBasicEvents["UpdateParticipant"] = "updateParticipant";
74
75
  WebSocketBasicEvents["OnParticipantUpdated"] = "participantUpdated";
75
76
  WebSocketBasicEvents["OnNewJoinee"] = "newJoinee";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client-native",
3
- "version": "0.3.7beta8",
3
+ "version": "0.3.9",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",