vani-meeting-client 2.1.6 → 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.
@@ -201,7 +201,9 @@ var CommunicationHandler = /** @class */ (function () {
201
201
  userId = participant.userId.split("-").at(0);
202
202
  }
203
203
  catch (err) { }
204
- participant.userId = userId + "_" + new Date().getTime();
204
+ if (this.meetingStartRequest && this.meetingStartRequest && this.meetingStartRequest.renewUserIdOnEveryReconnection) {
205
+ participant.userId = userId + "_" + new Date().getTime();
206
+ }
205
207
  };
206
208
  CommunicationHandler.prototype.getSelfParticipant = function () {
207
209
  var _a;
@@ -228,6 +230,7 @@ var CommunicationHandler = /** @class */ (function () {
228
230
  };
229
231
  CommunicationHandler.prototype.onServerParticipants = function (data) {
230
232
  var _this = this;
233
+ var _a;
231
234
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(data);
232
235
  if (data && data.message) {
233
236
  var userIds = "";
@@ -241,6 +244,7 @@ var CommunicationHandler = /** @class */ (function () {
241
244
  // allParticiapntsToBeRemove.forEach(participant => {
242
245
  // this.removeParticipant(participant, true);
243
246
  // })
247
+ (_a = this.videoCallHandler) === null || _a === void 0 ? void 0 : _a.onAllParticipants(this.allParticipants);
244
248
  this.emitMessageToSource(VaniEvent.OnAllParticipants, this.allParticipants);
245
249
  }
246
250
  };
@@ -251,7 +255,7 @@ var CommunicationHandler = /** @class */ (function () {
251
255
  return this.allParticipants.find(function (participant) { return participant.userId === userId; });
252
256
  };
253
257
  CommunicationHandler.prototype.addParticipantIfNotExist = function (participant, shouldInfrom) {
254
- var _a, _b, _c;
258
+ var _a, _b, _c, _d;
255
259
  if (shouldInfrom === void 0) { shouldInfrom = false; }
256
260
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("addParticipantIfNotExist", this.allParticipants);
257
261
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("addParticipantIfNotExist new user", participant);
@@ -285,16 +289,17 @@ var CommunicationHandler = /** @class */ (function () {
285
289
  catch (err) {
286
290
  }
287
291
  this.allParticipants.push(participant);
292
+ (_c = this.videoCallHandler) === null || _c === void 0 ? void 0 : _c.onUserJoined(participant);
288
293
  if (shouldInfrom) {
289
294
  this.emitMessageToSource(VaniEvent.OnUserJoined, participant);
290
295
  }
291
- (_c = this.videoCallHandler) === null || _c === void 0 ? void 0 : _c.onParticipantUpdated();
296
+ (_d = this.videoCallHandler) === null || _d === void 0 ? void 0 : _d.onParticipantUpdated();
292
297
  return participant;
293
298
  }
294
299
  };
295
300
  CommunicationHandler.prototype.removeParticipant = function (participant, shouldInfrom) {
296
301
  var _this = this;
297
- var _a;
302
+ var _a, _b;
298
303
  if (shouldInfrom === void 0) { shouldInfrom = false; }
299
304
  var tracks = this.getAllTracksForParticipant(participant);
300
305
  if (tracks) {
@@ -304,6 +309,7 @@ var CommunicationHandler = /** @class */ (function () {
304
309
  }
305
310
  Utility.deleteArrayObject(participant, this.allParticipants);
306
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);
307
313
  if (shouldInfrom) {
308
314
  this.emitMessageToSource(VaniEvent.OnUserLeft, participant);
309
315
  }
@@ -469,6 +475,9 @@ var CommunicationHandler = /** @class */ (function () {
469
475
  var _a;
470
476
  (_a = this.websocketCallHandler) === null || _a === void 0 ? void 0 : _a.sendSocketMessage(type, data);
471
477
  };
478
+ // public sendWebSocketMessageForWebrtc(type: WebrtcMessageType, data: any, to : string) {
479
+ // this.websocketCallHandler?.sendSocketMessage(type, data)
480
+ // }
472
481
  CommunicationHandler.prototype.onVideoCallWebSocketMessage = function (websocketMessage) {
473
482
  var _a;
474
483
  return __awaiter(this, void 0, void 0, function () {
@@ -565,7 +574,7 @@ var CommunicationHandler = /** @class */ (function () {
565
574
  this.internetReachbilityTimeout = window.setTimeout(this.checkIfInternetReachable, 200, 0);
566
575
  };
567
576
  CommunicationHandler.prototype.onApiResponded = function (count) {
568
- var _a, _b, _c;
577
+ var _a, _b, _c, _d;
569
578
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onApiResponded", count);
570
579
  if (this.isReachable === false) {
571
580
  this.isReachable = true;
@@ -576,12 +585,13 @@ var CommunicationHandler = /** @class */ (function () {
576
585
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onApiResponded inside", count);
577
586
  if (this.meetingStartRequest && this.meetingStartRequest.isMobileApp) {
578
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();
579
589
  return;
580
590
  }
581
591
  this.websocketCallHandler.reconnectOnInternetFailur();
582
592
  }
583
- else if ((_b = this.websocketCallHandler) === null || _b === void 0 ? void 0 : _b.isWebScoketConnected()) {
584
- (_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();
585
595
  }
586
596
  else {
587
597
  this.websocketCallHandler.reconnectOnInternetFailur();
@@ -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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client",
3
- "version": "2.1.6",
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",