vani-meeting-client-native 0.0.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.
Files changed (42) hide show
  1. package/README.md +153 -0
  2. package/lib/MeetingHandler.d.ts +55 -0
  3. package/lib/MeetingHandler.js +496 -0
  4. package/lib/base/Base.d.ts +9 -0
  5. package/lib/base/Base.js +17 -0
  6. package/lib/index.d.ts +7 -0
  7. package/lib/index.js +7 -0
  8. package/lib/inter-communication-handler/CommunicationHandler.d.ts +65 -0
  9. package/lib/inter-communication-handler/CommunicationHandler.js +521 -0
  10. package/lib/model/Event.d.ts +84 -0
  11. package/lib/model/Event.js +35 -0
  12. package/lib/model/MeetingStartRequest.d.ts +54 -0
  13. package/lib/model/MeetingStartRequest.js +60 -0
  14. package/lib/model/MessagePayload.d.ts +32 -0
  15. package/lib/model/MessagePayload.js +31 -0
  16. package/lib/model/Participant.d.ts +16 -0
  17. package/lib/model/Participant.js +22 -0
  18. package/lib/model/TaskResponse.d.ts +5 -0
  19. package/lib/model/TaskResponse.js +1 -0
  20. package/lib/model/Track.d.ts +19 -0
  21. package/lib/model/Track.js +27 -0
  22. package/lib/user-media-handler/UserMediaHandler.d.ts +38 -0
  23. package/lib/user-media-handler/UserMediaHandler.js +786 -0
  24. package/lib/utility/DynamicLibHelper.d.ts +8 -0
  25. package/lib/utility/DynamicLibHelper.js +109 -0
  26. package/lib/utility/DynamicLibHelper.native.d.ts +8 -0
  27. package/lib/utility/DynamicLibHelper.native.js +109 -0
  28. package/lib/utility/DynamicLibHelper.node.d.ts +8 -0
  29. package/lib/utility/DynamicLibHelper.node.js +108 -0
  30. package/lib/utility/Utility.d.ts +3 -0
  31. package/lib/utility/Utility.js +12 -0
  32. package/lib/utility/VaniEventListener.d.ts +4 -0
  33. package/lib/utility/VaniEventListener.js +24 -0
  34. package/lib/video-call-handler/BaseVideoCallHandler.d.ts +25 -0
  35. package/lib/video-call-handler/BaseVideoCallHandler.js +98 -0
  36. package/lib/video-call-handler/SFUHandler.d.ts +57 -0
  37. package/lib/video-call-handler/SFUHandler.js +811 -0
  38. package/lib/video-call-handler/WebrtcHandler.d.ts +17 -0
  39. package/lib/video-call-handler/WebrtcHandler.js +107 -0
  40. package/lib/websocket-handler/WebsocketHandler.d.ts +102 -0
  41. package/lib/websocket-handler/WebsocketHandler.js +541 -0
  42. package/package.json +53 -0
