vani-meeting-client-native 0.2.5 → 0.2.6

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.
@@ -483,7 +483,6 @@ var MeetingHandler = /** @class */ (function () {
483
483
  MeetingHandler.prototype.checkSocket = function () {
484
484
  return __awaiter(this, void 0, void 0, function () {
485
485
  return __generator(this, function (_a) {
486
- debugger;
487
486
  if (!this.meetingStartRequest) {
488
487
  log.error("meetingStartRequestObject not found");
489
488
  return [2 /*return*/, false];
@@ -54,7 +54,7 @@ export declare class CommunicationHandler {
54
54
  sendWebSocketMessage(type: WebSocketEvents, data: any): void;
55
55
  onVideoCallWebSocketMessage(websocketMessage: WebSocketMessageBody): Promise<void>;
56
56
  onReconnect(): Promise<void>;
57
- onStartMeeingCalled(): void;
57
+ onStartMeeingCalled(): boolean;
58
58
  onAudioBlocked(data: any): void;
59
59
  onAudioUnblocked(data: any): void;
60
60
  onVideoBlocked(data: any): void;
@@ -507,6 +507,14 @@ var CommunicationHandler = /** @class */ (function () {
507
507
  if (this.isStartAndSetupWithServerCalled) {
508
508
  return;
509
509
  }
510
+ if (!this.meetingStartRequest) {
511
+ log.warn("meetingStartRequestObject not found onStartMeeingCalled");
512
+ return false;
513
+ }
514
+ if (!this.websocketCallHandler) {
515
+ log.warn("Init method not called onStartMeeingCalled");
516
+ return false;
517
+ }
510
518
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("onStartAndSetupWithServerCalled");
511
519
  this.isStartAndSetupWithServerCalled = true;
512
520
  var data = { user: (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.userId };
@@ -13,6 +13,8 @@ export declare class Participant {
13
13
  isAudioEnable: boolean;
14
14
  isStartMeetingCalled: boolean;
15
15
  isRecordingUser: boolean;
16
- peerConnections: Map<string, PeerConnection>;
16
+ private peerConnections;
17
+ getPeerConnections: () => Map<string, PeerConnection>;
18
+ getPeerConnectionsViaUserId: (userId: string) => PeerConnection;
17
19
  constructor(_userId: string, _roomId: string, _userData?: any, _isAdmin?: boolean);
18
20
  }
@@ -1,7 +1,9 @@
1
+ import { PeerConnection } from "./PeerConnection";
1
2
  var Participant = /** @class */ (function () {
2
3
  function Participant(_userId, _roomId, _userData, _isAdmin) {
3
4
  if (_userData === void 0) { _userData = {}; }
4
5
  if (_isAdmin === void 0) { _isAdmin = false; }
6
+ var _this = this;
5
7
  this.isAdmin = false;
6
8
  this.isAudioBlockedByAdmin = false;
7
9
  this.isVideoBlockedByAdmin = false;
@@ -13,6 +15,18 @@ var Participant = /** @class */ (function () {
13
15
  this.isStartMeetingCalled = false;
14
16
  this.isRecordingUser = false;
15
17
  this.peerConnections = new Map();
18
+ this.getPeerConnections = function () {
19
+ if (!_this.peerConnections) {
20
+ _this.peerConnections = new Map();
21
+ }
22
+ return _this.peerConnections;
23
+ };
24
+ this.getPeerConnectionsViaUserId = function (userId) {
25
+ if (!_this.getPeerConnections().has(userId)) {
26
+ _this.getPeerConnections().set(userId, new PeerConnection());
27
+ }
28
+ return _this.getPeerConnections().get(userId);
29
+ };
16
30
  this.userId = _userId;
17
31
  this.roomId = _roomId;
18
32
  this.userData = _userData;
@@ -1,6 +1,8 @@
1
1
  export declare class PeerConnection {
2
2
  rtcPeerConnection: any;
3
3
  offer: any;
4
+ remoteOffer: any;
4
5
  answer: any;
6
+ remoteAnswer: any;
5
7
  userId: string;
6
8
  }
@@ -8,8 +8,19 @@ export declare class WebrtcHandler extends BaseVideoCallHandler {
8
8
  resumeIncomingTrack(track: Track): void;
9
9
  pauseIncomingTrack(track: Track): void;
10
10
  onSocketMessage(websocketCallHandler: WebSocketMessageBody): void;
11
+ onNewOffer: (data: {
12
+ sdp: string;
13
+ type: string;
14
+ sender: Participant;
15
+ }) => Promise<void>;
16
+ onNewAnswer: (data: {
17
+ sdp: string;
18
+ type: string;
19
+ sender: Participant;
20
+ }) => Promise<void>;
11
21
  onAllParticipants(participants: Participant[]): Promise<void>;
12
22
  onUserJoined(participant: Participant): Promise<void>;
23
+ private sendWebrtcMessage;
13
24
  init(): Promise<void>;
14
25
  onReconnect(): Promise<void>;
15
26
  stopTrack(track: Track): void;
@@ -49,16 +49,65 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
49
49
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
50
  }
51
51
  };
52
+ import { WebrtcMessageType } from "../websocket-handler/WebsocketHandler";
52
53
  import { BaseVideoCallHandler } from "./BaseVideoCallHandler";
53
54
  import log from 'loglevel';
54
55
  import { LogLevel } from "../model/MeetingStartRequest";
55
56
  import { DynamicLibHelper } from "../utility/DynamicLibHelper";
56
- import { PeerConnection } from "../model/PeerConnection";
57
57
  var WebrtcHandler = /** @class */ (function (_super) {
58
58
  __extends(WebrtcHandler, _super);
59
59
  function WebrtcHandler() {
60
60
  var _this = _super !== null && _super.apply(this, arguments) || this;
61
61
  _this.dynamicLibHelper = (new DynamicLibHelper());
62
+ _this.onNewOffer = function (data) { return __awaiter(_this, void 0, void 0, function () {
63
+ var selfParticpant, participant, peerConnectionObject, peerConnection, answer, messageJson;
64
+ return __generator(this, function (_a) {
65
+ switch (_a.label) {
66
+ case 0:
67
+ selfParticpant = this.communicationHandler.getSelfParticipant();
68
+ participant = data.sender;
69
+ peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
70
+ if (peerConnectionObject) {
71
+ peerConnectionObject.remoteOffer = data.sdp;
72
+ }
73
+ peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
74
+ if (!peerConnection) return [3 /*break*/, 2];
75
+ peerConnection.addTransceiver("audio", { direction: "sendrecv" });
76
+ peerConnection.addTransceiver("video", { direction: "sendrecv" });
77
+ peerConnection.setRemoteDescription({ type: 'offer', sdp: peerConnectionObject.remoteOffer });
78
+ return [4 /*yield*/, peerConnection.createAnswer()];
79
+ case 1:
80
+ answer = _a.sent();
81
+ peerConnection.setLocalDescription(answer);
82
+ peerConnectionObject.answer = answer;
83
+ peerConnectionObject.rtcPeerConnection = peerConnection;
84
+ console.log("answer", answer);
85
+ messageJson = { to: participant.userId, type: WebrtcMessageType.SendAnswer, data: answer };
86
+ this.sendWebrtcMessage(messageJson);
87
+ _a.label = 2;
88
+ case 2: return [2 /*return*/];
89
+ }
90
+ });
91
+ }); };
92
+ _this.onNewAnswer = function (data) { return __awaiter(_this, void 0, void 0, function () {
93
+ var selfParticpant, participant, peerConnectionObject, peerConnection;
94
+ return __generator(this, function (_a) {
95
+ selfParticpant = this.communicationHandler.getSelfParticipant();
96
+ participant = data.sender;
97
+ peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
98
+ if (peerConnectionObject) {
99
+ peerConnectionObject.remoteAnswer = data.sdp;
100
+ }
101
+ peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
102
+ if (peerConnection) {
103
+ peerConnection.setRemoteDescription({ type: 'answer', sdp: peerConnectionObject.remoteAnswer });
104
+ }
105
+ return [2 /*return*/];
106
+ });
107
+ }); };
108
+ _this.sendWebrtcMessage = function (data) {
109
+ _this.communicationHandler.sendWebSocketMessage(WebrtcMessageType.WebrtcMessage, data);
110
+ };
62
111
  _this.isOfferInitParticipant = function (participant) {
63
112
  var selfParticpant = _this.communicationHandler.getSelfParticipant();
64
113
  if (participant.userId > selfParticpant.userId) {
@@ -69,16 +118,38 @@ var WebrtcHandler = /** @class */ (function (_super) {
69
118
  return _this;
70
119
  }
71
120
  WebrtcHandler.prototype.onParticipantUpdated = function () {
72
- throw new Error("Method not implemented.");
121
+ console.log("onParticipantUpdated");
122
+ // throw new Error("Method not implemented.");
73
123
  };
74
124
  WebrtcHandler.prototype.resumeIncomingTrack = function (track) {
75
- throw new Error("Method not implemented.");
125
+ // throw new Error("Method not implemented.");
76
126
  };
77
127
  WebrtcHandler.prototype.pauseIncomingTrack = function (track) {
78
- throw new Error("Method not implemented.");
128
+ // throw new Error("Method not implemented.");
79
129
  };
80
130
  WebrtcHandler.prototype.onSocketMessage = function (websocketCallHandler) {
81
- throw new Error("Method not implemented.");
131
+ var _a;
132
+ console.log("websocketCallHandler", websocketCallHandler);
133
+ var data = websocketCallHandler.data;
134
+ if (websocketCallHandler.data.message) {
135
+ data = websocketCallHandler.data.message;
136
+ }
137
+ if (data.sender && data.sender._id) {
138
+ var participant = this.communicationHandler.participantByUserId(data.sender._id);
139
+ if (!participant) {
140
+ data.sender = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.addParticipantIfNotExist(data.sender, false);
141
+ }
142
+ else {
143
+ data.sender = participant;
144
+ }
145
+ }
146
+ if (websocketCallHandler.type === WebrtcMessageType.SendOffer) {
147
+ this.onNewOffer(data);
148
+ }
149
+ else if (websocketCallHandler.type === WebrtcMessageType.SendAnswer) {
150
+ this.onNewAnswer(data);
151
+ }
152
+ // throw new Error("Method not implemented.");
82
153
  };
83
154
  WebrtcHandler.prototype.onAllParticipants = function (participants) {
84
155
  return __awaiter(this, void 0, void 0, function () {
@@ -93,19 +164,18 @@ var WebrtcHandler = /** @class */ (function (_super) {
93
164
  };
94
165
  WebrtcHandler.prototype.onUserJoined = function (participant) {
95
166
  return __awaiter(this, void 0, void 0, function () {
96
- var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer;
167
+ var selfParticpant, isOfferInitParticipant, peerConnectionObject, peerConnection, offer, messageJson;
97
168
  return __generator(this, function (_a) {
98
169
  switch (_a.label) {
99
170
  case 0:
100
171
  selfParticpant = this.communicationHandler.getSelfParticipant();
101
- if (!(selfParticpant.userId !== participant.userId && !selfParticpant.peerConnections.has(participant.userId))) return [3 /*break*/, 2];
172
+ console.log(selfParticpant);
173
+ if (!(selfParticpant.userId !== participant.userId && !selfParticpant.getPeerConnections().has(participant.userId))) return [3 /*break*/, 2];
174
+ console.log("onUserJoined ", participant);
102
175
  isOfferInitParticipant = this.isOfferInitParticipant(participant);
103
176
  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);
177
+ peerConnectionObject = selfParticpant.getPeerConnectionsViaUserId(participant.userId);
178
+ peerConnection = peerConnectionObject.rtcPeerConnection ? peerConnectionObject.rtcPeerConnection : this.dynamicLibHelper.getRTCPeerConnection(this.meetingStartRequest);
109
179
  if (!peerConnection) return [3 /*break*/, 2];
110
180
  peerConnection.addTransceiver("audio", { direction: "sendrecv" });
111
181
  peerConnection.addTransceiver("video", { direction: "sendrecv" });
@@ -114,8 +184,11 @@ var WebrtcHandler = /** @class */ (function (_super) {
114
184
  offer = _a.sent();
115
185
  peerConnection.setLocalDescription(offer);
116
186
  peerConnectionObject.offer = offer;
187
+ peerConnectionObject.rtcPeerConnection = peerConnection;
117
188
  // send offer to peer
118
189
  console.log("offer", offer);
190
+ messageJson = { to: participant.userId, type: WebrtcMessageType.SendOffer, data: offer };
191
+ this.sendWebrtcMessage(messageJson);
119
192
  _a.label = 2;
120
193
  case 2: return [2 /*return*/];
121
194
  }
@@ -134,16 +207,16 @@ var WebrtcHandler = /** @class */ (function (_super) {
134
207
  throw new Error("Method not implemented.");
135
208
  };
136
209
  WebrtcHandler.prototype.stopTrack = function (track) {
137
- throw new Error("Method not implemented.");
210
+ // throw new Error("Method not implemented.");
138
211
  };
139
212
  WebrtcHandler.prototype.pauseTrack = function (track) {
140
- throw new Error("Method not implemented.");
213
+ // throw new Error("Method not implemented.");
141
214
  };
142
215
  WebrtcHandler.prototype.resumeTrack = function (track) {
143
- throw new Error("Method not implemented.");
216
+ // throw new Error("Method not implemented.");
144
217
  };
145
218
  WebrtcHandler.prototype.sendTrack = function (track) {
146
- throw new Error("Method not implemented.");
219
+ // throw new Error("Method not implemented.");
147
220
  };
148
221
  WebrtcHandler.prototype.createDataChannel = function () {
149
222
  return __awaiter(this, void 0, void 0, function () {
@@ -153,7 +226,7 @@ var WebrtcHandler = /** @class */ (function (_super) {
153
226
  });
154
227
  };
155
228
  WebrtcHandler.prototype.sendMessageViaDataChannel = function (messagePayload) {
156
- throw new Error('Method not implemented.');
229
+ // throw new Error('Method not implemented.');
157
230
  };
158
231
  return WebrtcHandler;
159
232
  }(BaseVideoCallHandler));
@@ -32,6 +32,7 @@ export declare enum WebSocketBasicEvents {
32
32
  }
33
33
  export declare enum WebrtcMessageType {
34
34
  SendOffer = "SendOffer",
35
+ WebrtcMessage = "WebrtcMessage",
35
36
  SendAnswer = "SendAnswer"
36
37
  }
37
38
  export declare enum SFUMessageType {
@@ -88,6 +88,7 @@ export var WebSocketBasicEvents;
88
88
  export var WebrtcMessageType;
89
89
  (function (WebrtcMessageType) {
90
90
  WebrtcMessageType["SendOffer"] = "SendOffer";
91
+ WebrtcMessageType["WebrtcMessage"] = "WebrtcMessage";
91
92
  WebrtcMessageType["SendAnswer"] = "SendAnswer";
92
93
  })(WebrtcMessageType || (WebrtcMessageType = {}));
93
94
  export var SFUMessageType;
@@ -278,7 +279,6 @@ var WebsocketHandler = /** @class */ (function (_super) {
278
279
  if (!url_1.includes("connection=")) {
279
280
  url_1 = url_1 + "/?connection=";
280
281
  }
281
- debugger;
282
282
  if (url_1) {
283
283
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url_1);
284
284
  this.isWebSocketConnectionInProgress = true;
@@ -322,7 +322,6 @@ var WebsocketHandler = /** @class */ (function (_super) {
322
322
  }
323
323
  };
324
324
  this.wss.onclose = function (event) {
325
- debugger;
326
325
  _this.isSetUpDone = false;
327
326
  _this.isWebSocketConnectionInProgress = false;
328
327
  _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && ("WebSocket is closed now.");
@@ -489,6 +488,7 @@ var WebsocketHandler = /** @class */ (function (_super) {
489
488
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
490
489
  this.lastPingTimeStamp = new Date().getTime();
491
490
  // this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("lastPingTimeStamp time ", this.lastPingTimeStamp)
491
+ console.log("message", message);
492
492
  var messagejson = JSON.parse(message);
493
493
  if (messagejson.type && messagejson.data) {
494
494
  var type = messagejson.type;
@@ -612,9 +612,13 @@ var WebsocketHandler = /** @class */ (function (_super) {
612
612
  }
613
613
  };
614
614
  WebsocketHandler.prototype.isVideoCallControllerMessageType = function (type) {
615
+ console.log("isVideoCallControllerMessageType", type);
615
616
  if (Object.values(SFUMessageType).includes(type)) {
616
617
  return true;
617
618
  }
619
+ else if (Object.values(WebrtcMessageType).includes(type)) {
620
+ return true;
621
+ }
618
622
  return false;
619
623
  };
620
624
  return WebsocketHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client-native",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",