@tixyel/streamelements 6.0.2 → 6.0.3

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.d.ts CHANGED
@@ -1907,7 +1907,12 @@ declare class Command {
1907
1907
  type QueueEvents<T> = {
1908
1908
  load: [];
1909
1909
  cancel: [];
1910
- update: [queue: QueueItem<T>[], priorityQueue: QueueItem<T>[], history: QueueItem<T>[], timeouts: Array<ReturnType<typeof setTimeout>>];
1910
+ update: [
1911
+ queue: QueueItem<T>[],
1912
+ priorityQueue: QueueItem<T>[],
1913
+ history: QueueItem<T>[],
1914
+ timeouts: Array<ReturnType<typeof setTimeout>>
1915
+ ];
1911
1916
  process: [item: QueueItem<T>, queue: useQueue<T>];
1912
1917
  };
1913
1918
  type QueueProps = {
@@ -1957,7 +1962,9 @@ declare class useQueue<T> extends EventProvider<QueueEvents<T>> {
1957
1962
  duration: QueueDuration;
1958
1963
  private loaded;
1959
1964
  processor: QueueProcessor<T>;
1965
+ private readonly clientWaitRetryDelay;
1960
1966
  constructor(options: QueueOptions<T>);
1967
+ private waitForClientAndBindLoad;
1961
1968
  /**
1962
1969
  * Enqueue an item or multiple items into the queue with optional processing options.
1963
1970
  * @param value - The item or items to be enqueued. Can be a single value of type T or an array of objects containing the value and options.
package/dist/index.es.js CHANGED
@@ -7171,12 +7171,17 @@ var q;
7171
7171
  })(q || (q = {}));
7172
7172
  class mt extends Z {
7173
7173
  constructor(e) {
7174
- if (super(), this.queue = [], this.priorityQueue = [], this.history = [], this.timeouts = [], this.running = !1, this.duration = void 0, this.loaded = !1, !(window.client instanceof G))
7175
- throw new Error("useQueue can only be instantiated after the Client is initialized.");
7176
- if (!e.processor || typeof e.processor != "function")
7174
+ if (super(), this.queue = [], this.priorityQueue = [], this.history = [], this.timeouts = [], this.running = !1, this.duration = void 0, this.loaded = !1, this.clientWaitRetryDelay = 50, !e.processor || typeof e.processor != "function")
7177
7175
  throw new Error("A valid processor function must be provided to useQueue.");
7178
- this.processor = e.processor, e.duration !== "client" && (this.duration = e.duration ?? 0), window.client.on("load", () => {
7179
- e.duration === "client" && (this.duration = window.client.fields?.widgetDuration ?? 0), this.emit("load"), this.loaded = !0;
7176
+ this.processor = e.processor, e.duration !== "client" && (this.duration = e.duration ?? 0), this.waitForClientAndBindLoad(e.duration);
7177
+ }
7178
+ waitForClientAndBindLoad(e = this.duration) {
7179
+ if (!(window?.client instanceof G)) {
7180
+ setTimeout(() => this.waitForClientAndBindLoad(e), this.clientWaitRetryDelay);
7181
+ return;
7182
+ }
7183
+ window.client.on("load", () => {
7184
+ e === "client" && (this.duration = window.client.fields?.widgetDuration ?? 0), this.emit("load"), this.loaded = !0;
7180
7185
  });
7181
7186
  }
7182
7187
  enqueue(e, t = {}) {
@@ -7209,7 +7214,9 @@ class mt extends Z {
7209
7214
  try {
7210
7215
  await this.processor.apply(this, [e.value, this]), this.emit("process", e, this);
7211
7216
  } catch (a) {
7212
- R.error(`Error during item processing: ${a instanceof Error ? a.message : String(a)}`);
7217
+ R.error(
7218
+ `Error during item processing: ${a instanceof Error ? a.message : String(a)}`
7219
+ );
7213
7220
  }
7214
7221
  this.history.push(e);
7215
7222
  const t = e.isPriority ? this.priorityQueue : this.queue;