@@ -0,0 +1,541 @@
1
+ var __extends = (this && this.__extends) || (function () {
2
+ var extendStatics = function (d, b) {
3
+ extendStatics = Object.setPrototypeOf ||
4
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
6
+ return extendStatics(d, b);
7
+ };
8
+ return function (d, b) {
9
+ if (typeof b !== "function" && b !== null)
10
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
11
+ extendStatics(d, b);
12
+ function __() { this.constructor = d; }
13
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
+ };
15
+ })();
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __generator = (this && this.__generator) || function (thisArg, body) {
26
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
27
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
28
+ function verb(n) { return function (v) { return step([n, v]); }; }
29
+ function step(op) {
30
+ if (f) throw new TypeError("Generator is already executing.");
31
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
32
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
33
+ if (y = 0, t) op = [op[0] & 2, t.value];
34
+ switch (op[0]) {
35
+ case 0: case 1: t = op; break;
36
+ case 4: _.label++; return { value: op[1], done: false };
37
+ case 5: _.label++; y = op[1]; op = [0]; continue;
38
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
39
+ default:
40
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
41
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
42
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
43
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
44
+ if (t[2]) _.ops.pop();
45
+ _.trys.pop(); continue;
46
+ }
47
+ op = body.call(thisArg, _);
48
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
49
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
50
+ }
51
+ };
52
+ import axios from 'axios';
53
+ import { LogLevel, MeetingType, VaniEvent } from '..';
54
+ import * as log from 'loglevel';
55
+ import { Base } from '../base/Base';
56
+ export var WebSocketBasicEvents;
57
+ (function (WebSocketBasicEvents) {
58
+ WebSocketBasicEvents["Config"] = "config";
59
+ WebSocketBasicEvents["JoinRoom"] = "joinRoom";
60
+ WebSocketBasicEvents["IsSetupDone"] = "setupDone";
61
+ WebSocketBasicEvents["Ping"] = "ping";
62
+ WebSocketBasicEvents["Pong"] = "pong";
63
+ WebSocketBasicEvents["CloseRoomForceFully"] = "CloseRoomForceFully";
64
+ WebSocketBasicEvents["AudioVideoPauseResume"] = "audioVideoPauseResume";
65
+ WebSocketBasicEvents["OnStartMeetingCalled"] = "startMeetingCalled";
66
+ WebSocketBasicEvents["OnAudioVideoPauseResume"] = "audioVideoPauseResume";
67
+ WebSocketBasicEvents["OnAudioVideoStatusUpdated"] = "audioVideoStatusUpdated";
68
+ WebSocketBasicEvents["OnAudioUnblockRequest"] = "audioUnblock";
69
+ WebSocketBasicEvents["OnVideoUnblockRequest"] = "videoUnblock";
70
+ WebSocketBasicEvents["OnAudioBlockRequest"] = "audioBlock";
71
+ WebSocketBasicEvents["OnVideoBlockRequest"] = "videoBlock";
72
+ WebSocketBasicEvents["UpdateParticipant"] = "updateParticipant";
73
+ WebSocketBasicEvents["OnParticipantUpdated"] = "participantUpdated";
74
+ WebSocketBasicEvents["OnNewJoinee"] = "newJoinee";
75
+ WebSocketBasicEvents["OnUserOnFoundWhileReconnect"] = "onUserOnFoundWhileReconnect";
76
+ WebSocketBasicEvents["OnRejoined"] = "OnRejoined";
77
+ WebSocketBasicEvents["OnUserLeft"] = "userLeft";
78
+ WebSocketBasicEvents["GetAllParticipant"] = "getParticipant";
79
+ WebSocketBasicEvents["OnServerParticipants"] = "participants";
80
+ WebSocketBasicEvents["GetMeetingStartTime"] = "getMeetingStartTime";
81
+ WebSocketBasicEvents["OnMeetingStartTime"] = "meetingStartTime";
82
+ WebSocketBasicEvents["GetOldMessages"] = "getOldMessages";
83
+ WebSocketBasicEvents["OnOldMessages"] = "oldMessages";
84
+ WebSocketBasicEvents["Message"] = "message";
85
+ WebSocketBasicEvents["OnChat"] = "chat";
86
+ WebSocketBasicEvents["SelfLeft"] = "selfLeft";
87
+ })(WebSocketBasicEvents || (WebSocketBasicEvents = {}));
88
+ export var SFUMessageType;
89
+ (function (SFUMessageType) {
90
+ SFUMessageType["SFUMessage"] = "sfuMessage";
91
+ SFUMessageType["GetRouterRtpCapabilities"] = "routerRtpCapabilities";
92
+ SFUMessageType["OnRouterRtpCapabilities"] = "onRouterRtpCapabilities";
93
+ SFUMessageType["OnTransportConnect"] = "transportConnect";
94
+ SFUMessageType["OnCreateTransports"] = "createTransports";
95
+ SFUMessageType["OnTransportConnectDone"] = "transportConnectDone";
96
+ SFUMessageType["OnSendTransport"] = "onSendTransport";
97
+ SFUMessageType["OnConsumeTransport"] = "onConsumeTransport";
98
+ SFUMessageType["OnTransportProduceSyncRequest"] = "transportProduceSync";
99
+ SFUMessageType["OnTransportDataProduceSyncRequest"] = "dataTransportProduceSync";
100
+ SFUMessageType["OnReadyToConsume"] = "readyToConsume";
101
+ SFUMessageType["OnStartRTMP"] = "startRtmp";
102
+ SFUMessageType["OnProducerClosed"] = "producerClosed";
103
+ SFUMessageType["OnPauseProducer"] = "pauseProducer";
104
+ SFUMessageType["OnResumeProducer"] = "resumeProducer";
105
+ SFUMessageType["OnNewProducer"] = "onNewProducer";
106
+ SFUMessageType["ConsumeProductId"] = "consumeProductId";
107
+ SFUMessageType["OnServerConsumer"] = "onServerConsumer";
108
+ SFUMessageType["ResumeConsumer"] = "resumeConsumer";
109
+ SFUMessageType["PauseConsumer"] = "pauseConsumer";
110
+ SFUMessageType["OnProduceSyncDone"] = "produceSyncDone";
111
+ SFUMessageType["OnSpeakerChanged"] = "onSpeakerChanged";
112
+ SFUMessageType["OnRestartIceCandidate"] = "restartIceCandidate";
113
+ SFUMessageType["OnTrackEnded"] = "onTrackEnded";
114
+ SFUMessageType["UpdateSpatialConsumer"] = "updateSpatialConsumer";
115
+ SFUMessageType["OnRestartIceCandidateResponse"] = "onRestartIceCandidate";
116
+ SFUMessageType["OnTransportNotFound"] = "onTransportNotFound";
117
+ SFUMessageType["OnCreateTransportsForcefully"] = "OnCreateTransportsForcefully";
118
+ SFUMessageType["GetAllProducers"] = "getAllProducers";
119
+ SFUMessageType["OnAllProducers"] = "onAllProducers";
120
+ SFUMessageType["OnAudioVolumeChanged"] = "OnAudioVolumeChanged";
121
+ SFUMessageType["OnConsumerNotFound"] = "OnConsumerNotFound";
122
+ SFUMessageType["OnProducerNotFound"] = "OnProducerNotFound";
123
+ })(SFUMessageType || (SFUMessageType = {}));
124
+ var ConnectionType;
125
+ (function (ConnectionType) {
126
+ ConnectionType["new"] = "new";
127
+ ConnectionType["reconnect"] = "reconnect";
128
+ })(ConnectionType || (ConnectionType = {}));
129
+ var WebsocketHandler = /** @class */ (function (_super) {
130
+ __extends(WebsocketHandler, _super);
131
+ function WebsocketHandler() {
132
+ var _this = _super !== null && _super.apply(this, arguments) || this;
133
+ _this.isEnded = false;
134
+ _this.isWebSocketConnectionInProgress = false;
135
+ _this.connection = ConnectionType.new;
136
+ _this.isSetUpDone = false;
137
+ _this.setUpTry = 0;
138
+ _this.pongData = undefined;
139
+ _this.lastPingTimeStamp = 0;
140
+ _this.onCloseTheRoomForcefully = function (data) { return __awaiter(_this, void 0, void 0, function () {
141
+ var _a, _b;
142
+ return __generator(this, function (_c) {
143
+ switch (_c.label) {
144
+ case 0: return [4 /*yield*/, ((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnAskedToCloseTheRoom, {}))];
145
+ case 1:
146
+ _c.sent();
147
+ (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.destoryRoomForcefully();
148
+ return [2 /*return*/];
149
+ }
150
+ });
151
+ }); };
152
+ return _this;
153
+ }
154
+ WebsocketHandler.prototype.onObjectCreated = function () {
155
+ var _a;
156
+ _super.prototype.onObjectCreated.call(this);
157
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.setWebsocketCallHandler(this);
158
+ };
159
+ WebsocketHandler.prototype.cleanup = function () {
160
+ var _a;
161
+ try {
162
+ var data = { userId: (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.userId };
163
+ this.sendSocketMessage(WebSocketBasicEvents.SelfLeft, data);
164
+ }
165
+ catch (err) {
166
+ }
167
+ this.loadBalancerIpAddressForWebSocket = undefined;
168
+ this.isEnded = true;
169
+ if (this.wss) {
170
+ this.wss.close();
171
+ this.wss = undefined;
172
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss undefined cleanup ");
173
+ }
174
+ if (this.socketCheckTimeout) {
175
+ window.clearTimeout(this.socketCheckTimeout);
176
+ this.socketCheckTimeout = undefined;
177
+ }
178
+ if (this.pingCheckTimeout) {
179
+ window.clearTimeout(this.pingCheckTimeout);
180
+ this.pingCheckTimeout = undefined;
181
+ }
182
+ _super.prototype.cleanup.call(this);
183
+ };
184
+ WebsocketHandler.prototype.startSocketConnection = function () {
185
+ return __awaiter(this, void 0, void 0, function () {
186
+ var request, urlToGetIpAddress, config;
187
+ var _this = this;
188
+ return __generator(this, function (_a) {
189
+ if (!this.meetingStartRequest) {
190
+ log.warn("meetingStartRequest not found on startSocketConnection");
191
+ return [2 /*return*/];
192
+ }
193
+ if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
194
+ if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl.endsWith("/") === false) {
195
+ this.meetingStartRequest.dynamicWebSocketFetchBaseUrl = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "/";
196
+ }
197
+ request = { meeting_id: this.meetingStartRequest.roomId, estimated_users: this.meetingStartRequest.numberOfUsers };
198
+ urlToGetIpAddress = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "api/getIpAddressForMeeting";
199
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(JSON.stringify(request));
200
+ config = {
201
+ headers: {
202
+ 'Content-Type': 'application/json'
203
+ }
204
+ };
205
+ axios
206
+ .post(urlToGetIpAddress, request, config)
207
+ .then(function (response) {
208
+ _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("response ", response.data);
209
+ if (response && response.data && response.data.status === true && response.data.ipAddress && response.data.ipAddress !== null) {
210
+ _this.loadBalancerIpAddressForWebSocket = response.data.ipAddress;
211
+ }
212
+ _this.connect(false);
213
+ })
214
+ .catch(function (error) {
215
+ _this.connect(false);
216
+ log.warn(error);
217
+ _this.connect(false);
218
+ });
219
+ }
220
+ else {
221
+ this.connect(false);
222
+ }
223
+ return [2 /*return*/];
224
+ });
225
+ });
226
+ };
227
+ WebsocketHandler.prototype.connect = function (isForceFully) {
228
+ var _a, _b, _c;
229
+ if (isForceFully === void 0) { isForceFully = false; }
230
+ return __awaiter(this, void 0, void 0, function () {
231
+ var url;
232
+ var _this = this;
233
+ return __generator(this, function (_d) {
234
+ if (this.isEnded === true || this.isWebSocketConnectionInProgress) {
235
+ return [2 /*return*/];
236
+ }
237
+ if (!this.wss || (isForceFully && this.isWebScoketConnected() === false)) {
238
+ url = void 0;
239
+ if (this.loadBalancerIpAddressForWebSocket) {
240
+ url = "ws://" + this.loadBalancerIpAddressForWebSocket + ":4003/?connection=";
241
+ }
242
+ else if (((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.wssUrl) && this.meetingStartRequest.wssUrl !== null) {
243
+ url = this.meetingStartRequest.wssUrl;
244
+ }
245
+ if (url) {
246
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url);
247
+ this.isWebSocketConnectionInProgress = true;
248
+ if ((_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.isMobileApp) {
249
+ this.wss = new WebSocket(url + this.connection);
250
+ }
251
+ else {
252
+ this.wss = new WebSocket(url + this.connection);
253
+ }
254
+ this.wss.onopen = function (event) {
255
+ // this.checkIfSocketConnected();
256
+ _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("connected ----");
257
+ _this.isWebSocketConnectionInProgress = false;
258
+ _this.isSetUpDone = false;
259
+ _this.socketCheckTimeout = undefined;
260
+ _this.onSocketConnected();
261
+ };
262
+ this.wss.onmessage = function (event) {
263
+ _this.isWebSocketConnectionInProgress = false;
264
+ _this.onMessage(event.data);
265
+ };
266
+ this.wss.onerror = function (event) {
267
+ var _a;
268
+ _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("wss error", event);
269
+ _this.isWebSocketConnectionInProgress = false;
270
+ (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketError, event);
271
+ if (_this.wss) {
272
+ _this.wss.close();
273
+ }
274
+ };
275
+ this.wss.onclose = function (event) {
276
+ _this.isWebSocketConnectionInProgress = false;
277
+ _this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && ("WebSocket is closed now.");
278
+ log.warn(event);
279
+ _this.onWebSocketClosed(event);
280
+ };
281
+ }
282
+ }
283
+ else if (isForceFully === false && this.isWebScoketConnected()) {
284
+ (_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnSocketConnected, {});
285
+ }
286
+ return [2 /*return*/];
287
+ });
288
+ });
289
+ };
290
+ WebsocketHandler.prototype.isWebScoketConnected = function () {
291
+ var _a;
292
+ if (this.wss && this.wss.readyState === 1) {
293
+ return true;
294
+ }
295
+ 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);
296
+ return false;
297
+ };
298
+ WebsocketHandler.prototype.sendSocketMessage = function (type, data) {
299
+ var _a;
300
+ if (this.isWebScoketConnected()) {
301
+ var paylod = { type: type, data: data };
302
+ (_a = this.wss) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(paylod));
303
+ }
304
+ };
305
+ WebsocketHandler.prototype.reconnectOnInternetFailur = function () {
306
+ var _a;
307
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("reconnectOnInternetFailur");
308
+ if (this.wss) {
309
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnReconecting, {});
310
+ this.wss.close(3005);
311
+ this.wss = undefined;
312
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss undefined reconnectOnInternetFailur ");
313
+ }
314
+ this.connection = ConnectionType.reconnect;
315
+ this.connect(true);
316
+ };
317
+ // private checkIfSocketConnected() {
318
+ // window.setTimeout(() => {
319
+ // if (this.isWebScoketConnected()) {
320
+ // log.info("Connected")
321
+ // this.checkIfSocketConnected();
322
+ // }
323
+ // else {
324
+ // log.info("Not Connected")
325
+ // }
326
+ // }, 1000);
327
+ // }
328
+ WebsocketHandler.prototype.onWebSocketClosed = function (event) {
329
+ var _this = this;
330
+ var _a;
331
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("onWebSocketClosed", event.code);
332
+ if (event.code === 3005 || event.wasClean === false || (event.message && event.message.toLowerCase().includes("software") && event.message.toLowerCase().includes("abort")) || (event.message && event.message.toLowerCase().includes("no address"))) {
333
+ this.socketCheckTimeout = window.setTimeout(function () {
334
+ var _a;
335
+ _this.tryToReconectSocket();
336
+ (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnReconecting, {});
337
+ }, 1000);
338
+ }
339
+ else {
340
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketDisconnected, {});
341
+ }
342
+ };
343
+ WebsocketHandler.prototype.tryToReconectSocket = function () {
344
+ var _a, _b;
345
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("tryToReconectSocket");
346
+ if (this.isWebScoketConnected() === false && this.isEnded === false) {
347
+ this.wss = undefined;
348
+ this.connection = ConnectionType.reconnect;
349
+ this.connect(true);
350
+ }
351
+ else {
352
+ this.socketCheckTimeout = undefined;
353
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketReconnectTimeOut, {});
354
+ (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.emitMessageToSource(VaniEvent.OnSocketDisconnected, {});
355
+ }
356
+ };
357
+ WebsocketHandler.prototype.onSocketConnected = function () {
358
+ this.socketSubscribeToTopic();
359
+ };
360
+ WebsocketHandler.prototype.socketSubscribeToTopic = function () {
361
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
362
+ if (this.isWebScoketConnected() === false) {
363
+ return;
364
+ }
365
+ var participant = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
366
+ participant.userData = (_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.userData;
367
+ var config = {
368
+ connectionProtocol: (_c = this.meetingStartRequest) === null || _c === void 0 ? void 0 : _c.connectionProtocol,
369
+ participant: (_d = this.communicationHandler) === null || _d === void 0 ? void 0 : _d.getSelfParticipant(), apiData: (_e = this.meetingStartRequest) === null || _e === void 0 ? void 0 : _e.apiData,
370
+ appId: (_f = this.meetingStartRequest) === null || _f === void 0 ? void 0 : _f.appId, sfuRequired: (((_g = this.meetingStartRequest) === null || _g === void 0 ? void 0 : _g.meetingType) === MeetingType.SFU), numberOfUsers: (_h = this.meetingStartRequest) === null || _h === void 0 ? void 0 : _h.numberOfUsers, meetId: (_j = this.meetingStartRequest) === null || _j === void 0 ? void 0 : _j.roomId
371
+ };
372
+ this.sendSocketMessage(WebSocketBasicEvents.Config, config);
373
+ var hostNotificationRoom = { roomId: (_k = this.meetingStartRequest) === null || _k === void 0 ? void 0 : _k.userId, id: (_l = this.meetingStartRequest) === null || _l === void 0 ? void 0 : _l.userId };
374
+ this.sendSocketMessage(WebSocketBasicEvents.JoinRoom, hostNotificationRoom);
375
+ var roomForAllClient = { roomId: (_m = this.meetingStartRequest) === null || _m === void 0 ? void 0 : _m.roomId, id: (_o = this.meetingStartRequest) === null || _o === void 0 ? void 0 : _o.userId };
376
+ this.sendSocketMessage(WebSocketBasicEvents.JoinRoom, roomForAllClient);
377
+ this.setUpTry = 0;
378
+ this.askIfSetupDone();
379
+ };
380
+ WebsocketHandler.prototype.askIfSetupDone = function () {
381
+ var _this = this;
382
+ if (this.isSetUpDone || this.setUpTry > 10) {
383
+ return;
384
+ }
385
+ if (!this.meetingStartRequest) {
386
+ return;
387
+ }
388
+ var checkIfSetupDone = { to: this.meetingStartRequest.userId };
389
+ this.sendSocketMessage(WebSocketBasicEvents.IsSetupDone, checkIfSetupDone);
390
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Vani setupDone asked");
391
+ window.setTimeout(function () {
392
+ if (_this.isSetUpDone) {
393
+ return;
394
+ }
395
+ else if (_this.setUpTry > 15) {
396
+ setTimeout(function () {
397
+ var _a;
398
+ if (!_this.isSetUpDone) {
399
+ (_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketError, {});
400
+ }
401
+ }, 10000);
402
+ return;
403
+ }
404
+ _this.askIfSetupDone();
405
+ _this.setUpTry = _this.setUpTry + 1;
406
+ }, 300);
407
+ };
408
+ WebsocketHandler.prototype.onMessage = function (message) {
409
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
410
+ this.lastPingTimeStamp = new Date().getTime();
411
+ // this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("lastPingTimeStamp time ", this.lastPingTimeStamp)
412
+ var messagejson = JSON.parse(message);
413
+ if (messagejson.type && messagejson.data) {
414
+ var type = messagejson.type;
415
+ var data = messagejson.data;
416
+ if (type === WebSocketBasicEvents.Ping) {
417
+ this.pongData = data;
418
+ this.sendSocketMessage(WebSocketBasicEvents.Pong, data);
419
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnNewPingFromServer, {});
420
+ }
421
+ else if (this.isVideoCallControllerMessageType(type)) {
422
+ (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.onVideoCallWebSocketMessage(messagejson);
423
+ return;
424
+ }
425
+ else if (type === WebSocketBasicEvents.IsSetupDone) {
426
+ this.onSetupDone(data);
427
+ }
428
+ else if (type === WebSocketBasicEvents.CloseRoomForceFully) {
429
+ this.onCloseTheRoomForcefully(data);
430
+ }
431
+ else if (type === WebSocketBasicEvents.OnUserOnFoundWhileReconnect) {
432
+ (_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnUserOnFoundWhileReconnect, {});
433
+ }
434
+ else if (type === WebSocketBasicEvents.OnNewJoinee || type === WebSocketBasicEvents.OnRejoined) {
435
+ if (data && data.message && data.message.participant) {
436
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("OnParticipantUpdated from server", data.message.participant);
437
+ (_d = this.communicationHandler) === null || _d === void 0 ? void 0 : _d.addParticipantIfNotExist(data.message.participant, true);
438
+ }
439
+ }
440
+ else if (type === WebSocketBasicEvents.OnParticipantUpdated) {
441
+ if (data) {
442
+ (_e = this.communicationHandler) === null || _e === void 0 ? void 0 : _e.addParticipantIfNotExist(data.message, true);
443
+ }
444
+ }
445
+ else if (type === WebSocketBasicEvents.OnUserLeft) {
446
+ (_f = this.communicationHandler) === null || _f === void 0 ? void 0 : _f.onUserLeft(data);
447
+ }
448
+ else if (type === WebSocketBasicEvents.OnServerParticipants) {
449
+ (_g = this.communicationHandler) === null || _g === void 0 ? void 0 : _g.onServerParticipants(data);
450
+ }
451
+ else if (type === WebSocketBasicEvents.OnOldMessages) {
452
+ (_h = this.communicationHandler) === null || _h === void 0 ? void 0 : _h.onOldMessages(data);
453
+ }
454
+ else if (type === WebSocketBasicEvents.OnChat) {
455
+ if (data.message) {
456
+ (_j = this.communicationHandler) === null || _j === void 0 ? void 0 : _j.onMessage(data.message);
457
+ }
458
+ }
459
+ else if (type === WebSocketBasicEvents.OnMeetingStartTime) {
460
+ if (data && (data.time || data.message)) {
461
+ var time = data.time ? data.time : data.message;
462
+ if (time > new Date().getTime()) {
463
+ time = new Date().getTime();
464
+ }
465
+ (_k = this.communicationHandler) === null || _k === void 0 ? void 0 : _k.emitMessageToSource(VaniEvent.OnMeetingStartTime, (time + ""));
466
+ }
467
+ }
468
+ else if (type === WebSocketBasicEvents.OnAudioVideoStatusUpdated) {
469
+ (_l = this.communicationHandler) === null || _l === void 0 ? void 0 : _l.onAudioVideoStatusUpdated(data);
470
+ }
471
+ else if (type === WebSocketBasicEvents.OnAudioBlockRequest) {
472
+ (_m = this.communicationHandler) === null || _m === void 0 ? void 0 : _m.onAudioBlocked(data);
473
+ }
474
+ else if (type === WebSocketBasicEvents.OnAudioUnblockRequest) {
475
+ (_o = this.communicationHandler) === null || _o === void 0 ? void 0 : _o.onAudioUnblocked(data);
476
+ }
477
+ else if (type === WebSocketBasicEvents.OnVideoBlockRequest) {
478
+ (_p = this.communicationHandler) === null || _p === void 0 ? void 0 : _p.onVideoBlocked(data);
479
+ }
480
+ else if (type === WebSocketBasicEvents.OnVideoUnblockRequest) {
481
+ (_q = this.communicationHandler) === null || _q === void 0 ? void 0 : _q.onVideoUnblocked(data);
482
+ }
483
+ }
484
+ };
485
+ WebsocketHandler.prototype.onSetupDone = function (data) {
486
+ var _a, _b, _c;
487
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onSetupDone", this.meetingStartRequest);
488
+ if (!this.meetingStartRequest) {
489
+ return;
490
+ }
491
+ if (this.isSetUpDone === false) {
492
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(data);
493
+ this.isSetUpDone = true;
494
+ if ((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isStartAndSetupWithServerCalled) {
495
+ var isReconnect = data.message.isReconnection;
496
+ if (isReconnect) {
497
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("'onReconnect Meeting");
498
+ (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.onReconnect();
499
+ }
500
+ return;
501
+ }
502
+ else {
503
+ (_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnConnected, {});
504
+ }
505
+ }
506
+ if (this.pingCheckTimeout) {
507
+ window.clearTimeout(this.pingCheckTimeout);
508
+ this.pingCheckTimeout = undefined;
509
+ }
510
+ this.checkIfPingIsRunning();
511
+ };
512
+ WebsocketHandler.prototype.checkIfPingIsRunning = function () {
513
+ var _this = this;
514
+ var _a, _b;
515
+ if (this.isWebScoketConnected()) {
516
+ if (this.pongData) {
517
+ this.sendSocketMessage(WebSocketBasicEvents.Pong, this.pongData);
518
+ }
519
+ if ((this.lastPingTimeStamp + (80 * 1000)) < new Date().getTime()) {
520
+ this.pingCheckTimeout = undefined;
521
+ this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("checkIfPingIsRunning", this.lastPingTimeStamp);
522
+ //Discounted
523
+ (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.onIceCandidateDisconnected();
524
+ (_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.emitMessageToSource(VaniEvent.OnNotReachable, {});
525
+ }
526
+ else {
527
+ this.pingCheckTimeout = window.setTimeout(function () {
528
+ _this.checkIfPingIsRunning();
529
+ }, 5 * 1000);
530
+ }
531
+ }
532
+ };
533
+ WebsocketHandler.prototype.isVideoCallControllerMessageType = function (type) {
534
+ if (Object.values(SFUMessageType).includes(type)) {
535
+ return true;
536
+ }
537
+ return false;
538
+ };
539
+ return WebsocketHandler;
540
+ }(Base));
541
+ export { WebsocketHandler };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "vani-meeting-client-native",
3
+ "version": "0.0.2",
4
+ "description": "Vani Meeting Clinet SDK",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": [
8
+ "lib/**/*"
9
+ ],
10
+ "scripts": {
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "build": "cp ./src/utility/DynamicLibHelper.native.ts ./src/utility/DynamicLibHelper.ts && tsc",
13
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
14
+ "lint": "tslint -p tsconfig.json",
15
+ "prepare": "npm run build",
16
+ "version": "npm run format && git add -A src",
17
+ "postversion": "git push && git push --tags"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/sachin-codeplaylabs/VaniMeetingClientSDK.git"
22
+ },
23
+ "keywords": [
24
+ "VaniMeeting",
25
+ "Codeplay",
26
+ "Webrtc",
27
+ "SFU",
28
+ "Mediasoup",
29
+ "Chat"
30
+ ],
31
+ "author": "Vani Meeting",
32
+ "license": "ISC",
33
+ "bugs": {
34
+ "url": "https://github.com/sachin-codeplaylabs/VaniMeetingClientSDK/issues"
35
+ },
36
+ "homepage": "https://vanimeetings.com/",
37
+ "devDependencies": {
38
+ "@types/node": "^16.11.11",
39
+ "prettier": "^2.5.0",
40
+ "tslint": "^6.1.3",
41
+ "tslint-config-prettier": "^1.18.0",
42
+ "typescript": "^4.5.2"
43
+ },
44
+ "dependencies": {
45
+ "@analytics/google-analytics": "^0.5.3",
46
+ "analytics": "^0.7.21",
47
+ "axios": "^0.24.0",
48
+ "loglevel": "^1.8.0",
49
+ "mediasoup-client": "^3.7.16",
50
+ "react-native-google-analytics-bridge": "^7.1.0"
51
+ },
52
+ "optionalDependencies": {}
53
+ }