@skyway-sdk/core
Version:
The official Next Generation JavaScript SDK for SkyWay
99 lines • 3.74 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalStreamBase = void 0;
const common_1 = require("@skyway-sdk/common");
const token_1 = require("@skyway-sdk/token");
class LocalStreamBase {
/**@internal */
constructor(contentType) {
this.contentType = contentType;
this.side = 'local';
/**@internal */
this._onConnectionStateChanged = new common_1.Event();
this.id = (0, token_1.uuidV4)();
/**@internal */
this._label = '';
this.published = false;
/**@private */
this._getTransportCallbacks = {};
/**@private */
this._getStatsCallbacks = {};
this._connectionState = {};
}
/**@internal */
_setLabel(label) {
this._label = label;
}
/**@internal */
_unpublished() {
this.published = false;
this._getTransportCallbacks = {};
this._getStatsCallbacks = {};
}
/**@internal */
_getTransport(selector) {
var _a, _b;
const id = typeof selector === 'string' ? selector : selector.id;
return (_b = (_a = this._getTransportCallbacks)[id]) === null || _b === void 0 ? void 0 : _b.call(_a);
}
/**@internal */
_setConnectionState(remoteMember, state) {
if (this._connectionState[remoteMember.id] === state)
return;
this._connectionState[remoteMember.id] = state;
this._onConnectionStateChanged.emit({ remoteMember, state });
}
/**@internal */
_getStats(selector) {
var _a, _b, _c;
const id = typeof selector === 'string' ? selector : selector.id;
return (_c = (_b = (_a = this._getStatsCallbacks)[id]) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : [];
}
/**@internal */
_getStatsAll() {
return Promise.all(Object.entries(this._getStatsCallbacks).map(([key, cb]) => __awaiter(this, void 0, void 0, function* () {
return ({
memberId: key,
stats: yield cb().catch(() => []),
});
})));
}
/**@internal */
_getRTCPeerConnection(selector) {
var _a;
return (_a = this._getTransport(selector)) === null || _a === void 0 ? void 0 : _a.rtcPeerConnection;
}
/**@internal */
_getConnectionState(selector) {
var _a;
const id = typeof selector === 'string' ? selector : selector.id;
return (_a = this._connectionState[id]) !== null && _a !== void 0 ? _a : 'new';
}
/**@internal */
_getConnectionStateAll() {
return Object.keys(this._getTransportCallbacks).map((memberId) => ({
memberId,
connectionState: this._getConnectionState(memberId),
}));
}
/**@internal */
toJSON() {
return {
label: this._label,
contentType: this.contentType,
id: this.id,
side: this.side,
};
}
}
exports.LocalStreamBase = LocalStreamBase;
//# sourceMappingURL=base.js.map