| "use strict"; |
| Object.defineProperty(exports, "__esModule", { value: true }); |
| exports.InMemoryTransport = void 0; |
| |
| |
| |
| class InMemoryTransport { |
| constructor() { |
| this._messageQueue = []; |
| } |
| |
| |
| |
| static createLinkedPair() { |
| const clientTransport = new InMemoryTransport(); |
| const serverTransport = new InMemoryTransport(); |
| clientTransport._otherTransport = serverTransport; |
| serverTransport._otherTransport = clientTransport; |
| return [clientTransport, serverTransport]; |
| } |
| async start() { |
| var _a; |
| |
| while (this._messageQueue.length > 0) { |
| const queuedMessage = this._messageQueue.shift(); |
| (_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, queuedMessage.message, queuedMessage.extra); |
| } |
| } |
| async close() { |
| var _a; |
| const other = this._otherTransport; |
| this._otherTransport = undefined; |
| await (other === null || other === void 0 ? void 0 : other.close()); |
| (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this); |
| } |
| |
| |
| |
| |
| async send(message, options) { |
| if (!this._otherTransport) { |
| throw new Error("Not connected"); |
| } |
| if (this._otherTransport.onmessage) { |
| this._otherTransport.onmessage(message, { authInfo: options === null || options === void 0 ? void 0 : options.authInfo }); |
| } |
| else { |
| this._otherTransport._messageQueue.push({ message, extra: { authInfo: options === null || options === void 0 ? void 0 : options.authInfo } }); |
| } |
| } |
| } |
| exports.InMemoryTransport = InMemoryTransport; |
| |