react-peer-chat 0.1.8 → 0.1.10

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/icons.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
2
  export function BsFillMicFill(props) {
3
- return React.createElement("span", { ...props },
3
+ return React.createElement("span", Object.assign({}, props),
4
4
  React.createElement("svg", { fill: "currentColor", width: '16px', height: '16px' },
5
5
  React.createElement("path", { d: "M5 3a3 3 0 0 1 6 0v5a3 3 0 0 1-6 0V3z" }),
6
6
  React.createElement("path", { d: "M3.5 6.5A.5.5 0 0 1 4 7v1a4 4 0 0 0 8 0V7a.5.5 0 0 1 1 0v1a5 5 0 0 1-4.5 4.975V15h3a.5.5 0 0 1 0 1h-7a.5.5 0 0 1 0-1h3v-2.025A5 5 0 0 1 3 8V7a.5.5 0 0 1 .5-.5z" })));
7
7
  }
8
8
  export function BsFillMicMuteFill(props) {
9
- return React.createElement("span", { ...props },
9
+ return React.createElement("span", Object.assign({}, props),
10
10
  React.createElement("svg", { fill: "currentColor", width: '16px', height: '16px' },
11
11
  React.createElement("path", { d: "M13 8c0 .564-.094 1.107-.266 1.613l-.814-.814A4.02 4.02 0 0 0 12 8V7a.5.5 0 0 1 1 0v1zm-5 4c.818 0 1.578-.245 2.212-.667l.718.719a4.973 4.973 0 0 1-2.43.923V15h3a.5.5 0 0 1 0 1h-7a.5.5 0 0 1 0-1h3v-2.025A5 5 0 0 1 3 8V7a.5.5 0 0 1 1 0v1a4 4 0 0 0 4 4zm3-9v4.879L5.158 2.037A3.001 3.001 0 0 1 11 3z" }),
12
12
  React.createElement("path", { d: "M9.486 10.607 5 6.12V8a3 3 0 0 0 4.486 2.607zm-7.84-9.253 12 12 .708-.708-12-12-.708.708z" })));
package/build/index.js CHANGED
@@ -1,7 +1,17 @@
1
- import React, { useEffect, useRef } from 'react';
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import React, { useEffect, useRef, useState } from 'react';
2
11
  import useStorage from './useStorage';
3
12
  import { BsFillMicFill, BsFillMicMuteFill } from './icons';
4
13
  export default function Chat({ peerId, remotePeerId, peerOptions, onError = () => console.error("Can not access microphone!") }) {
14
+ const [peer, setPeer] = useState();
5
15
  const [audio, setAudio] = useStorage('rpc-audio', false, { local: true, save: true });
6
16
  const streamRef = useRef(null);
7
17
  const localStream = useRef();
@@ -9,8 +19,17 @@ export default function Chat({ peerId, remotePeerId, peerOptions, onError = () =
9
19
  useEffect(() => {
10
20
  if (!audio)
11
21
  return;
12
- const Peer = require('peerjs').default;
13
- const peer = new Peer(`rpc-${peerId}`, peerOptions);
22
+ (function loadPeer() {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const Peer = (yield import('peerjs')).default;
25
+ const peer = new Peer(`rpc-${peerId}`, peerOptions);
26
+ setPeer(peer);
27
+ });
28
+ })();
29
+ }, [audio]);
30
+ useEffect(() => {
31
+ if (!peer)
32
+ return;
14
33
  let call;
15
34
  peer.on('open', () => {
16
35
  const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
@@ -35,13 +54,14 @@ export default function Chat({ peerId, remotePeerId, peerOptions, onError = () =
35
54
  }, onError);
36
55
  });
37
56
  return () => {
38
- localStream.current?.getTracks().forEach(track => track.stop());
39
- call?.removeAllListeners();
40
- call?.close();
57
+ var _a;
58
+ (_a = localStream.current) === null || _a === void 0 ? void 0 : _a.getTracks().forEach(track => track.stop());
59
+ call === null || call === void 0 ? void 0 : call.removeAllListeners();
60
+ call === null || call === void 0 ? void 0 : call.close();
41
61
  peer.removeAllListeners();
42
62
  peer.destroy();
43
63
  };
44
- }, [audio]);
64
+ }, [peer]);
45
65
  return React.createElement("button", { onClick: () => setAudio(audio => !audio) }, audio ? React.createElement(React.Fragment, null,
46
66
  React.createElement("audio", { ref: streamRef, autoPlay: true, className: 'hidden' }),
47
67
  React.createElement(BsFillMicFill, { title: "Turn mic off" })) : React.createElement(BsFillMicMuteFill, { title: "Turn mic on" }));
@@ -10,7 +10,7 @@ const getStorage = (key, fallbackValue, local = false) => {
10
10
  throw new Error("Value doesn't exist");
11
11
  value = JSON.parse(value);
12
12
  }
13
- catch {
13
+ catch (_a) {
14
14
  if (fallbackValue !== undefined) {
15
15
  value = fallbackValue;
16
16
  setStorage(key, value, local);
@@ -23,7 +23,7 @@ const getStorage = (key, fallbackValue, local = false) => {
23
23
  return value;
24
24
  };
25
25
  export default function useStorage(key, initialValue, { local = false, save = false } = {}) {
26
- save ||= getStorage('mode') !== 'online';
26
+ save || (save = getStorage('mode') !== 'online');
27
27
  const [storedValue, setStoredValue] = useState(save ? getStorage(key, initialValue, local) : initialValue);
28
28
  const setValue = (value) => {
29
29
  setStoredValue((old) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "An easy to use react component for impleting peer-to-peer chatting.",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -32,7 +32,6 @@
32
32
  "react-dom": ">=16.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "^20.5.9",
36
35
  "@types/react": "^18.2.21"
37
36
  },
38
37
  "dependencies": {