@maxverse/media-web-sdk
Version:
84 lines (81 loc) • 3.47 kB
JavaScript
import { createClass as _createClass, classCallCheck as _classCallCheck, asyncToGenerator as _asyncToGenerator, classPrivateFieldLooseBase as _classPrivateFieldLooseBase, classPrivateFieldLooseKey as _classPrivateFieldLooseKey, regeneratorRuntime as _regeneratorRuntime } from '../_virtual/_rollupPluginBabelHelpers.mjs';
import { InitialConnectionStatus } from '../types/index.mjs';
var _room = /*#__PURE__*/_classPrivateFieldLooseKey("room");
var _url = /*#__PURE__*/_classPrivateFieldLooseKey("url");
var Connection = /*#__PURE__*/_createClass(function Connection(room) {
var _this = this;
_classCallCheck(this, Connection);
Object.defineProperty(this, _room, {
writable: true,
value: void 0
});
Object.defineProperty(this, _url, {
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:
url = url || _classPrivateFieldLooseBase(_this, _url)[_url];
_context.prev = 1;
_context.next = 4;
return _classPrivateFieldLooseBase(_this, _room)[_room].prepareConnection(url);
case 4:
return _context.abrupt("return", InitialConnectionStatus.PREPARE_CONNECTION_SUCCESS);
case 7:
_context.prev = 7;
_context.t0 = _context["catch"](1);
throw new Error('prepare connection fail');
case 10:
case "end":
return _context.stop();
}
}, _callee, null, [[1, 7]]);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
this.connectToRoom = /*#__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:
url = url || _classPrivateFieldLooseBase(_this, _url)[_url];
_context2.prev = 1;
_context2.next = 4;
return _classPrivateFieldLooseBase(_this, _room)[_room].connect(url, token);
case 4:
return _context2.abrupt("return", InitialConnectionStatus.CONNECTION_SUCCESS);
case 7:
_context2.prev = 7;
_context2.t0 = _context2["catch"](1);
throw new Error('connection fail');
case 10:
case "end":
return _context2.stop();
}
}, _callee2, null, [[1, 7]]);
}));
return function (_x2, _x3) {
return _ref2.apply(this, arguments);
};
}();
this.disConnectRoom = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_classPrivateFieldLooseBase(_this, _room)[_room].disconnect();
case 1:
case "end":
return _context3.stop();
}
}, _callee3);
}));
_classPrivateFieldLooseBase(this, _room)[_room] = room;
_classPrivateFieldLooseBase(this, _url)[_url] = 'wss://media.maxverse.io';
});
var Connection$1 = Connection;
export { Connection$1 as default };