react-peer-chat 0.11.2 → 0.11.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.
@@ -1,4 +1,4 @@
1
- import { useChat } from './chunk-CIIM7EHX.js';
1
+ import { useChat } from './chunk-MVAZLLW2.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';
@@ -95,8 +95,9 @@ function useChat({
95
95
  }
96
96
  function handleConnection(conn) {
97
97
  const peerId2 = conn.peer;
98
- if (connRef.current[peerId2]) return conn.close();
99
98
  conn.on("open", () => {
99
+ var _a;
100
+ (_a = connRef.current[peerId2]) == null ? void 0 : _a.close();
100
101
  connRef.current[peerId2] = conn;
101
102
  conn.on("data", ({ type, message, messages: messages2, remotePeerName }) => {
102
103
  switch (type) {
@@ -113,17 +114,18 @@ function useChat({
113
114
  });
114
115
  conn.on("close", () => {
115
116
  conn.removeAllListeners();
116
- delete connRef.current[peerId2];
117
+ if (connRef.current[peerId2] === conn) delete connRef.current[peerId2];
117
118
  });
118
119
  }
119
120
  function handleCall(call) {
120
121
  const peerId2 = call.peer;
121
- if (callsRef.current[peerId2]) return call.close();
122
122
  if (!call.localStream) {
123
123
  if (!localStreamRef.current) return call.close();
124
124
  call.answer(localStreamRef.current);
125
125
  }
126
126
  call.on("stream", () => {
127
+ var _a;
128
+ (_a = callsRef.current[peerId2]) == null ? void 0 : _a.close();
127
129
  callsRef.current[peerId2] = call;
128
130
  if (!audioContextRef.current) audioContextRef.current = new AudioContext();
129
131
  if (audioContextRef.current.state === "suspended") audioContextRef.current.resume();
@@ -142,8 +144,10 @@ function useChat({
142
144
  });
143
145
  call.on("close", () => {
144
146
  call.removeAllListeners();
145
- removePeerAudio(peerId2);
146
- delete callsRef.current[peerId2];
147
+ if (callsRef.current[peerId2] === call) {
148
+ removePeerAudio(peerId2);
149
+ delete callsRef.current[peerId2];
150
+ }
147
151
  });
148
152
  }
149
153
  function receiveMessage(message) {
@@ -1,5 +1,5 @@
1
- export { Chat as default } from './chunks/chunk-B2RQAOIC.js';
2
- import './chunks/chunk-CIIM7EHX.js';
1
+ export { Chat as default } from './chunks/chunk-DBJS3VES.js';
2
+ import './chunks/chunk-MVAZLLW2.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-CIIM7EHX.js';
1
+ export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-MVAZLLW2.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-B2RQAOIC.js';
2
- export { useChat } from './chunks/chunk-CIIM7EHX.js';
1
+ export { Chat as default } from './chunks/chunk-DBJS3VES.js';
2
+ export { useChat } from './chunks/chunk-MVAZLLW2.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.2",
3
+ "version": "0.11.3",
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>",