react-peer-chat 0.11.6 → 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,7 +31,8 @@ var defaults = {
31
31
  peerOptions: {},
32
32
  remotePeerId: []
33
33
  };
34
- var maxReconnectionAttempts = 2;
34
+ var iosRegex = /iPhone|iPad|iPod/i;
35
+ var mobileRegex = /Android|webOS|BlackBerry|IEMobile|Opera Mini/i;
35
36
 
36
37
  // src/lib/connection.ts
37
38
  function closeConnection(conn) {
@@ -41,6 +42,12 @@ function closeConnection(conn) {
41
42
 
42
43
  // src/lib/utils.ts
43
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
+ }
44
51
 
45
52
  // src/lib/react.ts
46
53
  function isSetStateFunction(v) {
@@ -182,7 +189,6 @@ function useChat({
182
189
  if (!text && !audio) return;
183
190
  let destroyed = false;
184
191
  let reconnecting = false;
185
- let reconnectAttempts = 0;
186
192
  let reconnectTimer;
187
193
  scheduleReconnectRef.current = () => {
188
194
  if (destroyed || reconnecting) return;
@@ -190,11 +196,8 @@ function useChat({
190
196
  reconnectTimer = setTimeout(() => {
191
197
  const peer = peerRef.current;
192
198
  if (peer) {
193
- reconnectAttempts++;
194
- if (reconnectAttempts >= maxReconnectionAttempts) {
195
- setPeerGeneration((prev) => prev + 1);
196
- reconnectAttempts = 0;
197
- } else peer.reconnect();
199
+ if (isMobile()) setPeerGeneration((prev) => prev + 1);
200
+ else peer.reconnect();
198
201
  }
199
202
  reconnecting = false;
200
203
  }, 1e3);
@@ -212,7 +215,6 @@ function useChat({
212
215
  peerRef.current = new Peer(completePeerId, __spreadValues({ config: defaultConfig }, peerOptions));
213
216
  setPeerEpoch((prev) => prev + 1);
214
217
  const peer = peerRef.current;
215
- peer.on("open", () => reconnectAttempts = 0);
216
218
  peer.on("connection", handleConnection);
217
219
  peer.on("call", handleCall);
218
220
  peer.on("disconnected", () => {
@@ -233,7 +235,6 @@ function useChat({
233
235
  var _a, _b;
234
236
  destroyed = true;
235
237
  reconnecting = false;
236
- reconnectAttempts = 0;
237
238
  clearTimeout(reconnectTimer);
238
239
  (_a = peerRef.current) == null ? void 0 : _a.removeAllListeners();
239
240
  (_b = peerRef.current) == null ? void 0 : _b.destroy();
@@ -1,4 +1,4 @@
1
- import { useChat } from './chunk-XJSK56RM.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-7M2EWH66.js';
2
- import './chunks/chunk-XJSK56RM.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-XJSK56RM.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-7M2EWH66.js';
2
- export { useChat } from './chunks/chunk-XJSK56RM.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.6",
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>",