react-peer-chat 0.1.5 → 0.1.7

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,23 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  import React from "react";
2
13
  export function BsFillMicFill(props) {
3
- return React.createElement("span", Object.assign({}, props),
14
+ return React.createElement("span", __assign({}, props),
4
15
  React.createElement("svg", { fill: "currentColor", width: '16px', height: '16px' },
5
16
  React.createElement("path", { d: "M5 3a3 3 0 0 1 6 0v5a3 3 0 0 1-6 0V3z" }),
6
17
  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
18
  }
8
19
  export function BsFillMicMuteFill(props) {
9
- return React.createElement("span", Object.assign({}, props),
20
+ return React.createElement("span", __assign({}, props),
10
21
  React.createElement("svg", { fill: "currentColor", width: '16px', height: '16px' },
11
22
  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
23
  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,19 +1,36 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
1
17
  import React, { useEffect, useRef } from 'react';
2
18
  import useStorage from './useStorage';
3
19
  import { BsFillMicFill, BsFillMicMuteFill } from './icons';
4
- export default function Chat({ peerId, remotePeerId, peerOptions, onError = () => console.error("Can not access microphone!") }) {
5
- const [audio, setAudio] = useStorage('rpc-audio', false, { local: true, save: true });
6
- const streamRef = useRef(null);
7
- const localStream = useRef();
8
- const handleRemoteStream = (remoteStream) => streamRef.current.srcObject = remoteStream;
9
- useEffect(() => {
20
+ export default function Chat(_a) {
21
+ var peerId = _a.peerId, remotePeerId = _a.remotePeerId, peerOptions = _a.peerOptions, _b = _a.onError, onError = _b === void 0 ? function () { return console.error("Can not access microphone!"); } : _b;
22
+ var _c = __read(useStorage('rpc-audio', false, { local: true, save: true }), 2), audio = _c[0], setAudio = _c[1];
23
+ var streamRef = useRef(null);
24
+ var localStream = useRef();
25
+ var handleRemoteStream = function (remoteStream) { return streamRef.current.srcObject = remoteStream; };
26
+ useEffect(function () {
10
27
  if (!audio)
11
28
  return;
12
- const Peer = require('peerjs').default;
13
- const peer = new Peer(`rpc-${peerId}`, peerOptions);
14
- let call;
15
- peer.on('open', () => {
16
- const getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
29
+ var Peer = require('peerjs').default;
30
+ var peer = new Peer("rpc-".concat(peerId), peerOptions);
31
+ var call;
32
+ peer.on('open', function () {
33
+ var getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
17
34
  getUserMedia({
18
35
  video: false,
19
36
  audio: {
@@ -21,12 +38,12 @@ export default function Chat({ peerId, remotePeerId, peerOptions, onError = () =
21
38
  noiseSuppression: true,
22
39
  echoCancellation: true
23
40
  }
24
- }, (stream) => {
41
+ }, function (stream) {
25
42
  localStream.current = stream;
26
- call = peer.call(`rpc-${remotePeerId}`, stream);
43
+ call = peer.call("rpc-".concat(remotePeerId), stream);
27
44
  call.on('stream', handleRemoteStream);
28
45
  call.on('close', call.removeAllListeners);
29
- peer.on('call', (e) => {
46
+ peer.on('call', function (e) {
30
47
  call = e;
31
48
  call.answer(stream);
32
49
  call.on('stream', handleRemoteStream);
@@ -34,16 +51,16 @@ export default function Chat({ peerId, remotePeerId, peerOptions, onError = () =
34
51
  });
35
52
  }, onError);
36
53
  });
37
- return () => {
54
+ return function () {
38
55
  var _a;
39
- (_a = localStream.current) === null || _a === void 0 ? void 0 : _a.getTracks().forEach(track => track.stop());
56
+ (_a = localStream.current) === null || _a === void 0 ? void 0 : _a.getTracks().forEach(function (track) { return track.stop(); });
40
57
  call === null || call === void 0 ? void 0 : call.removeAllListeners();
41
58
  call === null || call === void 0 ? void 0 : call.close();
42
59
  peer.removeAllListeners();
43
60
  peer.destroy();
44
61
  };
45
62
  }, [audio]);
46
- return React.createElement("button", { onClick: () => setAudio(audio => !audio) }, audio ? React.createElement(React.Fragment, null,
63
+ return React.createElement("button", { onClick: function () { return setAudio(function (audio) { return !audio; }); } }, audio ? React.createElement(React.Fragment, null,
47
64
  React.createElement("audio", { ref: streamRef, autoPlay: true, className: 'hidden' }),
48
65
  React.createElement(BsFillMicFill, { title: "Turn mic off" })) : React.createElement(BsFillMicMuteFill, { title: "Turn mic on" }));
49
66
  }
@@ -1,10 +1,33 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
1
17
  import { useState } from "react";
2
- const setStorage = (key, value, local = false) => (local ? localStorage : sessionStorage).setItem(key, JSON.stringify(value));
3
- const removeStorage = (key, local = false) => (local ? localStorage : sessionStorage).removeItem(key);
4
- const getStorage = (key, fallbackValue, local = false) => {
18
+ var setStorage = function (key, value, local) {
19
+ if (local === void 0) { local = false; }
20
+ return (local ? localStorage : sessionStorage).setItem(key, JSON.stringify(value));
21
+ };
22
+ var removeStorage = function (key, local) {
23
+ if (local === void 0) { local = false; }
24
+ return (local ? localStorage : sessionStorage).removeItem(key);
25
+ };
26
+ var getStorage = function (key, fallbackValue, local) {
27
+ if (local === void 0) { local = false; }
5
28
  if (typeof window === "undefined")
6
29
  return fallbackValue;
7
- let value = (local ? localStorage : sessionStorage).getItem(key);
30
+ var value = (local ? localStorage : sessionStorage).getItem(key);
8
31
  try {
9
32
  if (!value)
10
33
  throw new Error("Value doesn't exist");
@@ -22,12 +45,13 @@ const getStorage = (key, fallbackValue, local = false) => {
22
45
  }
23
46
  return value;
24
47
  };
25
- export default function useStorage(key, initialValue, { local = false, save = false } = {}) {
48
+ export default function useStorage(key, initialValue, _a) {
49
+ var _b = _a === void 0 ? {} : _a, _c = _b.local, local = _c === void 0 ? false : _c, _d = _b.save, save = _d === void 0 ? false : _d;
26
50
  save || (save = getStorage('mode') !== 'online');
27
- const [storedValue, setStoredValue] = useState(save ? getStorage(key, initialValue, local) : initialValue);
28
- const setValue = (value) => {
29
- setStoredValue((old) => {
30
- const updatedValue = typeof value === 'function' ? value(old) : value;
51
+ var _e = __read(useState(save ? getStorage(key, initialValue, local) : initialValue), 2), storedValue = _e[0], setStoredValue = _e[1];
52
+ var setValue = function (value) {
53
+ setStoredValue(function (old) {
54
+ var updatedValue = typeof value === 'function' ? value(old) : value;
31
55
  if (save)
32
56
  setStorage(key, updatedValue, local);
33
57
  return updatedValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "An easy to use react component for impleting peer-to-peer chatting.",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {