react-peer-chat 0.4.1 → 0.4.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/build/index.js +9 -5
- package/build/storage.d.ts +1 -4
- package/build/storage.js +7 -7
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -8,14 +8,14 @@ function closeConnection(conn) {
|
|
|
8
8
|
export default function Chat({ name, peerId, remotePeerId = [], peerOptions, text = true, voice = true, dialogOptions, onError = () => alert('Browser not supported! Try some other browser.'), onMicError = () => alert('Microphone not accessible!'), children, props = {} }) {
|
|
9
9
|
const [peer, setPeer] = useState();
|
|
10
10
|
const [notification, setNotification] = useState(false);
|
|
11
|
-
const [remotePeers, setRemotePeers] = useStorage('rpc-remote-peer', {}
|
|
12
|
-
const [messages, setMessages] = useStorage('rpc-messages', []
|
|
11
|
+
const [remotePeers, setRemotePeers] = useStorage('rpc-remote-peer', {});
|
|
12
|
+
const [messages, setMessages] = useStorage('rpc-messages', []);
|
|
13
13
|
const connRef = useRef({});
|
|
14
14
|
const [dialog, setDialog] = useState(false);
|
|
15
15
|
const dialogRef = useRef(null);
|
|
16
16
|
const containerRef = useRef(null);
|
|
17
17
|
const inputRef = useRef(null);
|
|
18
|
-
const [audio, setAudio] = useStorage('rpc-audio', false,
|
|
18
|
+
const [audio, setAudio] = useStorage('rpc-audio', false, true);
|
|
19
19
|
const streamRef = useRef(null);
|
|
20
20
|
const localStream = useRef();
|
|
21
21
|
peerId = `rpc-${peerId}`;
|
|
@@ -47,6 +47,10 @@ export default function Chat({ name, peerId, remotePeerId = [], peerOptions, tex
|
|
|
47
47
|
});
|
|
48
48
|
conn.on('close', conn.removeAllListeners);
|
|
49
49
|
}
|
|
50
|
+
function handleError() {
|
|
51
|
+
setAudio(false);
|
|
52
|
+
onMicError();
|
|
53
|
+
}
|
|
50
54
|
useEffect(() => {
|
|
51
55
|
if (!text && !audio) {
|
|
52
56
|
setPeer(undefined);
|
|
@@ -93,10 +97,10 @@ export default function Chat({ name, peerId, remotePeerId = [], peerOptions, tex
|
|
|
93
97
|
call.on('close', call.removeAllListeners);
|
|
94
98
|
calls[call.peer] = call;
|
|
95
99
|
});
|
|
96
|
-
},
|
|
100
|
+
}, handleError);
|
|
97
101
|
}
|
|
98
102
|
catch (_a) {
|
|
99
|
-
|
|
103
|
+
handleError();
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
});
|
package/build/storage.d.ts
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
export declare const removeStorage: (key: string, local?: boolean) => void;
|
|
2
|
-
export default function useStorage<Value>(key: string, initialValue: Value,
|
|
3
|
-
local?: boolean | undefined;
|
|
4
|
-
save?: boolean | undefined;
|
|
5
|
-
}): [Value, (value: Value | ((old: Value) => Value)) => void];
|
|
2
|
+
export default function useStorage<Value>(key: string, initialValue: Value, local?: boolean): [Value, (value: Value | ((old: Value) => Value)) => void];
|
package/build/storage.js
CHANGED
|
@@ -2,8 +2,6 @@ import { useState } from "react";
|
|
|
2
2
|
const setStorage = (key, value, local = false) => (local ? localStorage : sessionStorage).setItem(key, JSON.stringify(value));
|
|
3
3
|
export const removeStorage = (key, local = false) => (local ? localStorage : sessionStorage).removeItem(key);
|
|
4
4
|
const getStorage = (key, fallbackValue, local = false) => {
|
|
5
|
-
if (typeof window === "undefined")
|
|
6
|
-
return fallbackValue;
|
|
7
5
|
let value = (local ? localStorage : sessionStorage).getItem(key);
|
|
8
6
|
try {
|
|
9
7
|
if (!value)
|
|
@@ -22,14 +20,16 @@ const getStorage = (key, fallbackValue, local = false) => {
|
|
|
22
20
|
}
|
|
23
21
|
return value;
|
|
24
22
|
};
|
|
25
|
-
export default function useStorage(key, initialValue,
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
export default function useStorage(key, initialValue, local = false) {
|
|
24
|
+
const [storedValue, setStoredValue] = useState(() => {
|
|
25
|
+
if (typeof window === "undefined")
|
|
26
|
+
return initialValue;
|
|
27
|
+
return getStorage(key, initialValue, local);
|
|
28
|
+
});
|
|
28
29
|
const setValue = (value) => {
|
|
29
30
|
setStoredValue((old) => {
|
|
30
31
|
const updatedValue = typeof value === 'function' ? value(old) : value;
|
|
31
|
-
|
|
32
|
-
setStorage(key, updatedValue, local);
|
|
32
|
+
setStorage(key, updatedValue, local);
|
|
33
33
|
return updatedValue;
|
|
34
34
|
});
|
|
35
35
|
};
|