@skyway-sdk/core
Version:
The official Next Generation JavaScript SDK for SkyWay
65 lines • 3.25 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.PublishingAgent = void 0;
const common_1 = require("@skyway-sdk/common");
const errors_1 = require("../../../errors");
const util_1 = require("../../../util");
const log = new common_1.Logger('packages/core/src/dataPlane/agent/publishing.ts');
class PublishingAgent {
constructor(_localPerson) {
this._localPerson = _localPerson;
this.context = this._localPerson.context;
}
/**@throws {SkyWayError} */
startPublishing(subscription) {
return __awaiter(this, void 0, void 0, function* () {
if (this.context.config.internal.disableDPlane) {
yield new Promise((r) => setTimeout(r, 500));
return;
}
const publication = subscription.publication;
const endpoint = subscription.subscriber;
// タイミング的にstreamのセットが完了していない可能性がある
if (!publication.stream) {
yield this._localPerson.onStreamPublished
.watch((e) => e.publication.id === publication.id, this.context.config.rtcApi.timeout)
.catch((error) => {
throw (0, util_1.createError)({
operationName: 'PublishingAgent.startPublishing',
context: this.context,
channel: this._localPerson.channel,
info: Object.assign(Object.assign({}, errors_1.errors.timeout), { detail: 'PublishingAgent onStreamPublished' }),
path: log.prefix,
payload: { publication },
error,
});
});
}
const connection = endpoint._getOrCreateConnection(this._localPerson);
if (connection.startPublishing) {
yield connection.startPublishing(publication, subscription.id);
}
});
}
stopPublishing(publication, endpoint) {
return __awaiter(this, void 0, void 0, function* () {
const connection = endpoint._getConnection(this._localPerson.id);
if (connection === null || connection === void 0 ? void 0 : connection.stopPublishing) {
connection.stopPublishing(publication).catch((err) => {
log.error('stopPublishing failed', err);
});
}
});
}
}
exports.PublishingAgent = PublishingAgent;
//# sourceMappingURL=publishing.js.map