UNPKG

@maxverse/media-web-sdk

Version:
141 lines (138 loc) 7.09 kB
import { createClass as _createClass, classCallCheck as _classCallCheck, classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../_virtual/_rollupPluginBabelHelpers.mjs'; import { LocalParticipant, ParticipantEvent, Track } from 'livekit-client'; import { TargetParticipantFactory } from './targetParticipant.mjs'; import { sequenceHandler } from '../helper/event.mjs'; var _room = /*#__PURE__*/_classPrivateFieldLooseKey("room"); var _handler = /*#__PURE__*/_classPrivateFieldLooseKey("handler"); var _onLocalTrackUpdated = /*#__PURE__*/_classPrivateFieldLooseKey("onLocalTrackUpdated"); var _onRemoteTrackUpdated = /*#__PURE__*/_classPrivateFieldLooseKey("onRemoteTrackUpdated"); var _onTrackSwitched = /*#__PURE__*/_classPrivateFieldLooseKey("onTrackSwitched"); var ParticipantEventContainer = /*#__PURE__*/_createClass(function ParticipantEventContainer(room, handler) { var _this = this; _classCallCheck(this, ParticipantEventContainer); Object.defineProperty(this, _room, { writable: true, value: void 0 }); Object.defineProperty(this, _handler, { writable: true, value: void 0 }); this.bindParticipantEvents = function (participant) { if (participant instanceof LocalParticipant) { participant.on(ParticipantEvent.LocalTrackPublished, _classPrivateFieldLooseBase(_this, _onLocalTrackUpdated)[_onLocalTrackUpdated]).on(ParticipantEvent.LocalTrackUnpublished, _classPrivateFieldLooseBase(_this, _onLocalTrackUpdated)[_onLocalTrackUpdated]); } participant.on(ParticipantEvent.TrackSubscribed, function (remoteTrack, remoteTrackPublication) { _classPrivateFieldLooseBase(_this, _onRemoteTrackUpdated)[_onRemoteTrackUpdated](participant, remoteTrack, remoteTrackPublication); }).on(ParticipantEvent.TrackUnsubscribed, function (remoteTrack, remoteTrackPublication) { _classPrivateFieldLooseBase(_this, _onRemoteTrackUpdated)[_onRemoteTrackUpdated](participant, remoteTrack, remoteTrackPublication); }).on(ParticipantEvent.TrackMuted, function (trackPublication) { _classPrivateFieldLooseBase(_this, _onTrackSwitched)[_onTrackSwitched](participant, trackPublication); }).on(ParticipantEvent.TrackUnmuted, function (trackPublication) { _classPrivateFieldLooseBase(_this, _onTrackSwitched)[_onTrackSwitched](participant, trackPublication); }); }; Object.defineProperty(this, _onLocalTrackUpdated, { writable: true, value: function () { var _value = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(localTrackPublication) { var source, targetParticipant; return _regeneratorRuntime().wrap(function _callee$(_context) { while (1) switch (_context.prev = _context.next) { case 0: source = localTrackPublication.source; _context.next = 3; return TargetParticipantFactory.create(_classPrivateFieldLooseBase(_this, _room)[_room].localParticipant); case 3: targetParticipant = _context.sent; if (source === Track.Source.Camera) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onLocalVideoUpdated, [targetParticipant]); } if (source === Track.Source.Microphone) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onLocalAudioUpdated, [targetParticipant]); } if (source === Track.Source.ScreenShare) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onLocalScreenShareUpdated, [targetParticipant]); } case 7: case "end": return _context.stop(); } }, _callee); })); function value(_x) { return _value.apply(this, arguments); } return value; }() }); Object.defineProperty(this, _onRemoteTrackUpdated, { writable: true, value: function () { var _value2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(participant, _remoteTrack, remoteTrackPublication) { var source, targetParticipant; return _regeneratorRuntime().wrap(function _callee2$(_context2) { while (1) switch (_context2.prev = _context2.next) { case 0: source = remoteTrackPublication.source; _context2.next = 3; return TargetParticipantFactory.create(participant); case 3: targetParticipant = _context2.sent; if (source === Track.Source.Camera) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onRemoteVideoUpdated, [targetParticipant]); } if (source === Track.Source.Microphone) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onRemoteAudioUpdated, [targetParticipant]); } if (source === Track.Source.ScreenShare) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onRemoteScreenShareUpdated, [targetParticipant]); } case 7: case "end": return _context2.stop(); } }, _callee2); })); function value(_x2, _x3, _x4) { return _value2.apply(this, arguments); } return value; }() }); Object.defineProperty(this, _onTrackSwitched, { writable: true, value: function () { var _value3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(participant, trackPublication) { var source, targetParticipant; return _regeneratorRuntime().wrap(function _callee3$(_context3) { while (1) switch (_context3.prev = _context3.next) { case 0: source = trackPublication.source; _context3.next = 3; return TargetParticipantFactory.create(participant); case 3: targetParticipant = _context3.sent; if (source === Track.Source.Camera) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onVideoSwitched, [targetParticipant]); } if (source === Track.Source.Microphone) { sequenceHandler(_classPrivateFieldLooseBase(_this, _handler)[_handler].onAudioSwitched, [targetParticipant]); } case 6: case "end": return _context3.stop(); } }, _callee3); })); function value(_x5, _x6) { return _value3.apply(this, arguments); } return value; }() }); _classPrivateFieldLooseBase(this, _room)[_room] = room; _classPrivateFieldLooseBase(this, _handler)[_handler] = handler; }); var ParticipantEventContainer$1 = ParticipantEventContainer; export { ParticipantEventContainer$1 as default };