vani-meeting-client 2.1.5 → 2.1.7

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.
@@ -26,6 +26,7 @@ export declare class CommunicationHandler {
26
26
  getEventEmitter(): VaniEventListener;
27
27
  onAudioVideoStatusUpdated(data: any): void;
28
28
  restartTransport: () => Promise<void>;
29
+ updateSelfParticipantUserId(): void;
29
30
  getSelfParticipant(): Participant | undefined;
30
31
  downloadParticipantsData(): void;
31
32
  onServerParticipants(data: any): void;
@@ -194,6 +194,17 @@ var CommunicationHandler = /** @class */ (function () {
194
194
  }
195
195
  }
196
196
  };
197
+ CommunicationHandler.prototype.updateSelfParticipantUserId = function () {
198
+ var participant = this.getSelfParticipant();
199
+ var userId;
200
+ try {
201
+ userId = participant.userId.split("-").at(0);
202
+ }
203
+ catch (err) { }
204
+ if (this.meetingStartRequest && this.meetingStartRequest && this.meetingStartRequest.renewUserIdOnEveryReconnection) {
205
+ participant.userId = userId + "_" + new Date().getTime();
206
+ }
207
+ };
197
208
  CommunicationHandler.prototype.getSelfParticipant = function () {
198
209
  var _a;
199
210
  if (this.meetingStartRequest) {
@@ -219,6 +230,7 @@ var CommunicationHandler = /** @class */ (function () {
219
230
  };
220
231
  CommunicationHandler.prototype.onServerParticipants = function (data) {
221
232
  var _this = this;
233
+ var _a;
222
234
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(data);
223
235
  if (data && data.message) {
224
236
  var userIds = "";
@@ -232,6 +244,7 @@ var CommunicationHandler = /** @class */ (function () {
232
244
  // allParticiapntsToBeRemove.forEach(participant => {
233
245
  // this.removeParticipant(participant, true);
234
246
  // })
247
+ (_a = this.videoCallHandler) === null || _a === void 0 ? void 0 : _a.onAllParticipants(this.allParticipants);
235
248
  this.emitMessageToSource(VaniEvent.OnAllParticipants, this.allParticipants);
236
249
  }
237
250
  };
@@ -242,7 +255,7 @@ var CommunicationHandler = /** @class */ (function () {
242
255
  return this.allParticipants.find(function (participant) { return participant.userId === userId; });
243
256
  };
244
257
  CommunicationHandler.prototype.addParticipantIfNotExist = function (participant, shouldInfrom) {
245
- var _a, _b, _c;
258
+ var _a, _b, _c, _d;
246
259
  if (shouldInfrom === void 0) { shouldInfrom = false; }
247
260
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("addParticipantIfNotExist", this.allParticipants);
248
261
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("addParticipantIfNotExist new user", participant);
@@ -276,16 +289,17 @@ var CommunicationHandler = /** @class */ (function () {
276
289
  catch (err) {
277
290
  }
278
291
  this.allParticipants.push(participant);
292
+ (_c = this.videoCallHandler) === null || _c === void 0 ? void 0 : _c.onUserJoined(participant);
279
293
  if (shouldInfrom) {
280
294
  this.emitMessageToSource(VaniEvent.OnUserJoined, participant);
281
295
  }
282
- (_c = this.videoCallHandler) === null || _c === void 0 ? void 0 : _c.onParticipantUpdated();
296
+ (_d = this.videoCallHandler) === null || _d === void 0 ? void 0 : _d.onParticipantUpdated();
283
297
  return participant;
284
298
  }
285
299
  };
286
300
  CommunicationHandler.prototype.removeParticipant = function (participant, shouldInfrom) {
287
301
  var _this = this;
288
- var _a;
302
+ var _a, _b;
289
303
  if (shouldInfrom === void 0) { shouldInfrom = false; }
290
304
  var tracks = this.getAllTracksForParticipant(participant);
291
305
  if (tracks) {
@@ -295,6 +309,7 @@ var CommunicationHandler = /** @class */ (function () {
295
309
  }
296
310
  Utility.deleteArrayObject(participant, this.allParticipants);
297
311
  (_a = this.videoCallHandler) === null || _a === void 0 ? void 0 : _a.onParticipantUpdated();
312
+ (_b = this.videoCallHandler) === null || _b === void 0 ? void 0 : _b.onUserLeft(participant);
298
313
  if (shouldInfrom) {
299
314
  this.emitMessageToSource(VaniEvent.OnUserLeft, participant);
300
315
  }
@@ -460,6 +475,9 @@ var CommunicationHandler = /** @class */ (function () {
460
475
  var _a;
461
476
  (_a = this.websocketCallHandler) === null || _a === void 0 ? void 0 : _a.sendSocketMessage(type, data);
462
477
  };
478
+ // public sendWebSocketMessageForWebrtc(type: WebrtcMessageType, data: any, to : string) {
479
+ // this.websocketCallHandler?.sendSocketMessage(type, data)
480
+ // }
463
481
  CommunicationHandler.prototype.onVideoCallWebSocketMessage = function (websocketMessage) {
464
482
  var _a;
465
483
  return __awaiter(this, void 0, void 0, function () {
@@ -556,7 +574,7 @@ var CommunicationHandler = /** @class */ (function () {
556
574
  this.internetReachbilityTimeout = window.setTimeout(this.checkIfInternetReachable, 200, 0);
557
575
  };
558
576
  CommunicationHandler.prototype.onApiResponded = function (count) {
559
- var _a, _b, _c;
577
+ var _a, _b, _c, _d;
560
578
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onApiResponded", count);
561
579
  if (this.isReachable === false) {
562
580
  this.isReachable = true;
@@ -567,12 +585,13 @@ var CommunicationHandler = /** @class */ (function () {
567
585
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onApiResponded inside", count);
568
586
  if (this.meetingStartRequest && this.meetingStartRequest.isMobileApp) {
569
587
  if ((_a = this.websocketCallHandler) === null || _a === void 0 ? void 0 : _a.isWebScoketConnected()) {
588
+ (_b = this.videoCallHandler) === null || _b === void 0 ? void 0 : _b.reconnectedWithoutPing();
570
589
  return;
571
590
  }
572
591
  this.websocketCallHandler.reconnectOnInternetFailur();
573
592
  }
574
- else if ((_b = this.websocketCallHandler) === null || _b === void 0 ? void 0 : _b.isWebScoketConnected()) {
575
- (_c = this.videoCallHandler) === null || _c === void 0 ? void 0 : _c.reconnectedWithoutPing();
593
+ else if ((_c = this.websocketCallHandler) === null || _c === void 0 ? void 0 : _c.isWebScoketConnected()) {
594
+ (_d = this.videoCallHandler) === null || _d === void 0 ? void 0 : _d.reconnectedWithoutPing();
576
595
  }
577
596
  else {
578
597
  this.websocketCallHandler.reconnectOnInternetFailur();
@@ -33,6 +33,7 @@ export declare class MeetingStartRequest {
33
33
  wssUrl: string;
34
34
  minBitrateConfig: number;
35
35
  maxBitRateConfig: number;
36
+ renewUserIdOnEveryReconnection: boolean;
36
37
  maxAudioBitrateConfig: number;
37
38
  logLevel: LogLevel;
38
39
  dynamicWebSocketFetchBaseUrl?: string;
@@ -33,6 +33,7 @@ var MeetingStartRequest = /** @class */ (function () {
33
33
  this.shouldForceTurn = false;
34
34
  this.minBitrateConfig = 40000;
35
35
  this.maxBitRateConfig = 620000;
36
+ this.renewUserIdOnEveryReconnection = false;
36
37
  this.maxAudioBitrateConfig = -1;
37
38
  this.logLevel = LogLevel.None;
38
39
  this.isRecordingUser = false;
@@ -1,3 +1,4 @@
1
+ import { PeerConnection } from "./PeerConnection";
1
2
  export declare class Participant {
2
3
  userId: string;
3
4
  userData: any;
@@ -12,5 +13,6 @@ export declare class Participant {
12
13
  isAudioEnable: boolean;
13
14
  isStartMeetingCalled: boolean;
14
15
  isRecordingUser: boolean;
16
+ peerConnections: Map<string, PeerConnection>;
15
17
  constructor(_userId: string, _roomId: string, _userData?: any, _isAdmin?: boolean);
16
18
  }
@@ -12,6 +12,7 @@ var Participant = /** @class */ (function () {
12
12
  this.isAudioEnable = false;
13
13
  this.isStartMeetingCalled = false;
14
14
  this.isRecordingUser = false;
15
+ this.peerConnections = new Map();
15
16
  this.userId = _userId;
16
17
  this.roomId = _roomId;
17
18
  this.userData = _userData;
@@ -0,0 +1,6 @@
1
+ export declare class PeerConnection {
2
+ rtcPeerConnection: any;
3
+ offer: any;
4
+ answer: any;
5
+ userId: string;
6
+ }
@@ -0,0 +1,6 @@
1
+ var PeerConnection = /** @class */ (function () {
2
+ function PeerConnection() {
3
+ }
4
+ return PeerConnection;
5
+ }());
6
+ export { PeerConnection };
@@ -5,4 +5,5 @@ export declare class DynamicLibHelper {
5
5
  getVideoCallClassHandler(meetingType: MeetingType, meetingStartRequest: MeetingStartRequest, _communicationHandler: CommunicationHandler): Promise<import("../video-call-handler/SFUHandler").SFUHandler | import("../video-call-handler/WebrtcHandler").WebrtcHandler>;
6
6
  getMediaDevicesVariable(meetingStartRequest: MeetingStartRequest): any;
7
7
  getMediaStreamVariable(meetingStartRequest: MeetingStartRequest): any;
8
+ getRTCPeerConnection(meetingStartRequest: MeetingStartRequest): any;
8
9
  }
@@ -103,6 +103,9 @@ var DynamicLibHelper = /** @class */ (function () {
103
103
  }
104
104
  return MediaStream;
105
105
  };
106
+ DynamicLibHelper.prototype.getRTCPeerConnection = function (meetingStartRequest) {
107
+ return new RTCPeerConnection();
108
+ };
106
109
  return DynamicLibHelper;
107
110
  }());
108
111
  export { DynamicLibHelper };
@@ -5,4 +5,5 @@ export declare class DynamicLibHelper {
5
5
  getVideoCallClassHandler(meetingType: MeetingType, meetingStartRequest: MeetingStartRequest, _communicationHandler: CommunicationHandler): Promise<import("../video-call-handler/SFUHandler").SFUHandler | import("../video-call-handler/WebrtcHandler").WebrtcHandler>;
6
6
  getMediaDevicesVariable(meetingStartRequest: MeetingStartRequest): any;
7
7
  getMediaStreamVariable(meetingStartRequest: MeetingStartRequest): any;
8
+ getRTCPeerConnection(meetingStartRequest: MeetingStartRequest): any;
8
9
  }
@@ -102,6 +102,17 @@ var DynamicLibHelper = /** @class */ (function () {
102
102
  }
103
103
  return MediaStream;
104
104
  };
105
+ DynamicLibHelper.prototype.getRTCPeerConnection = function (meetingStartRequest) {
106
+ try {
107
+ if (meetingStartRequest === null || meetingStartRequest === void 0 ? void 0 : meetingStartRequest.isMobileApp) {
108
+ return new (require("react-native-webrtc").RTCPeerConnection)();
109
+ }
110
+ }
111
+ catch (err) {
112
+ log.error("react-native-webrtc not found. Please do npm install ");
113
+ }
114
+ return new RTCPeerConnection();
115
+ };
105
116
  return DynamicLibHelper;
106
117
  }());
107
118
  export { DynamicLibHelper };
@@ -5,4 +5,5 @@ export declare class DynamicLibHelper {
5
5
  getVideoCallClassHandler(meetingType: MeetingType, meetingStartRequest: MeetingStartRequest, _communicationHandler: CommunicationHandler): Promise<import("../video-call-handler/SFUHandler").SFUHandler | import("../video-call-handler/WebrtcHandler").WebrtcHandler>;
6
6
  getMediaDevicesVariable(meetingStartRequest: MeetingStartRequest): any;
7
7
  getMediaStreamVariable(meetingStartRequest: MeetingStartRequest): any;
8
+ getRTCPeerConnection(meetingStartRequest: MeetingStartRequest): any;
8
9
  }
@@ -103,6 +103,9 @@ var DynamicLibHelper = /** @class */ (function () {
103
103
  }
104
104
  return MediaStream;
105
105
  };
106
+ DynamicLibHelper.prototype.getRTCPeerConnection = function (meetingStartRequest) {
107
+ return new RTCPeerConnection();
108
+ };
106
109
  return DynamicLibHelper;
107
110
  }());
108
111
  export { DynamicLibHelper };
@@ -1,5 +1,6 @@
1
1
  import { Track } from "../model/Track";
2
2
  import { WebSocketMessageBody } from "../websocket-handler/WebsocketHandler";
3
+ import { Participant } from "../model/Participant";
3
4
  import { Base } from "../base/Base";
4
5
  import { TrackStats } from "../model/TrackStats";
5
6
  export declare abstract class BaseVideoCallHandler extends Base {
@@ -16,6 +17,9 @@ export declare abstract class BaseVideoCallHandler extends Base {
16
17
  abstract onParticipantUpdated(): void;
17
18
  abstract createDataChannel(): any;
18
19
  abstract sendMessageViaDataChannel(messagePayload: any): any;
20
+ onAllParticipants(participants: Participant[]): Promise<void>;
21
+ onUserJoined(participants: Participant): Promise<void>;
22
+ onUserLeft(participants: Participant): Promise<void>;
19
23
  getConsumerForTrack(track: Track): void;
20
24
  resumeProducerOrConsumerForTrack(track: Track): Promise<void>;
21
25
  pauseProducerOrConsumerForTrack(track: Track): Promise<void>;
@@ -68,6 +68,27 @@ var BaseVideoCallHandler = /** @class */ (function (_super) {
68
68
  _super.prototype.onObjectCreated.call(this);
69
69
  (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.setVideoCallHandler(this);
70
70
  };
71
+ BaseVideoCallHandler.prototype.onAllParticipants = function (participants) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ return __generator(this, function (_a) {
74
+ return [2 /*return*/];
75
+ });
76
+ });
77
+ };
78
+ BaseVideoCallHandler.prototype.onUserJoined = function (participants) {
79
+ return __awaiter(this, void 0, void 0, function () {
80
+ return __generator(this, function (_a) {
81
+ return [2 /*return*/];
82
+ });
83
+ });
84
+ };
85
+ BaseVideoCallHandler.prototype.onUserLeft = function (participants) {
86
+ return __awaiter(this, void 0, void 0, function () {
87
+ return __generator(this, function (_a) {
88
+ return [2 /*return*/];
89
+ });
90
+ });
91
+ };
71
92
  BaseVideoCallHandler.prototype.getConsumerForTrack = function (track) {
72
93
  };
73
94
  BaseVideoCallHandler.prototype.resumeProducerOrConsumerForTrack = function (track) {
@@ -266,7 +266,9 @@ var SFUHandler = /** @class */ (function (_super) {
266
266
  case 3:
267
267
  _b.sent();
268
268
  _b.label = 4;
269
- case 4: return [2 /*return*/];
269
+ case 4:
270
+ this.communicationHandler.onReconnect();
271
+ return [2 /*return*/];
270
272
  }
271
273
  });
272
274
  });
@@ -428,7 +430,7 @@ var SFUHandler = /** @class */ (function (_super) {
428
430
  producerData.encodings = this.meetingStartRequest.simulcastEncodings;
429
431
  }
430
432
  if (track.track.kind === "audio") {
431
- producerData.codecOptions = { opusStereo: true, opusFec: true };
433
+ producerData.codecOptions = { opusStereo: true, opusFec: true, opusDtx: true };
432
434
  if (this.meetingStartRequest.maxAudioBitrateConfig > 0) {
433
435
  producerData.codecOptions.opusMaxAverageBitrate = (_d = this.meetingStartRequest) === null || _d === void 0 ? void 0 : _d.maxAudioBitrateConfig;
434
436
  }
@@ -1,11 +1,15 @@
1
+ import { Participant } from "../model/Participant";
1
2
  import { Track } from "../model/Track";
2
3
  import { WebSocketMessageBody } from "../websocket-handler/WebsocketHandler";
3
4
  import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
4
5
  export declare class WebrtcHandler extends BaseVideoCallHandler {
6
+ private dynamicLibHelper;
5
7
  onParticipantUpdated(): void;
6
8
  resumeIncomingTrack(track: Track): void;
7
9
  pauseIncomingTrack(track: Track): void;
8
10
  onSocketMessage(websocketCallHandler: WebSocketMessageBody): void;
11
+ onAllParticipants(participants: Participant[]): Promise<void>;
12
+ onUserJoined(participant: Participant): Promise<void>;
9
13
  init(): Promise<void>;
10
14
  onReconnect(): Promise<void>;
11
15
  stopTrack(track: Track): void;
@@ -14,4 +18,5 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
14
18
  sendTrack(track: Track): void;
15
19
  createDataChannel(): Promise<void>;
16
20
  sendMessageViaDataChannel(messagePayload: any): void;
21
+ private isOfferInitParticipant;
17
22
  }
@@ -52,10 +52,21 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
53
53
  import log from 'loglevel';
54
54
  import { LogLevel } from "../model/MeetingStartRequest";
55
+ import { DynamicLibHelper } from "../utility/DynamicLibHelper";
56
+ import { PeerConnection } from "../model/PeerConnection";
55
57
  var WebrtcHandler = /** @class */ (function (_super) {
56
58
  __extends(WebrtcHandler, _super);
57
59
  function WebrtcHandler() {
58
- return _super !== null && _super.apply(this, arguments) || this;
60
+ var _this = _super !== null && _super.apply(this, arguments) || this;
61
+ _this.dynamicLibHelper = (new DynamicLibHelper());
62
+ _this.isOfferInitParticipant = function (participant) {
63
+ var selfParticpant = _this.communicationHandler.getSelfParticipant();
64
+ if (participant.userId > selfParticpant.userId) {
65
+ return true;
66
+ }
67
+ return false;
68
+ };
69
+ return _this;
59
70
  }
60
71
  WebrtcHandler.prototype.onParticipantUpdated = function () {
61
72
  throw new Error("Method not implemented.");
@@ -69,6 +80,48 @@ var WebrtcHandler = /** @class */ (function (_super) {
69
80
  WebrtcHandler.prototype.onSocketMessage = function (websocketCallHandler) {
70
81
  throw new Error("Method not implemented.");
71
82
  };
83
+ WebrtcHandler.prototype.onAllParticipants = function (participants) {
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var _this = this;
86
+ return __generator(this, function (_a) {
87
+ participants.forEach(function (eachParticiapant) {
88
+ _this.onUserJoined(eachParticiapant);
89
+ });
90
+ return [2 /*return*/];
91
+ });
92
+ });
93
+ };
94
+ WebrtcHandler.prototype.onUserJoined = function (participant) {
95
+ return __awaiter(this, void 0, void 0, function () {
96
+ var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer;
97
+ return __generator(this, function (_a) {
98
+ switch (_a.label) {
99
+ case 0:
100
+ selfParticpant = this.communicationHandler.getSelfParticipant();
101
+ if (!(selfParticpant.userId !== participant.userId && !selfParticpant.peerConnections.has(participant.userId))) return [3 /*break*/, 2];
102
+ isOfferInitParticipant = this.isOfferInitParticipant(participant);
103
+ if (!!isOfferInitParticipant) return [3 /*break*/, 2];
104
+ if (!selfParticpant.peerConnections.has(participant.userId)) {
105
+ selfParticpant.peerConnections.set(participant.userId, new PeerConnection());
106
+ }
107
+ peerConnectionObject = selfParticpant.peerConnections.get(participant.userId);
108
+ peerConnection = this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
109
+ if (!peerConnection) return [3 /*break*/, 2];
110
+ peerConnection.addTransceiver("audio", { direction: "sendrecv" });
111
+ peerConnection.addTransceiver("video", { direction: "sendrecv" });
112
+ return [4 /*yield*/, peerConnection.createOffer()];
113
+ case 1:
114
+ offer = _a.sent();
115
+ peerConnection.setLocalDescription(offer);
116
+ peerConnectionObject.offer = offer;
117
+ // send offer to peer
118
+ console.log("offer", offer);
119
+ _a.label = 2;
120
+ case 2: return [2 /*return*/];
121
+ }
122
+ });
123
+ });
124
+ };
72
125
  WebrtcHandler.prototype.init = function () {
73
126
  return __awaiter(this, void 0, void 0, function () {
74
127
  return __generator(this, function (_a) {
@@ -30,6 +30,10 @@ export declare enum WebSocketBasicEvents {
30
30
  OnChat = "chat",
31
31
  SelfLeft = "selfLeft"
32
32
  }
33
+ export declare enum WebrtcMessageType {
34
+ SendOffer = "SendOffer",
35
+ SendAnswer = "SendAnswer"
36
+ }
33
37
  export declare enum SFUMessageType {
34
38
  SFUMessage = "sfuMessage",
35
39
  GetRouterRtpCapabilities = "routerRtpCapabilities",
@@ -70,7 +74,7 @@ export declare enum SFUMessageType {
70
74
  OnProducerScoreChange = "OnProducerScoreChange",
71
75
  OnConsumerLayerChange = "OnConsumerLayerChange"
72
76
  }
73
- export type WebSocketEvents = SFUMessageType | WebSocketBasicEvents;
77
+ export type WebSocketEvents = SFUMessageType | WebSocketBasicEvents | WebrtcMessageType;
74
78
  export interface WebSocketMessageBody {
75
79
  type?: WebSocketEvents;
76
80
  data?: any;
@@ -85,6 +85,11 @@ export var WebSocketBasicEvents;
85
85
  WebSocketBasicEvents["OnChat"] = "chat";
86
86
  WebSocketBasicEvents["SelfLeft"] = "selfLeft";
87
87
  })(WebSocketBasicEvents || (WebSocketBasicEvents = {}));
88
+ export var WebrtcMessageType;
89
+ (function (WebrtcMessageType) {
90
+ WebrtcMessageType["SendOffer"] = "SendOffer";
91
+ WebrtcMessageType["SendAnswer"] = "SendAnswer";
92
+ })(WebrtcMessageType || (WebrtcMessageType = {}));
88
93
  export var SFUMessageType;
89
94
  (function (SFUMessageType) {
90
95
  SFUMessageType["SFUMessage"] = "sfuMessage";
@@ -389,6 +394,7 @@ var WebsocketHandler = /** @class */ (function (_super) {
389
394
  if (this.isWebScoketConnected() === false) {
390
395
  return;
391
396
  }
397
+ this.communicationHandler.updateSelfParticipantUserId();
392
398
  var participant = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
393
399
  participant.userData = (_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.userData;
394
400
  var config = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",