vani-meeting-client
Version:
Vani Meeting Clinet SDK
545 lines (544 loc) • 31 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
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;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import axios from 'axios';
import { LogLevel, MeetingType, VaniEvent } from '..';
import * as log from 'loglevel';
import { Base } from '../base/Base';
export var WebSocketBasicEvents;
(function (WebSocketBasicEvents) {
WebSocketBasicEvents["Config"] = "config";
WebSocketBasicEvents["JoinRoom"] = "joinRoom";
WebSocketBasicEvents["IsSetupDone"] = "setupDone";
WebSocketBasicEvents["Ping"] = "ping";
WebSocketBasicEvents["Pong"] = "pong";
WebSocketBasicEvents["CloseRoomForceFully"] = "CloseRoomForceFully";
WebSocketBasicEvents["AudioVideoPauseResume"] = "audioVideoPauseResume";
WebSocketBasicEvents["OnStartMeetingCalled"] = "startMeetingCalled";
WebSocketBasicEvents["OnAudioVideoPauseResume"] = "audioVideoPauseResume";
WebSocketBasicEvents["OnAudioVideoStatusUpdated"] = "audioVideoStatusUpdated";
WebSocketBasicEvents["OnAudioUnblockRequest"] = "audioUnblock";
WebSocketBasicEvents["OnVideoUnblockRequest"] = "videoUnblock";
WebSocketBasicEvents["OnAudioBlockRequest"] = "audioBlock";
WebSocketBasicEvents["OnVideoBlockRequest"] = "videoBlock";
WebSocketBasicEvents["UpdateParticipant"] = "updateParticipant";
WebSocketBasicEvents["OnParticipantUpdated"] = "participantUpdated";
WebSocketBasicEvents["OnNewJoinee"] = "newJoinee";
WebSocketBasicEvents["OnUserOnFoundWhileReconnect"] = "onUserOnFoundWhileReconnect";
WebSocketBasicEvents["OnRejoined"] = "OnRejoined";
WebSocketBasicEvents["OnUserLeft"] = "userLeft";
WebSocketBasicEvents["GetAllParticipant"] = "getParticipant";
WebSocketBasicEvents["OnServerParticipants"] = "participants";
WebSocketBasicEvents["GetMeetingStartTime"] = "getMeetingStartTime";
WebSocketBasicEvents["OnMeetingStartTime"] = "meetingStartTime";
WebSocketBasicEvents["GetOldMessages"] = "getOldMessages";
WebSocketBasicEvents["OnOldMessages"] = "oldMessages";
WebSocketBasicEvents["Message"] = "message";
WebSocketBasicEvents["OnChat"] = "chat";
WebSocketBasicEvents["SelfLeft"] = "selfLeft";
})(WebSocketBasicEvents || (WebSocketBasicEvents = {}));
export var SFUMessageType;
(function (SFUMessageType) {
SFUMessageType["SFUMessage"] = "sfuMessage";
SFUMessageType["GetRouterRtpCapabilities"] = "routerRtpCapabilities";
SFUMessageType["ReloadSFUCleanUpDone"] = "ReloadSFUCleanUpDone";
SFUMessageType["ReloadSFU"] = "reloadSFU";
SFUMessageType["OnRouterRtpCapabilities"] = "onRouterRtpCapabilities";
SFUMessageType["OnTransportConnect"] = "transportConnect";
SFUMessageType["OnCreateTransports"] = "createTransports";
SFUMessageType["OnTransportConnectDone"] = "transportConnectDone";
SFUMessageType["OnSendTransport"] = "onSendTransport";
SFUMessageType["OnConsumeTransport"] = "onConsumeTransport";
SFUMessageType["OnTransportProduceSyncRequest"] = "transportProduceSync";
SFUMessageType["OnTransportDataProduceSyncRequest"] = "dataTransportProduceSync";
SFUMessageType["OnReadyToConsume"] = "readyToConsume";
SFUMessageType["OnStartRTMP"] = "startRtmp";
SFUMessageType["OnProducerClosed"] = "producerClosed";
SFUMessageType["OnPauseProducer"] = "pauseProducer";
SFUMessageType["OnResumeProducer"] = "resumeProducer";
SFUMessageType["OnNewProducer"] = "onNewProducer";
SFUMessageType["ConsumeProductId"] = "consumeProductId";
SFUMessageType["OnServerConsumer"] = "onServerConsumer";
SFUMessageType["ResumeConsumer"] = "resumeConsumer";
SFUMessageType["PauseConsumer"] = "pauseConsumer";
SFUMessageType["OnProduceSyncDone"] = "produceSyncDone";
SFUMessageType["OnSpeakerChanged"] = "onSpeakerChanged";
SFUMessageType["OnRestartIceCandidate"] = "restartIceCandidate";
SFUMessageType["OnTrackEnded"] = "onTrackEnded";
SFUMessageType["UpdateSpatialConsumer"] = "updateSpatialConsumer";
SFUMessageType["OnRestartIceCandidateResponse"] = "onRestartIceCandidate";
SFUMessageType["OnTransportNotFound"] = "onTransportNotFound";
SFUMessageType["OnCreateTransportsForcefully"] = "OnCreateTransportsForcefully";
SFUMessageType["GetAllProducers"] = "getAllProducers";
SFUMessageType["OnAllProducers"] = "onAllProducers";
SFUMessageType["OnAudioVolumeChanged"] = "OnAudioVolumeChanged";
SFUMessageType["OnConsumerNotFound"] = "OnConsumerNotFound";
SFUMessageType["OnProducerNotFound"] = "OnProducerNotFound";
})(SFUMessageType || (SFUMessageType = {}));
var ConnectionType;
(function (ConnectionType) {
ConnectionType["new"] = "new";
ConnectionType["reconnect"] = "reconnect";
})(ConnectionType || (ConnectionType = {}));
var WebsocketHandler = /** @class */ (function (_super) {
__extends(WebsocketHandler, _super);
function WebsocketHandler() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.isEnded = false;
_this.isWebSocketConnectionInProgress = false;
_this.connection = ConnectionType.new;
_this.isSetUpDone = false;
_this.setUpTry = 0;
_this.pongData = undefined;
_this.lastPingTimeStamp = 0;
_this.onCloseTheRoomForcefully = function (data) { return __awaiter(_this, void 0, void 0, function () {
var _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, ((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnAskedToCloseTheRoom, {}))];
case 1:
_c.sent();
(_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.destoryRoomForcefully();
return [2 /*return*/];
}
});
}); };
return _this;
}
WebsocketHandler.prototype.onObjectCreated = function () {
var _a;
_super.prototype.onObjectCreated.call(this);
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.setWebsocketCallHandler(this);
};
WebsocketHandler.prototype.cleanup = function () {
var _a;
try {
var data = { userId: (_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.userId };
this.sendSocketMessage(WebSocketBasicEvents.SelfLeft, data);
}
catch (err) {
}
this.loadBalancerIpAddressForWebSocket = undefined;
this.isEnded = true;
if (this.wss) {
this.wss.close();
this.wss = undefined;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss undefined cleanup ");
}
if (this.socketCheckTimeout) {
window.clearTimeout(this.socketCheckTimeout);
this.socketCheckTimeout = undefined;
}
if (this.pingCheckTimeout) {
window.clearTimeout(this.pingCheckTimeout);
this.pingCheckTimeout = undefined;
}
_super.prototype.cleanup.call(this);
};
WebsocketHandler.prototype.startSocketConnection = function () {
return __awaiter(this, void 0, void 0, function () {
var request, urlToGetIpAddress, config;
var _this = this;
return __generator(this, function (_a) {
if (!this.meetingStartRequest) {
log.warn("meetingStartRequest not found on startSocketConnection");
return [2 /*return*/];
}
if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl) {
if (this.meetingStartRequest.dynamicWebSocketFetchBaseUrl.endsWith("/") === false) {
this.meetingStartRequest.dynamicWebSocketFetchBaseUrl = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "/";
}
request = { meeting_id: this.meetingStartRequest.roomId, estimated_users: this.meetingStartRequest.numberOfUsers };
urlToGetIpAddress = this.meetingStartRequest.dynamicWebSocketFetchBaseUrl + "api/getIpAddressForMeeting";
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(JSON.stringify(request));
config = {
headers: {
'Content-Type': 'application/json'
}
};
axios
.post(urlToGetIpAddress, request, config)
.then(function (response) {
_this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("response ", response.data);
if (response && response.data && response.data.status === true && response.data.ipAddress && response.data.ipAddress !== null) {
_this.loadBalancerIpAddressForWebSocket = response.data.ipAddress;
}
_this.connect(false);
})
.catch(function (error) {
_this.connect(false);
log.warn(error);
_this.connect(false);
});
}
else {
this.connect(false);
}
return [2 /*return*/];
});
});
};
WebsocketHandler.prototype.connect = function (isForceFully) {
var _a, _b, _c;
if (isForceFully === void 0) { isForceFully = false; }
return __awaiter(this, void 0, void 0, function () {
var url;
var _this = this;
return __generator(this, function (_d) {
if (this.isEnded === true || this.isWebSocketConnectionInProgress) {
return [2 /*return*/];
}
if (!this.wss || (isForceFully && this.isWebScoketConnected() === false)) {
url = void 0;
if (this.loadBalancerIpAddressForWebSocket) {
url = "ws://" + this.loadBalancerIpAddressForWebSocket + ":4003/?connection=";
}
else if (((_a = this.meetingStartRequest) === null || _a === void 0 ? void 0 : _a.wssUrl) && this.meetingStartRequest.wssUrl !== null) {
url = this.meetingStartRequest.wssUrl;
}
if (url) {
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Connecting to ", url);
this.isWebSocketConnectionInProgress = true;
if ((_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.isMobileApp) {
this.wss = new WebSocket(url + this.connection);
}
else {
this.wss = new WebSocket(url + this.connection);
}
this.wss.onopen = function (event) {
// this.checkIfSocketConnected();
_this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("connected ----");
_this.isWebSocketConnectionInProgress = false;
_this.isSetUpDone = false;
_this.socketCheckTimeout = undefined;
_this.onSocketConnected();
};
this.wss.onmessage = function (event) {
_this.isWebSocketConnectionInProgress = false;
_this.onMessage(event.data);
};
this.wss.onerror = function (event) {
var _a;
_this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("wss error", event);
_this.isWebSocketConnectionInProgress = false;
(_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketError, event);
if (_this.wss) {
_this.wss.close();
}
};
this.wss.onclose = function (event) {
_this.isWebSocketConnectionInProgress = false;
_this.meetingStartRequest && _this.meetingStartRequest.logLevel === LogLevel.Debug && ("WebSocket is closed now.");
log.warn(event);
_this.onWebSocketClosed(event);
};
}
}
else if (isForceFully === false && this.isWebScoketConnected()) {
(_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnSocketConnected, {});
}
return [2 /*return*/];
});
});
};
WebsocketHandler.prototype.isWebScoketConnected = function () {
var _a;
if (this.wss && this.wss.readyState === 1) {
return true;
}
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);
return false;
};
WebsocketHandler.prototype.sendSocketMessage = function (type, data) {
var _a;
if (this.isWebScoketConnected()) {
var paylod = { type: type, data: data };
(_a = this.wss) === null || _a === void 0 ? void 0 : _a.send(JSON.stringify(paylod));
}
};
WebsocketHandler.prototype.reconnectOnInternetFailur = function () {
var _a;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("reconnectOnInternetFailur");
if (this.wss) {
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnReconecting, {});
this.wss.close(3005);
this.wss = undefined;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("this.wss undefined reconnectOnInternetFailur ");
}
this.connection = ConnectionType.reconnect;
this.connect(true);
};
// private checkIfSocketConnected() {
// window.setTimeout(() => {
// if (this.isWebScoketConnected()) {
// log.info("Connected")
// this.checkIfSocketConnected();
// }
// else {
// log.info("Not Connected")
// }
// }, 1000);
// }
WebsocketHandler.prototype.onWebSocketClosed = function (event) {
var _this = this;
var _a;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("onWebSocketClosed", event.code);
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"))) {
this.socketCheckTimeout = window.setTimeout(function () {
var _a;
_this.tryToReconectSocket();
(_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnReconecting, {});
}, 1000);
}
else {
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketDisconnected, {});
}
};
WebsocketHandler.prototype.tryToReconectSocket = function () {
var _a, _b;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("tryToReconectSocket");
if (this.isWebScoketConnected() === false && this.isEnded === false) {
this.wss = undefined;
this.connection = ConnectionType.reconnect;
this.connect(true);
}
else {
this.socketCheckTimeout = undefined;
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketReconnectTimeOut, {});
(_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.emitMessageToSource(VaniEvent.OnSocketDisconnected, {});
}
};
WebsocketHandler.prototype.onSocketConnected = function () {
this.socketSubscribeToTopic();
};
WebsocketHandler.prototype.socketSubscribeToTopic = function () {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
if (this.isWebScoketConnected() === false) {
return;
}
var participant = (_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.getSelfParticipant();
participant.userData = (_b = this.meetingStartRequest) === null || _b === void 0 ? void 0 : _b.userData;
var config = {
connectionProtocol: (_c = this.meetingStartRequest) === null || _c === void 0 ? void 0 : _c.connectionProtocol,
participant: (_d = this.communicationHandler) === null || _d === void 0 ? void 0 : _d.getSelfParticipant(), apiData: (_e = this.meetingStartRequest) === null || _e === void 0 ? void 0 : _e.apiData,
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
};
this.sendSocketMessage(WebSocketBasicEvents.Config, config);
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 };
this.sendSocketMessage(WebSocketBasicEvents.JoinRoom, hostNotificationRoom);
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 };
this.sendSocketMessage(WebSocketBasicEvents.JoinRoom, roomForAllClient);
this.setUpTry = 0;
this.askIfSetupDone();
};
WebsocketHandler.prototype.askIfSetupDone = function () {
var _this = this;
if (this.isSetUpDone || this.setUpTry > 10) {
return;
}
if (!this.meetingStartRequest) {
return;
}
var checkIfSetupDone = { to: this.meetingStartRequest.userId };
this.sendSocketMessage(WebSocketBasicEvents.IsSetupDone, checkIfSetupDone);
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("Vani setupDone asked");
window.setTimeout(function () {
if (_this.isSetUpDone) {
return;
}
else if (_this.setUpTry > 15) {
setTimeout(function () {
var _a;
if (!_this.isSetUpDone) {
(_a = _this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnSocketError, {});
}
}, 10000);
return;
}
_this.askIfSetupDone();
_this.setUpTry = _this.setUpTry + 1;
}, 300);
};
WebsocketHandler.prototype.onMessage = function (message) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
this.lastPingTimeStamp = new Date().getTime();
// this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("lastPingTimeStamp time ", this.lastPingTimeStamp)
var messagejson = JSON.parse(message);
if (messagejson.type && messagejson.data) {
var type = messagejson.type;
var data = messagejson.data;
if (type === WebSocketBasicEvents.Ping) {
this.pongData = data;
this.sendSocketMessage(WebSocketBasicEvents.Pong, data);
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.emitMessageToSource(VaniEvent.OnNewPingFromServer, {});
}
else if (this.isVideoCallControllerMessageType(type)) {
(_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.onVideoCallWebSocketMessage(messagejson);
return;
}
else if (type === WebSocketBasicEvents.IsSetupDone) {
this.onSetupDone(data);
}
else if (type === WebSocketBasicEvents.CloseRoomForceFully) {
this.onCloseTheRoomForcefully(data);
}
else if (type === WebSocketBasicEvents.OnUserOnFoundWhileReconnect) {
(_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnUserOnFoundWhileReconnect, {});
}
else if (type === WebSocketBasicEvents.OnNewJoinee || type === WebSocketBasicEvents.OnRejoined) {
if (data && data.message && data.message.participant) {
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("OnParticipantUpdated from server", data.message.participant);
(_d = this.communicationHandler) === null || _d === void 0 ? void 0 : _d.addParticipantIfNotExist(data.message.participant, true);
}
}
else if (type === WebSocketBasicEvents.OnParticipantUpdated) {
if (data) {
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("WebSocketBasicEvents.OnParticipantUpdated", data.message);
(_e = this.communicationHandler) === null || _e === void 0 ? void 0 : _e.addParticipantIfNotExist(data.message, true);
}
}
else if (type === WebSocketBasicEvents.OnUserLeft) {
(_f = this.communicationHandler) === null || _f === void 0 ? void 0 : _f.onUserLeft(data);
}
else if (type === WebSocketBasicEvents.OnServerParticipants) {
(_g = this.communicationHandler) === null || _g === void 0 ? void 0 : _g.onServerParticipants(data);
}
else if (type === WebSocketBasicEvents.OnOldMessages) {
(_h = this.communicationHandler) === null || _h === void 0 ? void 0 : _h.onOldMessages(data);
}
else if (type === WebSocketBasicEvents.OnChat) {
if (data.message) {
(_j = this.communicationHandler) === null || _j === void 0 ? void 0 : _j.onMessage(data.message);
}
}
else if (type === WebSocketBasicEvents.OnMeetingStartTime) {
if (data && (data.time || data.message)) {
var time = data.time ? data.time : data.message;
if (time > new Date().getTime()) {
time = new Date().getTime();
}
(_k = this.communicationHandler) === null || _k === void 0 ? void 0 : _k.emitMessageToSource(VaniEvent.OnMeetingStartTime, (time + ""));
}
}
else if (type === WebSocketBasicEvents.OnAudioVideoStatusUpdated) {
(_l = this.communicationHandler) === null || _l === void 0 ? void 0 : _l.onAudioVideoStatusUpdated(data);
}
else if (type === WebSocketBasicEvents.OnAudioBlockRequest) {
(_m = this.communicationHandler) === null || _m === void 0 ? void 0 : _m.onAudioBlocked(data);
}
else if (type === WebSocketBasicEvents.OnAudioUnblockRequest) {
(_o = this.communicationHandler) === null || _o === void 0 ? void 0 : _o.onAudioUnblocked(data);
}
else if (type === WebSocketBasicEvents.OnVideoBlockRequest) {
(_p = this.communicationHandler) === null || _p === void 0 ? void 0 : _p.onVideoBlocked(data);
}
else if (type === WebSocketBasicEvents.OnVideoUnblockRequest) {
(_q = this.communicationHandler) === null || _q === void 0 ? void 0 : _q.onVideoUnblocked(data);
}
}
};
WebsocketHandler.prototype.onSetupDone = function (data) {
var _a, _b, _c;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("onSetupDone", this.meetingStartRequest);
if (!this.meetingStartRequest) {
return;
}
if (this.isSetUpDone === false) {
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info(data);
this.isSetUpDone = true;
if ((_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.isStartAndSetupWithServerCalled) {
var isReconnect = data.message.isReconnection;
if (isReconnect) {
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && log.info("'onReconnect Meeting");
(_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.onReconnect();
}
return;
}
else {
(_c = this.communicationHandler) === null || _c === void 0 ? void 0 : _c.emitMessageToSource(VaniEvent.OnConnected, {});
}
}
if (this.pingCheckTimeout) {
window.clearTimeout(this.pingCheckTimeout);
this.pingCheckTimeout = undefined;
}
this.checkIfPingIsRunning();
};
WebsocketHandler.prototype.checkIfPingIsRunning = function () {
var _this = this;
var _a, _b;
if (this.isWebScoketConnected()) {
if (this.pongData) {
this.sendSocketMessage(WebSocketBasicEvents.Pong, this.pongData);
}
if ((this.lastPingTimeStamp + (80 * 1000)) < new Date().getTime()) {
this.pingCheckTimeout = undefined;
this.meetingStartRequest && this.meetingStartRequest.logLevel === LogLevel.Debug && console.log("checkIfPingIsRunning", this.lastPingTimeStamp);
//Discounted
(_a = this.communicationHandler) === null || _a === void 0 ? void 0 : _a.onIceCandidateDisconnected();
(_b = this.communicationHandler) === null || _b === void 0 ? void 0 : _b.emitMessageToSource(VaniEvent.OnNotReachable, {});
}
else {
this.pingCheckTimeout = window.setTimeout(function () {
_this.checkIfPingIsRunning();
}, 5 * 1000);
}
}
};
WebsocketHandler.prototype.isVideoCallControllerMessageType = function (type) {
if (Object.values(SFUMessageType).includes(type)) {
return true;
}
return false;
};
return WebsocketHandler;
}(Base));
export { WebsocketHandler };