@tixyel/streamelements 6.0.2 → 6.1.0

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
@@ -1740,15 +1740,12 @@ type UseStorageOptions<T> = {
1740
1740
  data: T;
1741
1741
  };
1742
1742
  declare class useStorage<T extends JSONObject> extends EventProvider<UseStorageEvents<T>> {
1743
- /**
1744
- * The unique identifier for the storage instance.
1745
- */
1743
+ private SE_API;
1744
+ /** The unique identifier for the storage instance. */
1746
1745
  id: string;
1747
1746
  loaded: boolean;
1748
1747
  data: T;
1749
1748
  constructor(options: UseStorageOptions<T>);
1750
- SE_API: StreamElements.SE_API | null;
1751
- private start;
1752
1749
  /**
1753
1750
  * Saves the current data to storage.
1754
1751
  * @param data Data to save (defaults to current)
@@ -1907,7 +1904,12 @@ declare class Command {
1907
1904
  type QueueEvents<T> = {
1908
1905
  load: [];
1909
1906
  cancel: [];
1910
- update: [queue: QueueItem<T>[], priorityQueue: QueueItem<T>[], history: QueueItem<T>[], timeouts: Array<ReturnType<typeof setTimeout>>];
1907
+ update: [
1908
+ queue: QueueItem<T>[],
1909
+ priorityQueue: QueueItem<T>[],
1910
+ history: QueueItem<T>[],
1911
+ timeouts: Array<ReturnType<typeof setTimeout>>
1912
+ ];
1911
1913
  process: [item: QueueItem<T>, queue: useQueue<T>];
1912
1914
  };
1913
1915
  type QueueProps = {
@@ -1957,7 +1959,9 @@ declare class useQueue<T> extends EventProvider<QueueEvents<T>> {
1957
1959
  duration: QueueDuration;
1958
1960
  private loaded;
1959
1961
  processor: QueueProcessor<T>;
1962
+ private readonly clientWaitRetryDelay;
1960
1963
  constructor(options: QueueOptions<T>);
1964
+ private waitForClientAndBindLoad;
1961
1965
  /**
1962
1966
  * Enqueue an item or multiple items into the queue with optional processing options.
1963
1967
  * @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.
@@ -2822,6 +2826,58 @@ declare namespace Data {
2822
2826
  }[];
2823
2827
  }
2824
2828
 
2829
+ type MessageMap = Record<string, any>;
2830
+ type MessageTuple<T extends MessageMap> = {
2831
+ [K in keyof T]: [key: K, data: T[K]];
2832
+ }[keyof T];
2833
+ type BaseEvents<T extends MessageMap> = {
2834
+ load: [];
2835
+ message: MessageTuple<T>;
2836
+ };
2837
+ type UseCommsOptions = {
2838
+ id?: string;
2839
+ };
2840
+ type UseCommItem<T extends MessageMap> = {
2841
+ nonce: string;
2842
+ key: keyof T;
2843
+ value: T[keyof T];
2844
+ timestamp: string;
2845
+ };
2846
+ /**
2847
+ * A module for handling communications between different widgets inside streamelements.
2848
+ * @example
2849
+ * ```ts
2850
+ * type CommsMessages = {
2851
+ * hello: { loaded: boolean };
2852
+ * update: { value: number };
2853
+ * reload: {};
2854
+ * tags: string[];
2855
+ * }
2856
+ *
2857
+ * const comms = new useComms<CommsMessages>();
2858
+ *
2859
+ * comms.on('message', (message, data) => {
2860
+ * switch (message) {
2861
+ * case 'hello': {}
2862
+ * case 'update': {}
2863
+ * case 'reload': {}
2864
+ * case 'tags': {}
2865
+ * }
2866
+ * })
2867
+ * ```
2868
+ */
2869
+ declare class useComms<T extends MessageMap> extends EventProvider<BaseEvents<T>> {
2870
+ private SE_API;
2871
+ id: string;
2872
+ loaded: boolean;
2873
+ private history;
2874
+ private detected;
2875
+ constructor(options?: UseCommsOptions);
2876
+ send<K extends keyof T>(key: K, data: T[K]): Promise<void>;
2877
+ update(history: Array<UseCommItem<T>>): void;
2878
+ on<K extends keyof BaseEvents<T>>(eventName: K, callback: (this: useComms<T>, ...args: BaseEvents<T>[K]) => void): this;
2879
+ }
2880
+
2825
2881
  declare const main: {
2826
2882
  SeAPI: Promise<StreamElements.SE_API>;
2827
2883
  Client: typeof Client;
@@ -2834,6 +2890,7 @@ declare const main: {
2834
2890
  useStorage: typeof useStorage;
2835
2891
  useQueue: typeof useQueue;
2836
2892
  useLogger: typeof useLogger;
2893
+ useComms: typeof useComms;
2837
2894
  };
2838
2895
  actions: {
2839
2896
  Button: typeof Button;
@@ -2844,6 +2901,7 @@ declare const main: {
2844
2901
  };
2845
2902
  data: {
2846
2903
  usedStorages: useStorage<any>[];
2904
+ usedComms: useComms<any>[];
2847
2905
  };
2848
2906
  pronouns: {
2849
2907
  Alejo: typeof Alejo;