react-peer-chat 0.11.1 → 0.11.2
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-CIIM7EHX.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';
|
|
@@ -66,6 +66,7 @@ function useChat({
|
|
|
66
66
|
const [audio, setAudio] = useAudio(allowed);
|
|
67
67
|
const connRef = useRef({});
|
|
68
68
|
const callsRef = useRef({});
|
|
69
|
+
const localStreamRef = useRef(null);
|
|
69
70
|
const audioContextRef = useRef(null);
|
|
70
71
|
const mixerRef = useRef(null);
|
|
71
72
|
const sourceNodesRef = useRef({});
|
|
@@ -95,8 +96,8 @@ function useChat({
|
|
|
95
96
|
function handleConnection(conn) {
|
|
96
97
|
const peerId2 = conn.peer;
|
|
97
98
|
if (connRef.current[peerId2]) return conn.close();
|
|
98
|
-
connRef.current[peerId2] = conn;
|
|
99
99
|
conn.on("open", () => {
|
|
100
|
+
connRef.current[peerId2] = conn;
|
|
100
101
|
conn.on("data", ({ type, message, messages: messages2, remotePeerName }) => {
|
|
101
102
|
switch (type) {
|
|
102
103
|
case "init":
|
|
@@ -118,6 +119,10 @@ function useChat({
|
|
|
118
119
|
function handleCall(call) {
|
|
119
120
|
const peerId2 = call.peer;
|
|
120
121
|
if (callsRef.current[peerId2]) return call.close();
|
|
122
|
+
if (!call.localStream) {
|
|
123
|
+
if (!localStreamRef.current) return call.close();
|
|
124
|
+
call.answer(localStreamRef.current);
|
|
125
|
+
}
|
|
121
126
|
call.on("stream", () => {
|
|
122
127
|
callsRef.current[peerId2] = call;
|
|
123
128
|
if (!audioContextRef.current) audioContextRef.current = new AudioContext();
|
|
@@ -207,13 +212,10 @@ function useChat({
|
|
|
207
212
|
}, [text, peer]);
|
|
208
213
|
useEffect(() => {
|
|
209
214
|
if (!audio || !peer) return;
|
|
210
|
-
let localStream;
|
|
211
215
|
const setupAudio = () => __async(null, null, function* () {
|
|
212
216
|
try {
|
|
213
|
-
|
|
214
|
-
completeRemotePeerIds.forEach((id) =>
|
|
215
|
-
if (!callsRef.current[id]) handleCall(peer.call(id, localStream));
|
|
216
|
-
});
|
|
217
|
+
localStreamRef.current = yield navigator.mediaDevices.getUserMedia({ video: false, audio: { autoGainControl: true, noiseSuppression: true, echoCancellation: true } });
|
|
218
|
+
completeRemotePeerIds.forEach((id) => localStreamRef.current && handleCall(peer.call(id, localStreamRef.current)));
|
|
217
219
|
} catch (e) {
|
|
218
220
|
setAudio(false);
|
|
219
221
|
onError(new Error("Microphone not accessible"));
|
|
@@ -222,11 +224,12 @@ function useChat({
|
|
|
222
224
|
if (peer.open) setupAudio();
|
|
223
225
|
peer.on("open", setupAudio);
|
|
224
226
|
return () => {
|
|
225
|
-
var _a;
|
|
227
|
+
var _a, _b;
|
|
226
228
|
peer.off("open", setupAudio);
|
|
227
|
-
|
|
229
|
+
(_a = localStreamRef.current) == null ? void 0 : _a.getTracks().forEach((track) => track.stop());
|
|
228
230
|
resetConnections("call");
|
|
229
|
-
(
|
|
231
|
+
(_b = audioContextRef.current) == null ? void 0 : _b.close();
|
|
232
|
+
localStreamRef.current = null;
|
|
230
233
|
audioContextRef.current = null;
|
|
231
234
|
mixerRef.current = null;
|
|
232
235
|
};
|
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-B2RQAOIC.js';
|
|
2
|
+
import './chunks/chunk-CIIM7EHX.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-B2RQAOIC.js';
|
|
2
|
+
export { useChat } from './chunks/chunk-CIIM7EHX.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