@maxverse/media-web-sdk
Version:
197 lines (194 loc) • 8.53 kB
JavaScript
import { createClass as _createClass, classCallCheck as _classCallCheck, classPrivateFieldLooseBase as _classPrivateFieldLooseBase, asyncToGenerator as _asyncToGenerator, objectWithoutProperties as _objectWithoutProperties, toConsumableArray as _toConsumableArray, classPrivateFieldLooseKey as _classPrivateFieldLooseKey, regeneratorRuntime as _regeneratorRuntime } from './_virtual/_rollupPluginBabelHelpers.mjs';
import { Room } from 'livekit-client';
import Presenter from './helper/presenter.mjs';
import DataChannelContainer from './room/dataChannelContainer.mjs';
import Cache from './utils/cache.mjs';
import DI from './utils/DI.mjs';
import LocalTrackController from './helper/localTrack.mjs';
import ParticipantEventContainer from './participant/eventContainer.mjs';
import RoomEventContainer from './room/eventContainer.mjs';
import Connection from './room/connection.mjs';
var _excluded = ["isVideoEnabled", "isAudioEnabled", "videoDeviceId", "audioDeviceId"];
var cache = new Cache();
var di = new DI();
var cacheStrategy = function cacheStrategy(key, callback) {
var value = cache.getValue(key);
if (value) {
return value;
}
var newValue = callback();
cache.setValue(key, newValue);
return newValue;
};
di.register("roomFactory", [], function () {
return function (roomOptions) {
return cacheStrategy("room", function () {
return new Room(roomOptions);
});
};
});
di.register("localTrackControllerFactory", ["roomFactory"], function (roomFactory) {
return function (isVideoEnabled, isAudioEnabeld, videoDeviceId, audioDeviceId) {
return new LocalTrackController(roomFactory(), isVideoEnabled, isAudioEnabeld, videoDeviceId, audioDeviceId);
};
});
di.register("participantEventContainerFactory", ["roomFactory"], function (roomFactory) {
return function (participantHandler) {
return new ParticipantEventContainer(roomFactory(), participantHandler);
};
});
di.register("presenter", ["roomFactory"], function (roomFactory) {
return new Presenter(roomFactory());
});
di.register("dataChannelContainer", ["presenter"], function (presenter) {
return new DataChannelContainer(presenter);
});
di.register("roomEventContainerFactory", ["roomFactory", "dataChannelContainer"], function (roomFactory, dataChannelContainer) {
return function (roomHandler) {
return new RoomEventContainer(roomFactory(), dataChannelContainer, roomHandler);
};
});
di.register("connection", ["roomFactory"], function (roomFactory) {
return new Connection(roomFactory());
});
var _currentRoom = /*#__PURE__*/_classPrivateFieldLooseKey("currentRoom");
var _connection = /*#__PURE__*/_classPrivateFieldLooseKey("connection");
var _localTrackController = /*#__PURE__*/_classPrivateFieldLooseKey("localTrackController");
var _localParticipant = /*#__PURE__*/_classPrivateFieldLooseKey("localParticipant");
var _remoteParticipants = /*#__PURE__*/_classPrivateFieldLooseKey("remoteParticipants");
var _allParticipants = /*#__PURE__*/_classPrivateFieldLooseKey("allParticipants");
var _findParticipant = /*#__PURE__*/_classPrivateFieldLooseKey("findParticipant");
var LiveRoom = /*#__PURE__*/_createClass(function LiveRoom(config) {
var _this = this;
_classCallCheck(this, LiveRoom);
Object.defineProperty(this, _findParticipant, {
value: _findParticipant2
});
Object.defineProperty(this, _allParticipants, {
get: _get_allParticipants,
set: void 0
});
Object.defineProperty(this, _remoteParticipants, {
get: _get_remoteParticipants,
set: void 0
});
Object.defineProperty(this, _localParticipant, {
get: _get_localParticipant,
set: void 0
});
Object.defineProperty(this, _currentRoom, {
writable: true,
value: void 0
});
Object.defineProperty(this, _connection, {
writable: true,
value: void 0
});
Object.defineProperty(this, _localTrackController, {
writable: true,
value: void 0
});
this.prepareConnection = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return _classPrivateFieldLooseBase(_this, _connection)[_connection].prepareConnection(url);
case 2:
return _context.abrupt("return", _context.sent);
case 3:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.connectRoom = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(token, url) {
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return _classPrivateFieldLooseBase(_this, _connection)[_connection].connectToRoom(token, url);
case 2:
return _context2.abrupt("return", _context2.sent);
case 3:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function (_x2, _x3) {
return _ref2.apply(this, arguments);
};
}();
this.toggleCam = function () {
_classPrivateFieldLooseBase(_this, _localTrackController)[_localTrackController].toggleCam();
};
this.toggleMic = function () {
_classPrivateFieldLooseBase(_this, _localTrackController)[_localTrackController].toggleMic();
};
this.toggleScreenShare = function () {
_classPrivateFieldLooseBase(_this, _localTrackController)[_localTrackController].toggleScreenShare();
};
this.bindRoomEvents = function (handler) {
if (!_classPrivateFieldLooseBase(_this, _currentRoom)[_currentRoom]) {
return;
}
di.get("roomEventContainerFactory")(handler).bindRoomEvents();
};
this.initializeCurrentRoomStatus = function (handler) {
_classPrivateFieldLooseBase(_this, _allParticipants)[_allParticipants].forEach(function (participant) {
return di.get("roomEventContainerFactory")(handler).initializeCurrentRoomStatus(participant);
});
};
this.bindParticipantEvents = function (sid, handler) {
var participant = _classPrivateFieldLooseBase(_this, _findParticipant)[_findParticipant](sid);
if (!participant) {
return;
}
di.get("participantEventContainerFactory")(handler).bindParticipantEvents(participant);
};
this.initializeLocalTracks = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.next = 2;
return _classPrivateFieldLooseBase(_this, _localTrackController)[_localTrackController].initializeLocalTracks();
case 2:
case "end":
return _context3.stop();
}
}, _callee3);
}));
this.disConnectRoom = function () {
_classPrivateFieldLooseBase(_this, _connection)[_connection].disConnectRoom();
};
var isVideoEnabled = config.isVideoEnabled,
isAudioEnabled = config.isAudioEnabled,
videoDeviceId = config.videoDeviceId,
audioDeviceId = config.audioDeviceId,
roomOptions = _objectWithoutProperties(config, _excluded);
_classPrivateFieldLooseBase(this, _currentRoom)[_currentRoom] = di.get("roomFactory")(roomOptions);
_classPrivateFieldLooseBase(this, _connection)[_connection] = di.get("connection");
_classPrivateFieldLooseBase(this, _localTrackController)[_localTrackController] = di.get("localTrackControllerFactory")(isVideoEnabled, isAudioEnabled, videoDeviceId, audioDeviceId);
});
function _get_localParticipant() {
return _classPrivateFieldLooseBase(this, _currentRoom)[_currentRoom].localParticipant;
}
function _get_remoteParticipants() {
return Array.from(_classPrivateFieldLooseBase(this, _currentRoom)[_currentRoom].participants.values());
}
function _get_allParticipants() {
return [_classPrivateFieldLooseBase(this, _localParticipant)[_localParticipant]].concat(_toConsumableArray(_classPrivateFieldLooseBase(this, _remoteParticipants)[_remoteParticipants]));
}
function _findParticipant2(sid) {
return _classPrivateFieldLooseBase(this, _allParticipants)[_allParticipants].find(function (participant) {
return participant.sid === sid;
});
}
export { LiveRoom };