react-peer-chat 0.11.5 → 0.11.6
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 { useChat } from './chunk-
|
|
1
|
+
import { useChat } from './chunk-XJSK56RM.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';
|
|
@@ -31,6 +31,7 @@ var defaults = {
|
|
|
31
31
|
peerOptions: {},
|
|
32
32
|
remotePeerId: []
|
|
33
33
|
};
|
|
34
|
+
var maxReconnectionAttempts = 2;
|
|
34
35
|
|
|
35
36
|
// src/lib/connection.ts
|
|
36
37
|
function closeConnection(conn) {
|
|
@@ -63,6 +64,7 @@ function useChat({
|
|
|
63
64
|
onMessageReceived
|
|
64
65
|
}) {
|
|
65
66
|
const [peerEpoch, setPeerEpoch] = useState(0);
|
|
67
|
+
const [peerGeneration, setPeerGeneration] = useState(0);
|
|
66
68
|
const [audio, setAudio] = useAudio(allowed);
|
|
67
69
|
const peerRef = useRef(null);
|
|
68
70
|
const scheduleReconnectRef = useRef(null);
|
|
@@ -180,13 +182,20 @@ function useChat({
|
|
|
180
182
|
if (!text && !audio) return;
|
|
181
183
|
let destroyed = false;
|
|
182
184
|
let reconnecting = false;
|
|
185
|
+
let reconnectAttempts = 0;
|
|
183
186
|
let reconnectTimer;
|
|
184
187
|
scheduleReconnectRef.current = () => {
|
|
185
188
|
if (destroyed || reconnecting) return;
|
|
186
189
|
reconnecting = true;
|
|
187
190
|
reconnectTimer = setTimeout(() => {
|
|
188
|
-
|
|
189
|
-
if (
|
|
191
|
+
const peer = peerRef.current;
|
|
192
|
+
if (peer) {
|
|
193
|
+
reconnectAttempts++;
|
|
194
|
+
if (reconnectAttempts >= maxReconnectionAttempts) {
|
|
195
|
+
setPeerGeneration((prev) => prev + 1);
|
|
196
|
+
reconnectAttempts = 0;
|
|
197
|
+
} else peer.reconnect();
|
|
198
|
+
}
|
|
190
199
|
reconnecting = false;
|
|
191
200
|
}, 1e3);
|
|
192
201
|
};
|
|
@@ -203,6 +212,7 @@ function useChat({
|
|
|
203
212
|
peerRef.current = new Peer(completePeerId, __spreadValues({ config: defaultConfig }, peerOptions));
|
|
204
213
|
setPeerEpoch((prev) => prev + 1);
|
|
205
214
|
const peer = peerRef.current;
|
|
215
|
+
peer.on("open", () => reconnectAttempts = 0);
|
|
206
216
|
peer.on("connection", handleConnection);
|
|
207
217
|
peer.on("call", handleCall);
|
|
208
218
|
peer.on("disconnected", () => {
|
|
@@ -222,12 +232,14 @@ function useChat({
|
|
|
222
232
|
return () => {
|
|
223
233
|
var _a, _b;
|
|
224
234
|
destroyed = true;
|
|
235
|
+
reconnecting = false;
|
|
236
|
+
reconnectAttempts = 0;
|
|
225
237
|
clearTimeout(reconnectTimer);
|
|
226
238
|
(_a = peerRef.current) == null ? void 0 : _a.removeAllListeners();
|
|
227
239
|
(_b = peerRef.current) == null ? void 0 : _b.destroy();
|
|
228
240
|
peerRef.current = null;
|
|
229
241
|
};
|
|
230
|
-
}, [completePeerId]);
|
|
242
|
+
}, [completePeerId, peerGeneration]);
|
|
231
243
|
useEffect(() => {
|
|
232
244
|
if (!text) return;
|
|
233
245
|
const peer = peerRef.current;
|
package/dist/components.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Chat as default } from './chunks/chunk-
|
|
2
|
-
import './chunks/chunk-
|
|
1
|
+
export { Chat as default } from './chunks/chunk-7M2EWH66.js';
|
|
2
|
+
import './chunks/chunk-XJSK56RM.js';
|
|
3
3
|
import './chunks/chunk-QIPTWGEX.js';
|
|
4
4
|
import './chunks/chunk-ZYFPSCFE.js';
|
|
5
5
|
import './chunks/chunk-FZ4QVG4I.js';
|
package/dist/hooks.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Chat as default } from './chunks/chunk-
|
|
2
|
-
export { useChat } from './chunks/chunk-
|
|
1
|
+
export { Chat as default } from './chunks/chunk-7M2EWH66.js';
|
|
2
|
+
export { useChat } from './chunks/chunk-XJSK56RM.js';
|
|
3
3
|
import './chunks/chunk-QIPTWGEX.js';
|
|
4
4
|
export { clearChat } from './chunks/chunk-ZYFPSCFE.js';
|
|
5
5
|
import './chunks/chunk-FZ4QVG4I.js';
|
package/package.json
CHANGED