UNPKG

@skyway-sdk/core

Version:

The official Next Generation JavaScript SDK for SkyWay

50 lines 2.58 kB
"use strict"; 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.SubscribingAgent = void 0; class SubscribingAgent { constructor(_localPerson) { this._localPerson = _localPerson; this._disposers = {}; this._context = this._localPerson.context; } startSubscribing(subscription) { return __awaiter(this, void 0, void 0, function* () { if (this._context.config.internal.disableDPlane) { yield new Promise((r) => setTimeout(r, 500)); return; } const publisher = subscription.publication.publisher; const connection = publisher._getOrCreateConnection(this._localPerson); if (connection.startSubscribing) { yield connection.startSubscribing(subscription); const { removeListener } = subscription._onChangeEncoding.add(() => __awaiter(this, void 0, void 0, function* () { var _a; yield ((_a = connection.changePreferredEncoding) === null || _a === void 0 ? void 0 : _a.call(connection, subscription)); })); this._disposers[subscription.id] = removeListener; } }); } stopSubscribing(subscription) { var _a, _b; return __awaiter(this, void 0, void 0, function* () { const publisher = subscription.publication.publisher; const connection = publisher._getConnection(this._localPerson.id); if (connection === null || connection === void 0 ? void 0 : connection.stopSubscribing) { yield connection.stopSubscribing(subscription); (_b = (_a = this._disposers)[subscription.id]) === null || _b === void 0 ? void 0 : _b.call(_a); } }); } } exports.SubscribingAgent = SubscribingAgent; //# sourceMappingURL=subscribing.js.map