react-peer-chat 0.3.2 → 0.3.4

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/build/index.d.ts CHANGED
@@ -26,7 +26,7 @@ type Props = {
26
26
  dialogOptions?: DialogOptions;
27
27
  onError?: () => void;
28
28
  children?: (childrenOptions: ChildrenOptions) => ReactNode;
29
- props: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
29
+ props?: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
30
30
  };
31
31
  export default function Chat({ name, peerId, remotePeerId, peerOptions, text, voice, dialogOptions, onError, children, props }: Props): React.JSX.Element;
32
32
  export declare const clearChat: () => void;
package/build/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
2
  import useStorage, { removeStorage } from './storage.js';
3
3
  import { BiSolidMessageDetail, BiSolidMessageX, BsFillMicFill, BsFillMicMuteFill, GrSend } from './icons.js';
4
- export default function Chat({ name, peerId, remotePeerId, peerOptions, text = true, voice = true, dialogOptions, onError = () => console.error("Can not access microphone!"), children, props }) {
4
+ export default function Chat({ name, peerId, remotePeerId, peerOptions, text = true, voice = true, dialogOptions, onError = () => alert("Microphone not accessible!"), children, props = {} }) {
5
5
  const [peer, setPeer] = useState();
6
6
  const [notification, setNotification] = useState(false);
7
7
  const [remotePeer, setRemotePeer] = useStorage('rpc-remote-peer', '', { save: true });
@@ -64,27 +64,32 @@ export default function Chat({ name, peerId, remotePeerId, peerOptions, text = t
64
64
  }
65
65
  if (audio) {
66
66
  const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
67
- getUserMedia({
68
- video: false,
69
- audio: {
70
- autoGainControl: false,
71
- noiseSuppression: true,
72
- echoCancellation: true
73
- }
74
- }, (stream) => {
75
- localStream.current = stream;
76
- if (remotePeerId) {
77
- call = peer.call(remotePeerId, stream);
78
- call.on('stream', handleRemoteStream);
79
- call.on('close', call.removeAllListeners);
80
- }
81
- peer.on('call', e => {
82
- call = e;
83
- call.answer(stream);
84
- call.on('stream', handleRemoteStream);
85
- call.on('close', call.removeAllListeners);
86
- });
87
- }, onError);
67
+ try {
68
+ getUserMedia({
69
+ video: false,
70
+ audio: {
71
+ autoGainControl: false,
72
+ noiseSuppression: true,
73
+ echoCancellation: true
74
+ }
75
+ }, (stream) => {
76
+ localStream.current = stream;
77
+ if (remotePeerId) {
78
+ call = peer.call(remotePeerId, stream);
79
+ call.on('stream', handleRemoteStream);
80
+ call.on('close', call.removeAllListeners);
81
+ }
82
+ peer.on('call', e => {
83
+ call = e;
84
+ call.answer(stream);
85
+ call.on('stream', handleRemoteStream);
86
+ call.on('close', call.removeAllListeners);
87
+ });
88
+ }, onError);
89
+ }
90
+ catch (_a) {
91
+ onError();
92
+ }
88
93
  }
89
94
  });
90
95
  peer.on('connection', handleConnection);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "An easy to use react component for impleting peer-to-peer chatting.",
5
5
  "main": "./build/index.js",
6
6
  "type": "module",