react-peer-chat 0.10.0 → 0.11.1
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.
- package/README.md +30 -19
- package/dist/chunks/{chunk-L3CFU5IB.js → chunk-B2B7BBRE.js} +85 -58
- package/dist/chunks/{chunk-LNEKYYG7.js → chunk-FZ4QVG4I.js} +21 -1
- package/dist/chunks/{chunk-JJPIWKLG.js → chunk-QIPTWGEX.js} +1 -1
- package/dist/chunks/{chunk-OB5LLPQI.js → chunk-YQPRV5JQ.js} +3 -3
- package/dist/components.js +4 -4
- package/dist/hooks.d.ts +1 -1
- package/dist/hooks.js +2 -2
- package/dist/icons.js +2 -2
- package/dist/index.js +4 -4
- package/dist/lib/storage.js +1 -1
- package/dist/types.d.ts +7 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ A simple-to-use React component for implementing peer-to-peer chatting, powered
|
|
|
11
11
|
- Option to clear chat on command
|
|
12
12
|
- Supports audio/voice chat with automatic mixing for multiple peers
|
|
13
13
|
- Multiple peer connections. See [multi-peer usage](#multi-peer-usage)
|
|
14
|
+
- Automatic reconnection handling for network interruptions
|
|
14
15
|
- Fully customizable. See [usage with FaC](#full-customization)
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
@@ -100,8 +101,9 @@ export default function App() {
|
|
|
100
101
|
style: { padding: "4px" },
|
|
101
102
|
}}
|
|
102
103
|
props={{ title: "React Peer Chat Component" }}
|
|
103
|
-
onError={() => console.error("
|
|
104
|
-
|
|
104
|
+
onError={(error) => console.error("Fatal error:", error)}
|
|
105
|
+
onPeerError={(error) => console.error("Peer error:", error.type, error)}
|
|
106
|
+
onNetworkError={(error) => console.log("Reconnecting...")}
|
|
105
107
|
/>
|
|
106
108
|
);
|
|
107
109
|
}
|
|
@@ -120,8 +122,8 @@ export default function App() {
|
|
|
120
122
|
name='John Doe'
|
|
121
123
|
peerId='my-unique-id'
|
|
122
124
|
remotePeerId='remote-unique-id'
|
|
123
|
-
onError={() => console.error('
|
|
124
|
-
|
|
125
|
+
onError={(error) => console.error('Fatal error:', error)}
|
|
126
|
+
onPeerError={(error) => console.error('Peer error:', error.type, error)}
|
|
125
127
|
>
|
|
126
128
|
{({ remotePeers, messages, sendMessage, audio, setAudio }) => (
|
|
127
129
|
<YourCustomComponent>
|
|
@@ -293,19 +295,20 @@ export default function App() {
|
|
|
293
295
|
|
|
294
296
|
Here is the full API for the `useChat` hook, these options can be passed as parameters to the hook:
|
|
295
297
|
|
|
296
|
-
| Parameter | Type | Required | Default
|
|
297
|
-
| ------------------- | --------------------------------------------- | -------- |
|
|
298
|
-
| `name` | `string` | No | Anonymous User
|
|
299
|
-
| `peerId` | `string` | Yes | -
|
|
300
|
-
| `remotePeerId` | `string \| string[]` | No | -
|
|
301
|
-
| `text` | `boolean` | No | `true`
|
|
302
|
-
| `recoverChat` | `boolean` | No | `false`
|
|
303
|
-
| `audio` | `boolean` | No | `true`
|
|
304
|
-
| `peerOptions` | [`PeerOptions`](#peeroptions) | No | -
|
|
305
|
-
| `onError` | [`ErrorHandler`](#errorhandler) | No | `
|
|
306
|
-
| `
|
|
307
|
-
| `
|
|
308
|
-
| `
|
|
298
|
+
| Parameter | Type | Required | Default | Description |
|
|
299
|
+
| ------------------- | --------------------------------------------- | -------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
300
|
+
| `name` | `string` | No | Anonymous User | Name of the peer which will be shown to the remote peer. |
|
|
301
|
+
| `peerId` | `string` | Yes | - | It is the unique id that is alloted to a peer. It uniquely identifies a peer from other peers. |
|
|
302
|
+
| `remotePeerId` | `string \| string[]` | No | - | Unique id(s) of remote peer(s) to connect to. Read at mount and when `peerId` changes; changes to this prop alone won't create new connections. |
|
|
303
|
+
| `text` | `boolean` | No | `true` | Text chat will be enabled if this property is set to true. |
|
|
304
|
+
| `recoverChat` | `boolean` | No | `false` | Old chats will be recovered upon reconnecting with the same peer(s). |
|
|
305
|
+
| `audio` | `boolean` | No | `true` | Voice chat will be enabled if this property is set to true. Audio from multiple peers is automatically mixed. |
|
|
306
|
+
| `peerOptions` | [`PeerOptions`](#peeroptions) | No | - | Options to customize peerjs Peer instance. |
|
|
307
|
+
| `onError` | [`ErrorHandler`](#errorhandler) | No | `console.error` | Function to be executed for fatal errors (browser not supported, microphone not accessible). |
|
|
308
|
+
| `onPeerError` | [`PeerErrorHandler`](#peererrorhandler) | No | `console.error` | Function to be executed for all peer runtime errors. The library automatically handles reconnection for network errors. |
|
|
309
|
+
| `onNetworkError` | [`PeerErrorHandler`](#peererrorhandler) | No | - | Function to be executed for network/server errors (which trigger automatic reconnection). Useful for showing "reconnecting..." UI. |
|
|
310
|
+
| `onMessageSent` | [`MessageEventHandler`](#messageeventhandler) | No | - | Function to be executed when a text message is sent to other peers. |
|
|
311
|
+
| `onMessageReceived` | [`MessageEventHandler`](#messageeventhandler) | No | - | Function to be executed when a text message is received from other peers. |
|
|
309
312
|
|
|
310
313
|
### Chat Component
|
|
311
314
|
|
|
@@ -363,7 +366,15 @@ type DivProps = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement
|
|
|
363
366
|
### ErrorHandler
|
|
364
367
|
|
|
365
368
|
```typescript
|
|
366
|
-
type ErrorHandler = () => void;
|
|
369
|
+
type ErrorHandler = (error: Error) => void;
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### PeerErrorHandler
|
|
373
|
+
|
|
374
|
+
```typescript
|
|
375
|
+
import type { PeerError, PeerErrorType } from "peerjs";
|
|
376
|
+
|
|
377
|
+
export type PeerErrorHandler = ErrorHandler<PeerError<`${PeerErrorType}`>>;
|
|
367
378
|
```
|
|
368
379
|
|
|
369
380
|
### MessageEventHandler
|
|
@@ -384,4 +395,4 @@ import type { PeerOptions } from "peerjs";
|
|
|
384
395
|
|
|
385
396
|
## License
|
|
386
397
|
|
|
387
|
-
This project is licensed under the [MIT License](LICENSE)
|
|
398
|
+
This project is licensed under the [MIT License](LICENSE)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getStorage, setStorage } from './chunk-ZYFPSCFE.js';
|
|
2
|
-
import { __spreadValues, __spreadProps } from './chunk-
|
|
2
|
+
import { __spreadValues, __async, __spreadProps } from './chunk-FZ4QVG4I.js';
|
|
3
3
|
import { useState, useRef, useMemo, useEffect } from 'react';
|
|
4
4
|
|
|
5
5
|
// src/constants.ts
|
|
@@ -56,8 +56,9 @@ function useChat({
|
|
|
56
56
|
text = true,
|
|
57
57
|
recoverChat = false,
|
|
58
58
|
audio: allowed = true,
|
|
59
|
-
onError =
|
|
60
|
-
|
|
59
|
+
onError = console.error,
|
|
60
|
+
onPeerError = console.error,
|
|
61
|
+
onNetworkError,
|
|
61
62
|
onMessageSent,
|
|
62
63
|
onMessageReceived
|
|
63
64
|
}) {
|
|
@@ -74,8 +75,49 @@ function useChat({
|
|
|
74
75
|
const remotePeerIds = Array.isArray(remotePeerId) ? remotePeerId : [remotePeerId];
|
|
75
76
|
return { completePeerId: addPrefix(peerId), completeRemotePeerIds: remotePeerIds.map(addPrefix) };
|
|
76
77
|
}, [peerId]);
|
|
78
|
+
function resetConnections(type = "all") {
|
|
79
|
+
switch (type) {
|
|
80
|
+
case "all":
|
|
81
|
+
resetConnections("data");
|
|
82
|
+
resetConnections("call");
|
|
83
|
+
break;
|
|
84
|
+
case "data":
|
|
85
|
+
Object.values(connRef.current).forEach(closeConnection);
|
|
86
|
+
connRef.current = {};
|
|
87
|
+
break;
|
|
88
|
+
case "call":
|
|
89
|
+
Object.values(callsRef.current).forEach(closeConnection);
|
|
90
|
+
Object.keys(sourceNodesRef.current).forEach(removePeerAudio);
|
|
91
|
+
callsRef.current = {};
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
function handleConnection(conn) {
|
|
96
|
+
const peerId2 = conn.peer;
|
|
97
|
+
if (connRef.current[peerId2]) return conn.close();
|
|
98
|
+
connRef.current[peerId2] = conn;
|
|
99
|
+
conn.on("open", () => {
|
|
100
|
+
conn.on("data", ({ type, message, messages: messages2, remotePeerName }) => {
|
|
101
|
+
switch (type) {
|
|
102
|
+
case "init":
|
|
103
|
+
setRemotePeers((prev) => __spreadProps(__spreadValues({}, prev), { [peerId2]: remotePeerName }));
|
|
104
|
+
if (recoverChat) setMessages((old) => messages2.length > old.length ? messages2 : old);
|
|
105
|
+
break;
|
|
106
|
+
case "message":
|
|
107
|
+
receiveMessage(message);
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
conn.send({ type: "init", remotePeerName: name, messages });
|
|
112
|
+
});
|
|
113
|
+
conn.on("close", () => {
|
|
114
|
+
conn.removeAllListeners();
|
|
115
|
+
delete connRef.current[peerId2];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
77
118
|
function handleCall(call) {
|
|
78
119
|
const peerId2 = call.peer;
|
|
120
|
+
if (callsRef.current[peerId2]) return call.close();
|
|
79
121
|
call.on("stream", () => {
|
|
80
122
|
callsRef.current[peerId2] = call;
|
|
81
123
|
if (!audioContextRef.current) audioContextRef.current = new AudioContext();
|
|
@@ -99,31 +141,14 @@ function useChat({
|
|
|
99
141
|
delete callsRef.current[peerId2];
|
|
100
142
|
});
|
|
101
143
|
}
|
|
102
|
-
function handleConnection(conn) {
|
|
103
|
-
connRef.current[conn.peer] = conn;
|
|
104
|
-
conn.on("open", () => {
|
|
105
|
-
conn.on("data", ({ message, messages: messages2, remotePeerName, type }) => {
|
|
106
|
-
if (type === "message") receiveMessage(message);
|
|
107
|
-
else if (type === "init") {
|
|
108
|
-
setRemotePeers((prev) => __spreadProps(__spreadValues({}, prev), { [conn.peer]: remotePeerName }));
|
|
109
|
-
if (recoverChat) setMessages((old) => messages2.length > old.length ? messages2 : old);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
conn.send({ type: "init", remotePeerName: name, messages });
|
|
113
|
-
});
|
|
114
|
-
conn.on("close", conn.removeAllListeners);
|
|
115
|
-
}
|
|
116
|
-
function handleError() {
|
|
117
|
-
setAudio(false);
|
|
118
|
-
onMicError();
|
|
119
|
-
}
|
|
120
144
|
function receiveMessage(message) {
|
|
121
145
|
addMessage(message);
|
|
122
146
|
onMessageReceived == null ? void 0 : onMessageReceived(message);
|
|
123
147
|
}
|
|
124
148
|
function removePeerAudio(peerId2) {
|
|
125
|
-
|
|
126
|
-
|
|
149
|
+
const source = sourceNodesRef.current[peerId2];
|
|
150
|
+
if (!source) return;
|
|
151
|
+
source.disconnect();
|
|
127
152
|
delete sourceNodesRef.current[peerId2];
|
|
128
153
|
}
|
|
129
154
|
function sendMessage(message) {
|
|
@@ -134,6 +159,7 @@ function useChat({
|
|
|
134
159
|
}
|
|
135
160
|
useEffect(() => {
|
|
136
161
|
if (!text && !audio) return;
|
|
162
|
+
let destroyed = false;
|
|
137
163
|
import('peerjs').then(
|
|
138
164
|
({
|
|
139
165
|
Peer,
|
|
@@ -141,15 +167,29 @@ function useChat({
|
|
|
141
167
|
supports: { audioVideo, data }
|
|
142
168
|
}
|
|
143
169
|
}) => {
|
|
144
|
-
if (!data || !audioVideo) return onError();
|
|
170
|
+
if (!data || !audioVideo) return onError(new Error("Browser not supported! Try some other browser."));
|
|
145
171
|
const peer2 = new Peer(completePeerId, __spreadValues({ config: defaultConfig }, peerOptions));
|
|
146
172
|
peer2.on("connection", handleConnection);
|
|
147
|
-
|
|
173
|
+
peer2.on("call", handleCall);
|
|
174
|
+
peer2.on("disconnected", () => {
|
|
175
|
+
resetConnections();
|
|
176
|
+
peer2.reconnect();
|
|
177
|
+
});
|
|
178
|
+
peer2.on("error", (error) => {
|
|
179
|
+
if (error.type === "network" || error.type === "server-error") {
|
|
180
|
+
resetConnections();
|
|
181
|
+
setTimeout(() => peer2.reconnect(), 1e3);
|
|
182
|
+
onNetworkError == null ? void 0 : onNetworkError(error);
|
|
183
|
+
}
|
|
184
|
+
onPeerError(error);
|
|
185
|
+
});
|
|
186
|
+
if (destroyed) peer2.destroy();
|
|
187
|
+
else setPeer(peer2);
|
|
148
188
|
}
|
|
149
189
|
);
|
|
150
190
|
return () => {
|
|
191
|
+
destroyed = true;
|
|
151
192
|
setPeer((prev) => {
|
|
152
|
-
prev == null ? void 0 : prev.removeAllListeners();
|
|
153
193
|
prev == null ? void 0 : prev.destroy();
|
|
154
194
|
return void 0;
|
|
155
195
|
});
|
|
@@ -157,45 +197,35 @@ function useChat({
|
|
|
157
197
|
}, [completePeerId]);
|
|
158
198
|
useEffect(() => {
|
|
159
199
|
if (!text || !peer) return;
|
|
160
|
-
const
|
|
161
|
-
if (peer.open)
|
|
162
|
-
|
|
200
|
+
const connectData = () => completeRemotePeerIds.forEach((id) => handleConnection(peer.connect(id)));
|
|
201
|
+
if (peer.open) connectData();
|
|
202
|
+
peer.on("open", connectData);
|
|
163
203
|
return () => {
|
|
164
|
-
|
|
165
|
-
|
|
204
|
+
peer.off("open", connectData);
|
|
205
|
+
resetConnections("data");
|
|
166
206
|
};
|
|
167
207
|
}, [text, peer]);
|
|
168
208
|
useEffect(() => {
|
|
169
209
|
if (!audio || !peer) return;
|
|
170
210
|
let localStream;
|
|
171
|
-
const setupAudio = () =>
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
211
|
+
const setupAudio = () => __async(null, null, function* () {
|
|
212
|
+
try {
|
|
213
|
+
localStream = yield navigator.mediaDevices.getUserMedia({ video: false, audio: { autoGainControl: true, noiseSuppression: true, echoCancellation: true } });
|
|
214
|
+
completeRemotePeerIds.forEach((id) => {
|
|
215
|
+
if (!callsRef.current[id]) handleCall(peer.call(id, localStream));
|
|
216
|
+
});
|
|
217
|
+
} catch (e) {
|
|
218
|
+
setAudio(false);
|
|
219
|
+
onError(new Error("Microphone not accessible"));
|
|
177
220
|
}
|
|
178
|
-
})
|
|
179
|
-
localStream = stream;
|
|
180
|
-
completeRemotePeerIds.forEach((id) => {
|
|
181
|
-
if (callsRef.current[id]) return;
|
|
182
|
-
const call = peer.call(id, stream);
|
|
183
|
-
handleCall(call);
|
|
184
|
-
});
|
|
185
|
-
peer.on("call", (call) => {
|
|
186
|
-
if (callsRef.current[call.peer]) return call.close();
|
|
187
|
-
call.answer(stream);
|
|
188
|
-
handleCall(call);
|
|
189
|
-
});
|
|
190
|
-
}).catch(handleError);
|
|
221
|
+
});
|
|
191
222
|
if (peer.open) setupAudio();
|
|
192
|
-
|
|
223
|
+
peer.on("open", setupAudio);
|
|
193
224
|
return () => {
|
|
194
225
|
var _a;
|
|
226
|
+
peer.off("open", setupAudio);
|
|
195
227
|
localStream == null ? void 0 : localStream.getTracks().forEach((track) => track.stop());
|
|
196
|
-
|
|
197
|
-
callsRef.current = {};
|
|
198
|
-
Object.keys(sourceNodesRef.current).forEach(removePeerAudio);
|
|
228
|
+
resetConnections("call");
|
|
199
229
|
(_a = audioContextRef.current) == null ? void 0 : _a.close();
|
|
200
230
|
audioContextRef.current = null;
|
|
201
231
|
mixerRef.current = null;
|
|
@@ -209,10 +239,7 @@ function useMessages() {
|
|
|
209
239
|
return [messages, setMessages, addMessage];
|
|
210
240
|
}
|
|
211
241
|
function useStorage(key, initialValue, local = false) {
|
|
212
|
-
const [storedValue, setStoredValue] = useState(() =>
|
|
213
|
-
if (typeof window === "undefined") return initialValue;
|
|
214
|
-
return getStorage(key, initialValue, local);
|
|
215
|
-
});
|
|
242
|
+
const [storedValue, setStoredValue] = useState(() => typeof window === "undefined" ? initialValue : getStorage(key, initialValue, local));
|
|
216
243
|
const setValue = (value) => {
|
|
217
244
|
setStoredValue((prev) => {
|
|
218
245
|
const next = isSetStateFunction(value) ? value(prev) : value;
|
|
@@ -29,5 +29,25 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
32
52
|
|
|
33
|
-
export { __objRest, __spreadProps, __spreadValues };
|
|
53
|
+
export { __async, __objRest, __spreadProps, __spreadValues };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useChat } from './chunk-
|
|
2
|
-
import { BiSolidMessageX, BiSolidMessageDetail, GrSend, BsFillMicFill, BsFillMicMuteFill } from './chunk-
|
|
3
|
-
import { __objRest, __spreadValues } from './chunk-
|
|
1
|
+
import { useChat } from './chunk-B2B7BBRE.js';
|
|
2
|
+
import { BiSolidMessageX, BiSolidMessageDetail, GrSend, BsFillMicFill, BsFillMicMuteFill } from './chunk-QIPTWGEX.js';
|
|
3
|
+
import { __objRest, __spreadValues } from './chunk-FZ4QVG4I.js';
|
|
4
4
|
import React, { useRef, useState, useEffect } from 'react';
|
|
5
5
|
|
|
6
6
|
// src/styles.css
|
package/dist/components.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Chat as default } from './chunks/chunk-
|
|
2
|
-
import './chunks/chunk-
|
|
3
|
-
import './chunks/chunk-
|
|
1
|
+
export { Chat as default } from './chunks/chunk-YQPRV5JQ.js';
|
|
2
|
+
import './chunks/chunk-B2B7BBRE.js';
|
|
3
|
+
import './chunks/chunk-QIPTWGEX.js';
|
|
4
4
|
import './chunks/chunk-ZYFPSCFE.js';
|
|
5
|
-
import './chunks/chunk-
|
|
5
|
+
import './chunks/chunk-FZ4QVG4I.js';
|
package/dist/hooks.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { SetStateAction } from 'react';
|
|
|
2
2
|
import { UseChatProps, UseChatReturn, Message } from './types.js';
|
|
3
3
|
import 'peerjs';
|
|
4
4
|
|
|
5
|
-
declare function useChat({ peerId, name, remotePeerId, peerOptions, text, recoverChat, audio: allowed, onError,
|
|
5
|
+
declare function useChat({ peerId, name, remotePeerId, peerOptions, text, recoverChat, audio: allowed, onError, onPeerError, onNetworkError, onMessageSent, onMessageReceived, }: UseChatProps): UseChatReturn;
|
|
6
6
|
declare function useMessages(): readonly [Message[], (value: SetStateAction<Message[]>) => void, (message: Message) => void];
|
|
7
7
|
declare function useStorage<T>(key: string, initialValue: T, local?: boolean): readonly [T, (value: SetStateAction<T>) => void];
|
|
8
8
|
declare function useStorage<T>(key: string, initialValue?: T, local?: boolean): readonly [T | undefined, (value: SetStateAction<T | undefined>) => void];
|
package/dist/hooks.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-
|
|
1
|
+
export { useAudio, useChat, useMessages, useStorage } from './chunks/chunk-B2B7BBRE.js';
|
|
2
2
|
import './chunks/chunk-ZYFPSCFE.js';
|
|
3
|
-
import './chunks/chunk-
|
|
3
|
+
import './chunks/chunk-FZ4QVG4I.js';
|
package/dist/icons.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BiSolidMessageDetail, BiSolidMessageX, BsFillMicFill, BsFillMicMuteFill, GrSend } from './chunks/chunk-
|
|
2
|
-
import './chunks/chunk-
|
|
1
|
+
export { BiSolidMessageDetail, BiSolidMessageX, BsFillMicFill, BsFillMicMuteFill, GrSend } from './chunks/chunk-QIPTWGEX.js';
|
|
2
|
+
import './chunks/chunk-FZ4QVG4I.js';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { Chat as default } from './chunks/chunk-
|
|
2
|
-
export { useChat } from './chunks/chunk-
|
|
3
|
-
import './chunks/chunk-
|
|
1
|
+
export { Chat as default } from './chunks/chunk-YQPRV5JQ.js';
|
|
2
|
+
export { useChat } from './chunks/chunk-B2B7BBRE.js';
|
|
3
|
+
import './chunks/chunk-QIPTWGEX.js';
|
|
4
4
|
export { clearChat } from './chunks/chunk-ZYFPSCFE.js';
|
|
5
|
-
import './chunks/chunk-
|
|
5
|
+
import './chunks/chunk-FZ4QVG4I.js';
|
package/dist/lib/storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { clearChat, getStorage, removeStorage, setStorage } from '../chunks/chunk-ZYFPSCFE.js';
|
|
2
|
-
import '../chunks/chunk-
|
|
2
|
+
import '../chunks/chunk-FZ4QVG4I.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { PeerOptions, DataConnection, MediaConnection } from 'peerjs';
|
|
1
|
+
import { PeerOptions, PeerError, PeerErrorType, DataConnection, MediaConnection } from 'peerjs';
|
|
2
2
|
export { PeerOptions } from 'peerjs';
|
|
3
3
|
import { CSSProperties, DetailedHTMLProps, HTMLAttributes, SetStateAction, ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
type Connection = DataConnection | MediaConnection;
|
|
6
|
-
type ErrorHandler = () => void;
|
|
6
|
+
type ErrorHandler<E = Error> = (error: E) => void;
|
|
7
7
|
type InputMessage = {
|
|
8
8
|
id: string;
|
|
9
9
|
text: string;
|
|
@@ -12,8 +12,10 @@ type Message = InputMessage & {
|
|
|
12
12
|
name: string;
|
|
13
13
|
};
|
|
14
14
|
type MessageEventHandler = (message: Message) => void;
|
|
15
|
+
type PeerErrorHandler = ErrorHandler<PeerError<`${PeerErrorType}`>>;
|
|
15
16
|
|
|
16
17
|
type RemotePeerId = string | string[];
|
|
18
|
+
type ResetConnectionType = "all" | "data" | "call";
|
|
17
19
|
type UseChatProps = {
|
|
18
20
|
peerId: string;
|
|
19
21
|
name?: string;
|
|
@@ -23,7 +25,8 @@ type UseChatProps = {
|
|
|
23
25
|
audio?: boolean;
|
|
24
26
|
peerOptions?: PeerOptions;
|
|
25
27
|
onError?: ErrorHandler;
|
|
26
|
-
|
|
28
|
+
onPeerError?: PeerErrorHandler;
|
|
29
|
+
onNetworkError?: PeerErrorHandler;
|
|
27
30
|
onMessageSent?: MessageEventHandler;
|
|
28
31
|
onMessageReceived?: MessageEventHandler;
|
|
29
32
|
};
|
|
@@ -52,4 +55,4 @@ type DialogPosition = "left" | "center" | "right";
|
|
|
52
55
|
type DivProps = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
53
56
|
type RemotePeers = Record<string, string>;
|
|
54
57
|
|
|
55
|
-
export type { ChatProps, Children, ChildrenOptions, Connection, DialogOptions, DialogPosition, DivProps, ErrorHandler, IconProps, InputMessage, Message, MessageEventHandler, RemotePeerId, RemotePeers, UseChatProps, UseChatReturn };
|
|
58
|
+
export type { ChatProps, Children, ChildrenOptions, Connection, DialogOptions, DialogPosition, DivProps, ErrorHandler, IconProps, InputMessage, Message, MessageEventHandler, PeerErrorHandler, RemotePeerId, RemotePeers, ResetConnectionType, UseChatProps, UseChatReturn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-peer-chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.1",
|
|
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>",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@release-it/conventional-changelog": "^10.0.4",
|
|
39
|
-
"@types/react": "^19.2.
|
|
39
|
+
"@types/react": "^19.2.8",
|
|
40
40
|
"prettier-package-json": "^2.8.0",
|
|
41
|
-
"release-it": "^19.2.
|
|
41
|
+
"release-it": "^19.2.3",
|
|
42
42
|
"tsup": "^8.5.1",
|
|
43
43
|
"typescript": "^5.9.3"
|
|
44
44
|
},
|