vani-meeting-client 2.1.8 → 2.2.0

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.
@@ -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;
@@ -80,6 +80,7 @@ export interface WebSocketMessageBody {
80
80
  data?: any;
81
81
  }
82
82
  export declare class WebsocketHandler extends Base {
83
+ private websocketConnectionUrl?;
83
84
  private loadBalancerIpAddressForWebSocket?;
84
85
  private isEnded;
85
86
  private isWebSocketConnectionInProgress;
@@ -93,8 +94,9 @@ export declare class WebsocketHandler extends Base {
93
94
  private lastPingTimeStamp;
94
95
  protected onObjectCreated(): void;
95
96
  cleanup(): Promise<void>;
96
- startSocketConnection(): Promise<void>;
97
+ startSocketConnection(isForPreConnect?: boolean, url?: string): Promise<void>;
97
98
  private connect;
99
+ isWebScoketConnectedWithoutSetup(): boolean;
98
100
  isWebScoketConnected(): boolean;
99
101
  sendSocketMessage(type: WebSocketEvents, data: any): void;
100
102
  reconnectOnInternetFailur(): void;
@@ -197,16 +197,16 @@ var WebsocketHandler = /** @class */ (function (_super) {
197
197
  });
198
198
  });
199
199
  };
200
- WebsocketHandler.prototype.startSocketConnection = function () {
200
+ WebsocketHandler.prototype.startSocketConnection = function (isForPreConnect, url) {
201
201
  return __awaiter(this, void 0, void 0, function () {
202
202
  var request, urlToGetIpAddress, config;
203
203
  var _this = this;
204
204
  return __generator(this, function (_a) {
205
- if (!this.meetingStartRequest) {
205
+ if (!this.meetingStartRequest && !isForPreConnect) {
206
206
  log.log("meetingStartRequest not found on startSocketConnection");
207
207
  return [2 /*return*/];
208
208
  }
209
- if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
209
+ if (!isForPreConnect && this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
210
210
  if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl.endsWith("/") === false) {
211
211
  this.meetingStartRequest.dynamicWebSocketFetchBaseUrl = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "/";
212
212
  }
@@ -234,46 +234,55 @@ var WebsocketHandler = /** @class */ (function (_super) {
234
234
  });
235
235
  }
236
236
  else {
237
- this.connect(false);
237
+ this.connect(false, isForPreConnect, url);
238
238
  }
239
239
  return [2 /*return*/];
240
240
  });
241
241
  });
242
242
  };
243
- WebsocketHandler.prototype.connect = function (isForceFully) {
243
+ WebsocketHandler.prototype.connect = function (isForceFully, isForPreConnect, _url) {
244
244
  var _a, _b, _c;
245
245
  if (isForceFully === void 0) { isForceFully = false; }
246
246
  return __awaiter(this, void 0, void 0, function () {
247
- var url;
247
+ var url_1;
248
248
  var _this = this;
249
249
  return __generator(this, function (_d) {
250
250
  if (this.isEnded === true || this.isWebSocketConnectionInProgress) {
251
251
  return [2 /*return*/];
252
252
  }
253
- if (!this.wss || (isForceFully && this.isWebScoketConnected() === false)) {
254
- url = void 0;
255
- if (this.loadBalancerIpAddressForWebSocket) {
256
- 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;
257
261
  }
258
- else if (((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.wssUrl) && this.meetingStartRequest.wssUrl !== null) {
259
- url = this.meetingStartRequest.wssUrl;
262
+ if (url_1 !== this.websocketConnectionUrl) {
263
+ if (this.wss) {
264
+ this.wss.close();
265
+ }
260
266
  }
261
- if (url) {
262
- this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url);
267
+ if (url_1) {
268
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url_1);
263
269
  this.isWebSocketConnectionInProgress = true;
264
270
  if (this.meetingStartRequest && ((_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.isMobileApp)) {
265
- this.wss = new WebSocket(url + this.connection);
271
+ this.wss = new WebSocket(url_1 + this.connection);
266
272
  }
267
273
  else {
268
- this.wss = new WebSocket(url + this.connection);
274
+ this.wss = new WebSocket(url_1 + this.connection);
269
275
  }
270
276
  this.wss.onopen = function (event) {
271
277
  // this.checkIfSocketConnected();
272
278
  _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("connected ----");
273
279
  _this.isWebSocketConnectionInProgress = false;
274
280
  _this.isSetUpDone = false;
281
+ _this.websocketConnectionUrl = url_1;
275
282
  _this.socketCheckTimeout = undefined;
276
- _this.onSocketConnected();
283
+ if (!isForPreConnect) {
284
+ _this.onSocketConnected();
285
+ }
277
286
  };
278
287
  this.wss.onmessage = function (event) {
279
288
  _this.isWebSocketConnectionInProgress = false;
@@ -301,14 +310,17 @@ var WebsocketHandler = /** @class */ (function (_super) {
301
310
  };
302
311
  }
303
312
  }
304
- else if (isForceFully === false && this.isWebScoketConnected()) {
313
+ else if (isForceFully === false && !isForPreConnect && this.isWebScoketConnected()) {
305
314
  (_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnSocketConnected, {});
306
315
  }
316
+ else if (isForPreConnect && this.isWebScoketConnectedWithoutSetup() && !this.isSetUpDone) {
317
+ this.onSocketConnected();
318
+ }
307
319
  return [2 /*return*/];
308
320
  });
309
321
  });
310
322
  };
311
- WebsocketHandler.prototype.isWebScoketConnected = function () {
323
+ WebsocketHandler.prototype.isWebScoketConnectedWithoutSetup = function () {
312
324
  var _a;
313
325
  if (this.wss && this.wss.readyState === 1) {
314
326
  return true;
@@ -316,6 +328,14 @@ var WebsocketHandler = /** @class */ (function (_super) {
316
328
  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);
317
329
  return false;
318
330
  };
331
+ WebsocketHandler.prototype.isWebScoketConnected = function () {
332
+ var _a;
333
+ if (this.wss && this.wss.readyState === 1 && this.isSetUpDone) {
334
+ return true;
335
+ }
336
+ 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);
337
+ return false;
338
+ };
319
339
  WebsocketHandler.prototype.sendSocketMessage = function (type, data) {
320
340
  var _a;
321
341
  if (this.isWebScoketConnected()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vani-meeting-client",
3
- "version": "2.1.8",
3
+ "version": "2.2.0",
4
4
  "description": "Vani Meeting Clinet SDK",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",