react-peer-chat 0.11.8 → 0.11.9

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.
@@ -1,4 +1,4 @@
1
- import { getStorage, subscribeToStorage, setStorage } from './chunk-RM3QSN63.js';
1
+ import { getStorage, subscribeToStorage, setStorage } from './chunk-MRYWIJDZ.js';
2
2
  import { __spreadValues, __async, __spreadProps } from './chunk-FZ4QVG4I.js';
3
3
  import { useState, useRef, useMemo, useEffect } from 'react';
4
4
 
@@ -288,7 +288,7 @@ function useMessages() {
288
288
  return [messages, setMessages, addMessage];
289
289
  }
290
290
  function useStorage(key, initialValue, local = false) {
291
- const [storedValue, setStoredValue] = useState(() => typeof window === "undefined" ? initialValue : getStorage(key, initialValue, local));
291
+ const [storedValue, setStoredValue] = useState(() => typeof window === "undefined" ? initialValue : getStorage(key, local, initialValue));
292
292
  const setValue = (value) => {
293
293
  setStoredValue((prev) => {
294
294
  const next = isSetStateFunction(value) ? value(prev) : value;
@@ -1,21 +1,12 @@
1
1
  // src/lib/storage.ts
2
2
  var listeners = /* @__PURE__ */ new Map();
3
3
  function clearChat() {
4
- removeStorage("rpc-remote-peer");
5
- removeStorage("rpc-messages");
4
+ removeStorage("rpc-remote-peer", false);
5
+ removeStorage("rpc-messages", false);
6
6
  }
7
- var getStorageInstance = (local = true) => local ? localStorage : sessionStorage;
8
- function clearStorage(prefix = "", local = true) {
9
- const storage = getStorageInstance(local);
10
- const keysToRemove = [];
11
- for (let i = 0; i < storage.length; i++) {
12
- const key = storage.key(i);
13
- if (key && key.startsWith(prefix)) keysToRemove.push(key);
14
- }
15
- keysToRemove.forEach((key) => removeStorage(key, local));
16
- }
17
- var getNamespacedKey = (key, local = true) => `${local ? "local" : "session"}:${key}`;
18
- function getStorage(key, fallbackValue, local = true) {
7
+ var getStorageInstance = (local) => local ? localStorage : sessionStorage;
8
+ var getNamespacedKey = (key, local) => `${local ? "local" : "session"}:${key}`;
9
+ function getStorage(key, local, fallbackValue) {
19
10
  if (typeof window === "undefined") return fallbackValue;
20
11
  const value = getStorageInstance(local).getItem(key);
21
12
  if (value) {
@@ -32,12 +23,12 @@ function publish(key, local, value) {
32
23
  const callbacks = listeners.get(getNamespacedKey(key, local));
33
24
  if (callbacks) callbacks.forEach((callback) => callback(value));
34
25
  }
35
- function removeStorage(key, local = true) {
26
+ function removeStorage(key, local) {
36
27
  getStorageInstance(local).removeItem(key);
37
28
  publish(key, local);
38
29
  }
39
- function setStorage(key, value, local = true) {
40
- if (typeof value === "function") value = value(getStorage(key, void 0, local));
30
+ function setStorage(key, value, local) {
31
+ if (typeof value === "function") value = value(getStorage(key, local));
41
32
  getStorageInstance(local).setItem(key, JSON.stringify(value));
42
33
  publish(key, local, value);
43
34
  }
@@ -52,4 +43,4 @@ function subscribeToStorage(key, local, callback) {
52
43
  };
53
44
  }
54
45
 
55
- export { clearChat, clearStorage, getStorage, removeStorage, setStorage, subscribeToStorage };
46
+ export { clearChat, getStorage, removeStorage, setStorage, subscribeToStorage };
@@ -1,4 +1,4 @@
1
- import { useChat } from './chunk-NWSTDMKZ.js';
1
+ import { useChat } from './chunk-KLBS4XTE.js';
2
2
  import { BiSolidMessageX, BiSolidMessageDetail, GrSend, BsFillMicFill, BsFillMicMuteFill } from './chunk-QIPTWGEX.js';
3
3
  import { __objRest, __spreadValues } from './chunk-FZ4QVG4I.js';
4
4
  import React, { useRef, useState, useEffect } from 'react';
@@ -1,5 +1,5 @@
1
- export { Chat as default } from './chunks/chunk-63W3RVVG.js';
2
- import './chunks/chunk-NWSTDMKZ.js';
1
+ export { Chat as default } from './chunks/chunk-SO7XYGB7.js';
2
+ import './chunks/chunk-KLBS4XTE.js';
3
3
  import './chunks/chunk-QIPTWGEX.js';
4
- import './chunks/chunk-RM3QSN63.js';
4
+ import './chunks/chunk-MRYWIJDZ.js';
5
5
  import './chunks/chunk-FZ4QVG4I.js';
package/dist/hooks.js CHANGED
@@ -1,3 +1,3 @@
1
- export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-NWSTDMKZ.js';
2
- import './chunks/chunk-RM3QSN63.js';
1
+ export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-KLBS4XTE.js';
2
+ import './chunks/chunk-MRYWIJDZ.js';
3
3
  import './chunks/chunk-FZ4QVG4I.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export { Chat as default } from './chunks/chunk-63W3RVVG.js';
2
- export { useChat } from './chunks/chunk-NWSTDMKZ.js';
1
+ export { Chat as default } from './chunks/chunk-SO7XYGB7.js';
2
+ export { useChat } from './chunks/chunk-KLBS4XTE.js';
3
3
  import './chunks/chunk-QIPTWGEX.js';
4
- export { clearChat } from './chunks/chunk-RM3QSN63.js';
4
+ export { clearChat } from './chunks/chunk-MRYWIJDZ.js';
5
5
  import './chunks/chunk-FZ4QVG4I.js';
@@ -3,10 +3,9 @@ import 'peerjs';
3
3
  import 'react';
4
4
 
5
5
  declare function clearChat(): void;
6
- declare function clearStorage(prefix?: string, local?: boolean): void;
7
- declare function getStorage<T>(key: string, fallbackValue?: T, local?: boolean): T | undefined;
8
- declare function removeStorage(key: string, local?: boolean): void;
9
- declare function setStorage(key: string, value: unknown, local?: boolean): void;
6
+ declare function getStorage<T>(key: string, local: boolean, fallbackValue?: T): T | undefined;
7
+ declare function removeStorage(key: string, local: boolean): void;
8
+ declare function setStorage(key: string, value: unknown, local: boolean): void;
10
9
  declare function subscribeToStorage<T>(key: string, local: boolean, callback: (value: T) => void): VoidFunction;
11
10
 
12
- export { clearChat, clearStorage, getStorage, removeStorage, setStorage, subscribeToStorage };
11
+ export { clearChat, getStorage, removeStorage, setStorage, subscribeToStorage };
@@ -1,2 +1,2 @@
1
- export { clearChat, clearStorage, getStorage, removeStorage, setStorage, subscribeToStorage } from '../chunks/chunk-RM3QSN63.js';
1
+ export { clearChat, getStorage, removeStorage, setStorage, subscribeToStorage } from '../chunks/chunk-MRYWIJDZ.js';
2
2
  import '../chunks/chunk-FZ4QVG4I.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.11.8",
3
+ "version": "0.11.9",
4
4
  "description": "An easy to use react component for impleting peer-to-peer chatting.",
5
5
  "license": "MIT",
6
6
  "author": "Sahil Aggarwal <aggarwalsahil2004@gmail.com>",