@textmode/runner-client 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,5 +109,6 @@ export declare class IframeTextmodeRuntime {
109
109
  private assertSandboxOriginPolicy;
110
110
  private setStatus;
111
111
  private disposeFrame;
112
+ private rejectPendingHandshake;
112
113
  private createRequestId;
113
114
  }
@@ -113,6 +113,7 @@ export class IframeTextmodeRuntime {
113
113
  if (this.isReady && this.iframe?.isConnected) {
114
114
  return true;
115
115
  }
116
+ this.rejectPendingHandshake('runner initialization superseded');
116
117
  this.disposeFrame();
117
118
  this.ready = false;
118
119
  this.setStatus('connecting');
@@ -129,6 +130,8 @@ export class IframeTextmodeRuntime {
129
130
  }, this.handshakeTimeoutMs);
130
131
  });
131
132
  iframe.addEventListener('load', () => {
133
+ if (this.iframe !== iframe)
134
+ return;
132
135
  this.connectPort();
133
136
  }, { once: true });
134
137
  return readyPromise;
@@ -149,6 +152,7 @@ export class IframeTextmodeRuntime {
149
152
  }
150
153
  this.pending.rejectAll(new Error('runner disposed'));
151
154
  this.heartbeat.stop();
155
+ this.rejectPendingHandshake('runner disposed');
152
156
  this.disposeFrame();
153
157
  this.ready = false;
154
158
  this.setStatus('idle');
@@ -338,6 +342,7 @@ export class IframeTextmodeRuntime {
338
342
  }
339
343
  this.heartbeat.stop();
340
344
  this.pending.rejectAll(new Error('runner reconnecting'));
345
+ this.rejectPendingHandshake('runner reconnecting');
341
346
  this.ready = false;
342
347
  this.disposeFrame();
343
348
  }
@@ -380,6 +385,18 @@ export class IframeTextmodeRuntime {
380
385
  this.iframe = null;
381
386
  }
382
387
  }
388
+ rejectPendingHandshake(reason) {
389
+ if (!this.readyRejecter && !this.readyResolver) {
390
+ return;
391
+ }
392
+ if (this.readyTimeoutId !== null) {
393
+ window.clearTimeout(this.readyTimeoutId);
394
+ this.readyTimeoutId = null;
395
+ }
396
+ this.readyRejecter?.(new Error(reason));
397
+ this.readyResolver = null;
398
+ this.readyRejecter = null;
399
+ }
383
400
  createRequestId(prefix) {
384
401
  return `${prefix}_${Date.now()}_${Math.random().toString(36).slice(2)}`;
385
402
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@textmode/runner-client",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Browser iframe runtime client for the hosted textmode runner.",
5
5
  "license": "AGPL-3.0-or-later",
6
6
  "type": "module",