vani-meeting-client-native 0.2.0 → 0.2.2

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.
package/lib/.DS_Store ADDED
Binary file
@@ -14,7 +14,9 @@ export declare class MeetingHandler {
14
14
  private userMediaHandler?;
15
15
  meetingStartRequestObject(roomId: string, userId: string, appId: string, wssUrl: string, shouldIgnoreCaseForRoomId?: boolean): MeetingStartRequest;
16
16
  endAndDestory(): void;
17
+ cleanupWebsocket: () => void;
17
18
  requestToCloseTheRoom: () => void;
19
+ preconnect: (url: string) => Promise<void>;
18
20
  init(): Promise<boolean>;
19
21
  recreateVideoCallHandler: () => Promise<BaseVideoCallHandler>;
20
22
  switchCamera(): void;
@@ -46,10 +46,28 @@ var MeetingHandler = /** @class */ (function () {
46
46
  function MeetingHandler() {
47
47
  var _this = this;
48
48
  this.communicationHandler = new CommunicationHandler(this);
49
+ this.cleanupWebsocket = function () {
50
+ var _a;
51
+ try {
52
+ (_a = _this.websocketCallHandler) === null || _a === void 0 ? void 0 : _a.cleanup();
53
+ _this.websocketCallHandler = undefined;
54
+ }
55
+ catch (err) {
56
+ }
57
+ };
49
58
  this.requestToCloseTheRoom = function () {
50
59
  var _a;
51
60
  (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.requestToCloseTheRoom();
52
61
  };
62
+ this.preconnect = function (url) { return __awaiter(_this, void 0, void 0, function () {
63
+ return __generator(this, function (_a) {
64
+ if (!this.websocketCallHandler) {
65
+ this.websocketCallHandler = new WebsocketHandler(this.meetingStartRequest, this.communicationHandler);
66
+ }
67
+ this.websocketCallHandler.startSocketConnection(true, url);
68
+ return [2 /*return*/];
69
+ });
70
+ }); };
53
71
  this.recreateVideoCallHandler = function () { return __awaiter(_this, void 0, void 0, function () {
54
72
  var _a;
55
73
  var _b;
@@ -140,11 +158,19 @@ var MeetingHandler = /** @class */ (function () {
140
158
  return [4 /*yield*/, new DynamicLibHelper().getVideoCallClassHandler((_c = this.meetingStartRequest) === null || _c === void 0 ? void 0 : _c.meetingType, this.meetingStartRequest, this.communicationHandler)];
141
159
  case 3:
142
160
  _e.videoCallHandler = _f.sent();
143
- _f.label = 4;
161
+ return [3 /*break*/, 5];
144
162
  case 4:
163
+ if (this.meetingStartRequest) {
164
+ this.videoCallHandler.setMeetingRequest(this.meetingStartRequest);
165
+ }
166
+ _f.label = 5;
167
+ case 5:
145
168
  if (!this.websocketCallHandler) {
146
169
  this.websocketCallHandler = new WebsocketHandler(this.meetingStartRequest, this.communicationHandler);
147
170
  }
171
+ else if (this.meetingStartRequest) {
172
+ this.websocketCallHandler.setMeetingRequest(this.meetingStartRequest);
173
+ }
148
174
  // this.handleGA();
149
175
  this.emitMessageToSource(VaniEvent.OnInitDone, {});
150
176
  return [2 /*return*/, true];
@@ -450,6 +476,7 @@ var MeetingHandler = /** @class */ (function () {
450
476
  MeetingHandler.prototype.checkSocket = function () {
451
477
  return __awaiter(this, void 0, void 0, function () {
452
478
  return __generator(this, function (_a) {
479
+ debugger;
453
480
  if (!this.meetingStartRequest) {
454
481
  log.error("meetingStartRequestObject not found");
455
482
  return [2 /*return*/, false];
@@ -4,6 +4,7 @@ export declare abstract class Base {
4
4
  protected meetingStartRequest?: MeetingStartRequest;
5
5
  protected communicationHandler?: CommunicationHandler;
6
6
  constructor(_meetingStartRequest: MeetingStartRequest, _communicationHandler: CommunicationHandler);
7
+ setMeetingRequest: (_meetingStartRequest: MeetingStartRequest) => void;
7
8
  protected onObjectCreated(): void;
8
9
  cleanup(): void;
9
10
  }
package/lib/base/Base.js CHANGED
@@ -1,5 +1,9 @@
1
1
  var Base = /** @class */ (function () {
2
2
  function Base(_meetingStartRequest, _communicationHandler) {
3
+ var _this = this;
4
+ this.setMeetingRequest = function (_meetingStartRequest) {
5
+ _this.meetingStartRequest = _meetingStartRequest;
6
+ };
3
7
  this.meetingStartRequest = _meetingStartRequest;
4
8
  this.communicationHandler = _communicationHandler;
5
9
  this.onObjectCreated();
@@ -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 () {
@@ -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 };
@@ -258,10 +258,7 @@ var UserMediaHandler = /** @class */ (function (_super) {
258
258
  };
259
259
  UserMediaHandler.prototype.getAudioDictionay = function () {
260
260
  var permissionDict = {
261
- echoCancellation: true, noiseSuppression: true, autoGainControl: true, latency: 0.001, googAutoGainControl: false,
262
- googNoiseSuppression: true,
263
- googEchoCancellation: true,
264
- googHighpassFilter: true
261
+ echoCancellation: true, noiseSuppression: true, autoGainControl: true
265
262
  };
266
263
  return permissionDict;
267
264
  };
@@ -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
  }
@@ -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) {
@@ -430,7 +430,7 @@ var SFUHandler = /** @class */ (function (_super) {
430
430
  producerData.encodings = this.meetingStartRequest.simulcastEncodings;
431
431
  }
432
432
  if (track.track.kind === "audio") {
433
- producerData.codecOptions = { opusStereo: true, opusFec: true };
433
+ producerData.codecOptions = { opusStereo: true, opusFec: true, opusDtx: true };
434
434
  if (this.meetingStartRequest.maxAudioBitrateConfig > 0) {
435
435
  producerData.codecOptions.opusMaxAverageBitrate = (_d = this.meetingStartRequest) === null || _d === void 0 ? void 0 : _d.maxAudioBitrateConfig;
436
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,12 +74,13 @@ 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;
77
81
  }
78
82
  export declare class WebsocketHandler extends Base {
83
+ private websocketConnectionUrl?;
79
84
  private loadBalancerIpAddressForWebSocket?;
80
85
  private isEnded;
81
86
  private isWebSocketConnectionInProgress;
@@ -89,8 +94,9 @@ export declare class WebsocketHandler extends Base {
89
94
  private lastPingTimeStamp;
90
95
  protected onObjectCreated(): void;
91
96
  cleanup(): Promise<void>;
92
- startSocketConnection(): Promise<void>;
97
+ startSocketConnection(isForPreConnect?: boolean, url?: string): Promise<void>;
93
98
  private connect;
99
+ isWebScoketConnectedWithoutSetup(): boolean;
94
100
  isWebScoketConnected(): boolean;
95
101
  sendSocketMessage(type: WebSocketEvents, data: any): void;
96
102
  reconnectOnInternetFailur(): void;
@@ -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";
@@ -192,16 +197,16 @@ var WebsocketHandler = /** @class */ (function (_super) {
192
197
  });
193
198
  });
194
199
  };
195
- WebsocketHandler.prototype.startSocketConnection = function () {
200
+ WebsocketHandler.prototype.startSocketConnection = function (isForPreConnect, url) {
196
201
  return __awaiter(this, void 0, void 0, function () {
197
202
  var request, urlToGetIpAddress, config;
198
203
  var _this = this;
199
204
  return __generator(this, function (_a) {
200
- if (!this.meetingStartRequest) {
205
+ if (!this.meetingStartRequest && !isForPreConnect) {
201
206
  log.log("meetingStartRequest not found on startSocketConnection");
202
207
  return [2 /*return*/];
203
208
  }
204
- if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
209
+ if (!isForPreConnect && this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
205
210
  if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl.endsWith("/") === false) {
206
211
  this.meetingStartRequest.dynamicWebSocketFetchBaseUrl = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "/";
207
212
  }
@@ -229,46 +234,65 @@ var WebsocketHandler = /** @class */ (function (_super) {
229
234
  });
230
235
  }
231
236
  else {
232
- this.connect(false);
237
+ this.connect(false, isForPreConnect, url);
233
238
  }
234
239
  return [2 /*return*/];
235
240
  });
236
241
  });
237
242
  };
238
- WebsocketHandler.prototype.connect = function (isForceFully) {
243
+ WebsocketHandler.prototype.connect = function (isForceFully, isForPreConnect, _url) {
239
244
  var _a, _b, _c;
240
245
  if (isForceFully === void 0) { isForceFully = false; }
241
246
  return __awaiter(this, void 0, void 0, function () {
242
- var url;
247
+ var url_1;
243
248
  var _this = this;
244
249
  return __generator(this, function (_d) {
245
250
  if (this.isEnded === true || this.isWebSocketConnectionInProgress) {
246
251
  return [2 /*return*/];
247
252
  }
248
- if (!this.wss || (isForceFully && this.isWebScoketConnected() === false)) {
249
- url = void 0;
250
- if (this.loadBalancerIpAddressForWebSocket) {
251
- url = "ws://" + this.loadBalancerIpAddressForWebSocket + ":4003/?connection=";
253
+ if (!this.wss || (isForceFully && this.isWebScoketConnectedWithoutSetup() === false)) {
254
+ url_1 = _url;
255
+ // if (this.loadBalancerIpAddressForWebSocket) {
256
+ // url = "ws://" + this.loadBalancerIpAddressForWebSocket + ":4003/?connection=";
257
+ // }
258
+ // else
259
+ if (!url_1 && ((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.wssUrl) && this.meetingStartRequest.wssUrl !== null) {
260
+ url_1 = this.meetingStartRequest.wssUrl;
252
261
  }
253
- else if (((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.wssUrl) && this.meetingStartRequest.wssUrl !== null) {
254
- url = this.meetingStartRequest.wssUrl;
262
+ if (!url_1 && this.websocketConnectionUrl) {
263
+ url_1 = this.websocketConnectionUrl;
255
264
  }
256
- if (url) {
257
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url);
265
+ if (!url_1) {
266
+ return [2 /*return*/];
267
+ }
268
+ if (url_1 !== this.websocketConnectionUrl) {
269
+ if (this.wss) {
270
+ this.wss.close();
271
+ }
272
+ }
273
+ if (!url_1.includes("connection=")) {
274
+ url_1 = url_1 + "/?connection=";
275
+ }
276
+ debugger;
277
+ if (url_1) {
278
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url_1);
258
279
  this.isWebSocketConnectionInProgress = true;
259
280
  if (this.meetingStartRequest && ((_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.isMobileApp)) {
260
- this.wss = new WebSocket(url + this.connection);
281
+ this.wss = new WebSocket(url_1 + this.connection);
261
282
  }
262
283
  else {
263
- this.wss = new WebSocket(url + this.connection);
284
+ this.wss = new WebSocket(url_1 + this.connection);
264
285
  }
265
286
  this.wss.onopen = function (event) {
266
287
  // this.checkIfSocketConnected();
267
288
  _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("connected ----");
268
289
  _this.isWebSocketConnectionInProgress = false;
269
290
  _this.isSetUpDone = false;
291
+ _this.websocketConnectionUrl = url_1;
270
292
  _this.socketCheckTimeout = undefined;
271
- _this.onSocketConnected();
293
+ if (!isForPreConnect) {
294
+ _this.onSocketConnected();
295
+ }
272
296
  };
273
297
  this.wss.onmessage = function (event) {
274
298
  _this.isWebSocketConnectionInProgress = false;
@@ -289,6 +313,8 @@ var WebsocketHandler = /** @class */ (function (_super) {
289
313
  }
290
314
  };
291
315
  this.wss.onclose = function (event) {
316
+ debugger;
317
+ _this.isSetUpDone = false;
292
318
  _this.isWebSocketConnectionInProgress = false;
293
319
  _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && ("WebSocket is closed now.");
294
320
  // log.warn(event)
@@ -296,14 +322,17 @@ var WebsocketHandler = /** @class */ (function (_super) {
296
322
  };
297
323
  }
298
324
  }
299
- else if (isForceFully === false && this.isWebScoketConnected()) {
325
+ else if (isForceFully === false && !isForPreConnect && this.isWebScoketConnected()) {
300
326
  (_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnSocketConnected, {});
301
327
  }
328
+ else if (!isForPreConnect && this.isWebScoketConnectedWithoutSetup() && !this.isSetUpDone) {
329
+ this.onSocketConnected();
330
+ }
302
331
  return [2 /*return*/];
303
332
  });
304
333
  });
305
334
  };
306
- WebsocketHandler.prototype.isWebScoketConnected = function () {
335
+ WebsocketHandler.prototype.isWebScoketConnectedWithoutSetup = function () {
307
336
  var _a;
308
337
  if (this.wss && this.wss.readyState === 1) {
309
338
  return true;
@@ -311,9 +340,17 @@ var WebsocketHandler = /** @class */ (function (_super) {
311
340
  this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss.readyState", this.wss, (_a = this.wss) === null || _a === void 0 ? void 0 : _a.readyState);
312
341
  return false;
313
342
  };
343
+ WebsocketHandler.prototype.isWebScoketConnected = function () {
344
+ var _a;
345
+ if (this.wss && this.wss.readyState === 1 && this.isSetUpDone) {
346
+ return true;
347
+ }
348
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss.readyState", this.wss, (_a = this.wss) === null || _a === void 0 ? void 0 : _a.readyState);
349
+ return false;
350
+ };
314
351
  WebsocketHandler.prototype.sendSocketMessage = function (type, data) {
315
352
  var _a;
316
- if (this.isWebScoketConnected()) {
353
+ if (this.isWebScoketConnectedWithoutSetup()) {
317
354
  var paylod = { type: type, data: data };
318
355
  (_a = this.wss) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(paylod));
319
356
  }
@@ -386,7 +423,7 @@ var WebsocketHandler = /** @class */ (function (_super) {
386
423
  };
387
424
  WebsocketHandler.prototype.socketSubscribeToTopic = function () {
388
425
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
389
- if (this.isWebScoketConnected() === false) {
426
+ if (this.isWebScoketConnectedWithoutSetup() === false) {
390
427
  return;
391
428
  }
392
429
  this.communicationHandler.updateSelfParticipantUserId();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client-native",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",