UNPKG

@skyway-sdk/core

Version:

The official Next Generation JavaScript SDK for SkyWay

51 lines 2.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MessageBuffer = void 0; const common_1 = require("@skyway-sdk/common"); const log = new common_1.Logger('packages/core/src/plugin/internal/person/connection/messageBuffer.ts'); /* connectionが生成されるイベントの通信経路と、 メッセージングの通信経路が違うので、 connectionが生成される前にメッセージを受信する タイミング問題が起きうる。 その対策のためのコンポーネント */ class MessageBuffer { constructor(signaling) { this.signaling = signaling; this._indicateMessageBuffer = {}; this._excludeConnectionIndicateBuffering = new Set(); this._disposer = new common_1.EventDisposer(); this.signaling.onMessage .add((req) => { const requesterIdName = req.src.id + req.src.name; if (this._excludeConnectionIndicateBuffering.has(requesterIdName)) { return; } if (!this._indicateMessageBuffer[requesterIdName]) { this._indicateMessageBuffer[requesterIdName] = []; } this._indicateMessageBuffer[requesterIdName].push(req); }) .disposer(this._disposer); } resolveMessagingBuffer({ id, name }) { const endpointIdName = id + name; const bufferedIndicates = this._indicateMessageBuffer[endpointIdName]; if ((bufferedIndicates === null || bufferedIndicates === void 0 ? void 0 : bufferedIndicates.length) > 0) { log.debug('resolveMessagingBuffer', { length: bufferedIndicates.length }); bufferedIndicates.forEach((req) => { this.signaling.onMessage.emit(req); }); delete this._indicateMessageBuffer[endpointIdName]; } this._excludeConnectionIndicateBuffering.add(endpointIdName); } close() { this._disposer.dispose(); this._indicateMessageBuffer = {}; this._excludeConnectionIndicateBuffering = new Set(); } } exports.MessageBuffer = MessageBuffer; //# sourceMappingURL=messageBuffer.js.map