@maxverse/media-web-sdk
Version:
128 lines (125 loc) • 5.72 kB
JavaScript
import { createClass as _createClass, classCallCheck as _classCallCheck, classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../_virtual/_rollupPluginBabelHelpers.mjs';
import { RoomEvent } from 'livekit-client';
import { TargetParticipantFactory } from '../participant/targetParticipant.mjs';
import { MetadataSort } from './dataChannelContainer.mjs';
import { sequenceHandler } from '../helper/event.mjs';
var _room = /*#__PURE__*/_classPrivateFieldLooseKey("room");
var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler");
var _dataChannelContainer = /*#__PURE__*/_classPrivateFieldLooseKey("dataChannelContainer");
var RoomEventContainer = /*#__PURE__*/_createClass(function RoomEventContainer(room, dataChannelContainer, handler) {
var _this = this;
_classCallCheck(this, RoomEventContainer);
Object.defineProperty(this, _room, {
writable: true,
value: void 0
});
Object.defineProperty(this, _handler, {
writable: true,
value: void 0
});
Object.defineProperty(this, _dataChannelContainer, {
writable: true,
value: void 0
});
this.bindRoomEvents = function () {
_classPrivateFieldLooseBase(_this, _room)[_room].on(RoomEvent.ParticipantConnected, _this.onParticipantConnected).on(RoomEvent.ParticipantDisconnected, _this.onParticipantDisconnected).on(RoomEvent.ConnectionStateChanged, _this.onConnectionStateChanged).on(RoomEvent.RoomMetadataChanged, _this.onRoomMetadataChanged);
};
this.initializeCurrentRoomStatus = function (participant) {
_this.onParticipantConnected(participant);
};
this.onParticipantConnected = /*#__PURE__*/function () {
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(participant) {
var targetParticipant;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return TargetParticipantFactory.create(participant);
case 2:
targetParticipant = _context.sent;
sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onParticipantConnected, [targetParticipant]);
case 4:
case "end":
return _context.stop();
}
}, _callee);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.onParticipantDisconnected = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(participant) {
var targetParticipant;
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
_context2.next = 2;
return TargetParticipantFactory.create(participant);
case 2:
targetParticipant = _context2.sent;
sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onParticipantDisconnected, [targetParticipant]);
case 4:
case "end":
return _context2.stop();
}
}, _callee2);
}));
return function (_x2) {
return _ref2.apply(this, arguments);
};
}();
this.onConnectionStateChanged = /*#__PURE__*/function () {
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(connectionState) {
var currentConnectionInfo;
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
currentConnectionInfo = {
roomId: _classPrivateFieldLooseBase(_this, _room)[_room].name,
status: connectionState
};
sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onConnectionStateChanged, [currentConnectionInfo]);
case 2:
case "end":
return _context3.stop();
}
}, _callee3);
}));
return function (_x3) {
return _ref3.apply(this, arguments);
};
}();
this.onRoomMetadataChanged = /*#__PURE__*/function () {
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(metadata) {
var data, targetParticipant;
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
data = _classPrivateFieldLooseBase(_this, _dataChannelContainer)[_dataChannelContainer].onFetchMetaDataHandler(metadata);
if (!(data.type === MetadataSort.PRESENTER)) {
_context4.next = 7;
break;
}
_context4.next = 4;
return TargetParticipantFactory.create(data.payload);
case 4:
targetParticipant = _context4.sent;
console.log(targetParticipant);
sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onPresenterUpdated, [targetParticipant]);
case 7:
case "end":
return _context4.stop();
}
}, _callee4);
}));
return function (_x4) {
return _ref4.apply(this, arguments);
};
}();
_classPrivateFieldLooseBase(this, _room)[_room] = room;
_classPrivateFieldLooseBase(this, _dataChannelContainer)[_dataChannelContainer] = dataChannelContainer;
_classPrivateFieldLooseBase(this, _handler)[_handler] = handler;
});
var RoomEventContainer$1 = RoomEventContainer;
export { RoomEventContainer$1 as default };