iii-browser-sdk 0.26.0-rc.6 → 0.26.0-rc.8

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.
package/dist/index.cjs CHANGED
@@ -4121,9 +4121,10 @@ var Sdk = class {
4121
4121
  return;
4122
4122
  }
4123
4123
  }
4124
- /** A state from the engine for `handle`; `disposed` frees its id. */
4124
+ /** A state from the engine for `handle`; `disposed` frees its id, unless the handle observes again. */
4125
4125
  applyObserverState(handle, wireState, reason) {
4126
4126
  const state = toObserverState(wireState);
4127
+ if (state === "disposed" && reason?.code === "OBSERVER_DISCONNECTED" && this.observeAgain(handle)) return;
4127
4128
  handle.setState(state, reason ? {
4128
4129
  code: reason.code,
4129
4130
  message: reason.message
@@ -4132,6 +4133,26 @@ var Sdk = class {
4132
4133
  this.unlistObserve(handle);
4133
4134
  if (this.observerHandles.get(handle.id) === handle) this.observerHandles.delete(handle.id);
4134
4135
  }
4136
+ /**
4137
+ * The engine disposed `handle`'s observer while this worker was away past
4138
+ * `observers.observer_grace_ms` (`OBSERVER_DISCONNECTED`, usually its answer
4139
+ * to the replay): the handle observes its id again at once, a new observer
4140
+ * (acceptance E17), and goes back to `pending` instead of `disposed`. Not
4141
+ * one with `max_fires` or `expires_in_ms` (a new observer would restart its
4142
+ * counters, decision 56), one being disposed, refused or in `error`, or one
4143
+ * already observed again on this connection (the engine disposed that one too).
4144
+ */
4145
+ observeAgain(handle) {
4146
+ const { max_fires, expires_in_ms } = handle.message;
4147
+ if (max_fires != null || expires_in_ms != null || handle.state === "error") return false;
4148
+ if (this.observerHandles.get(handle.id) !== handle || handle.observedAgainOn === this.connectionEpoch) return false;
4149
+ this.logWarn(`Observer ${handle.id}: the engine disposed it while this worker was away past the grace period; observing it again`);
4150
+ handle.observedAgainOn = this.connectionEpoch;
4151
+ this.unlistObserve(handle);
4152
+ handle.setState("pending");
4153
+ this.sendObserve(handle);
4154
+ return true;
4155
+ }
4135
4156
  unlistObserve(handle) {
4136
4157
  const sent = this.observesSent.get(handle.id);
4137
4158
  const at = sent ? sent.indexOf(handle) : -1;