react-peer-chat 0.11.5 → 0.11.7

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.
@@ -31,6 +31,8 @@ var defaults = {
31
31
  peerOptions: {},
32
32
  remotePeerId: []
33
33
  };
34
+ var iosRegex = /iPhone|iPad|iPod/i;
35
+ var mobileRegex = /Android|webOS|BlackBerry|IEMobile|Opera Mini/i;
34
36
 
35
37
  // src/lib/connection.ts
36
38
  function closeConnection(conn) {
@@ -40,6 +42,12 @@ function closeConnection(conn) {
40
42
 
41
43
  // src/lib/utils.ts
42
44
  var addPrefix = (str) => `rpc-${str}`;
45
+ function isMobile(iOS = true) {
46
+ var _a;
47
+ let result = (_a = navigator.userAgentData) == null ? void 0 : _a.mobile;
48
+ result != null ? result : result = mobileRegex.test(navigator.userAgent) || iOS && iosRegex.test(navigator.userAgent);
49
+ return result;
50
+ }
43
51
 
44
52
  // src/lib/react.ts
45
53
  function isSetStateFunction(v) {
@@ -63,6 +71,7 @@ function useChat({
63
71
  onMessageReceived
64
72
  }) {
65
73
  const [peerEpoch, setPeerEpoch] = useState(0);
74
+ const [peerGeneration, setPeerGeneration] = useState(0);
66
75
  const [audio, setAudio] = useAudio(allowed);
67
76
  const peerRef = useRef(null);
68
77
  const scheduleReconnectRef = useRef(null);
@@ -185,8 +194,11 @@ function useChat({
185
194
  if (destroyed || reconnecting) return;
186
195
  reconnecting = true;
187
196
  reconnectTimer = setTimeout(() => {
188
- var _a;
189
- if (!destroyed && ((_a = peerRef.current) == null ? void 0 : _a.disconnected)) peerRef.current.reconnect();
197
+ const peer = peerRef.current;
198
+ if (peer) {
199
+ if (isMobile()) setPeerGeneration((prev) => prev + 1);
200
+ else peer.reconnect();
201
+ }
190
202
  reconnecting = false;
191
203
  }, 1e3);
192
204
  };
@@ -222,12 +234,13 @@ function useChat({
222
234
  return () => {
223
235
  var _a, _b;
224
236
  destroyed = true;
237
+ reconnecting = false;
225
238
  clearTimeout(reconnectTimer);
226
239
  (_a = peerRef.current) == null ? void 0 : _a.removeAllListeners();
227
240
  (_b = peerRef.current) == null ? void 0 : _b.destroy();
228
241
  peerRef.current = null;
229
242
  };
230
- }, [completePeerId]);
243
+ }, [completePeerId, peerGeneration]);
231
244
  useEffect(() => {
232
245
  if (!text) return;
233
246
  const peer = peerRef.current;
@@ -1,4 +1,4 @@
1
- import { useChat } from './chunk-JNCYZVYO.js';
1
+ import { useChat } from './chunk-24RW4ODA.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-7LX3CBZL.js';
2
- import './chunks/chunk-JNCYZVYO.js';
1
+ export { Chat as default } from './chunks/chunk-7UUTQKOW.js';
2
+ import './chunks/chunk-24RW4ODA.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
@@ -1,3 +1,3 @@
1
- export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-JNCYZVYO.js';
1
+ export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-24RW4ODA.js';
2
2
  import './chunks/chunk-ZYFPSCFE.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-7LX3CBZL.js';
2
- export { useChat } from './chunks/chunk-JNCYZVYO.js';
1
+ export { Chat as default } from './chunks/chunk-7UUTQKOW.js';
2
+ export { useChat } from './chunks/chunk-24RW4ODA.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.11.5",
3
+ "version": "0.11.7",
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>",