react-peer-chat 0.2.0 → 0.2.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.
package/build/icons.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import React from "react";
2
- import './icons.css';
3
2
  export declare function BiSolidMessageDetail(props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>): React.JSX.Element;
4
3
  export declare function BiSolidMessageX(props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>): React.JSX.Element;
5
4
  export declare function GrSend(props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>): React.JSX.Element;
package/build/icons.js CHANGED
@@ -1,39 +1,28 @@
1
1
  import React from "react";
2
- import './icons.css';
3
2
  export function BiSolidMessageDetail(props) {
4
- return <span {...props}>
5
- <svg fill="currentColor" width='1.5rem' height='1.5rem' className='scale-down'>
6
- <path d="M20 2H4c-1.103 0-2 .894-2 1.992v12.016C2 17.106 2.897 18 4 18h3v4l6.351-4H20c1.103 0 2-.894 2-1.992V3.992A1.998 1.998 0 0 0 20 2zm-6 11H7v-2h7v2zm3-4H7V7h10v2z"/>
7
- </svg>
8
- </span>;
3
+ return React.createElement("span", Object.assign({}, props),
4
+ React.createElement("svg", { fill: "currentColor", width: '1.5rem', height: '1.5rem', className: 'rpc-scale-down' },
5
+ React.createElement("path", { d: "M20 2H4c-1.103 0-2 .894-2 1.992v12.016C2 17.106 2.897 18 4 18h3v4l6.351-4H20c1.103 0 2-.894 2-1.992V3.992A1.998 1.998 0 0 0 20 2zm-6 11H7v-2h7v2zm3-4H7V7h10v2z" })));
9
6
  }
10
7
  export function BiSolidMessageX(props) {
11
- return <span {...props}>
12
- <svg fill="currentColor" width='1.5rem' height='1.5rem' className='scale-down'>
13
- <path d="M20 2H4c-1.103 0-2 .894-2 1.992v12.016C2 17.106 2.897 18 4 18h3v4l6.351-4H20c1.103 0 2-.894 2-1.992V3.992A1.998 1.998 0 0 0 20 2zm-3.293 11.293-1.414 1.414L12 11.414l-3.293 3.293-1.414-1.414L10.586 10 7.293 6.707l1.414-1.414L12 8.586l3.293-3.293 1.414 1.414L13.414 10l3.293 3.293z"/>
14
- </svg>
15
- </span>;
8
+ return React.createElement("span", Object.assign({}, props),
9
+ React.createElement("svg", { fill: "currentColor", width: '1.5rem', height: '1.5rem', className: 'rpc-scale-down' },
10
+ React.createElement("path", { d: "M20 2H4c-1.103 0-2 .894-2 1.992v12.016C2 17.106 2.897 18 4 18h3v4l6.351-4H20c1.103 0 2-.894 2-1.992V3.992A1.998 1.998 0 0 0 20 2zm-3.293 11.293-1.414 1.414L12 11.414l-3.293 3.293-1.414-1.414L10.586 10 7.293 6.707l1.414-1.414L12 8.586l3.293-3.293 1.414 1.414L13.414 10l3.293 3.293z" })));
16
11
  }
17
12
  export function GrSend(props) {
18
- return <span {...props}>
19
- <svg fill="currentColor" width='1.5rem' height='1.5rem' className='scale-down invert'>
20
- <path fill="none" stroke="#000" strokeWidth={2} d="M22,3 L2,11 L20.5,19 L22,3 Z M10,20.5 L13,16 M15.5,9.5 L9,14 L9.85884537,20.0119176 C9.93680292,20.5576204 10.0751625,20.5490248 10.1651297,20.009222 L11,15 L15.5,9.5 Z"/>
21
- </svg>
22
- </span>;
13
+ return React.createElement("span", Object.assign({}, props),
14
+ React.createElement("svg", { fill: "currentColor", width: '1.5rem', height: '1.5rem', className: 'rpc-scale-down rpc-invert' },
15
+ React.createElement("path", { fill: "none", stroke: "#000", strokeWidth: 2, d: "M22,3 L2,11 L20.5,19 L22,3 Z M10,20.5 L13,16 M15.5,9.5 L9,14 L9.85884537,20.0119176 C9.93680292,20.5576204 10.0751625,20.5490248 10.1651297,20.009222 L11,15 L15.5,9.5 Z" })));
23
16
  }
24
17
  export function BsFillMicFill(props) {
25
- return <span {...props}>
26
- <svg fill="currentColor" width='1rem' height='1rem'>
27
- <path d="M5 3a3 3 0 0 1 6 0v5a3 3 0 0 1-6 0V3z"/>
28
- <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"/>
29
- </svg>
30
- </span>;
18
+ return React.createElement("span", Object.assign({}, props),
19
+ React.createElement("svg", { fill: "currentColor", width: '1rem', height: '1rem' },
20
+ React.createElement("path", { d: "M5 3a3 3 0 0 1 6 0v5a3 3 0 0 1-6 0V3z" }),
21
+ 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" })));
31
22
  }
32
23
  export function BsFillMicMuteFill(props) {
33
- return <span {...props}>
34
- <svg fill="currentColor" width='1rem' height='1rem'>
35
- <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"/>
36
- <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"/>
37
- </svg>
38
- </span>;
24
+ return React.createElement("span", Object.assign({}, props),
25
+ React.createElement("svg", { fill: "currentColor", width: '1rem', height: '1rem' },
26
+ 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" }),
27
+ 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" })));
39
28
  }
package/build/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import React, { CSSProperties, DetailedHTMLProps, HTMLAttributes, ReactNode, RefObject } from 'react';
2
2
  import { PeerOptions } from 'peerjs';
3
- import './index.css';
4
3
  type Message = {
5
4
  id: string;
6
5
  text: string;
@@ -30,5 +29,5 @@ type Props = {
30
29
  children?: ReactNode | ((childrenOptions: ChildrenOptions) => ReactNode);
31
30
  } & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
32
31
  export default function Chat({ name, peerId, remotePeerId, peerOptions, text, voice, dialogOptions, onError, children, ...props }: Props): React.JSX.Element;
33
- export declare const cleanStorage: () => void;
32
+ export declare const clearChat: () => void;
34
33
  export {};
package/build/index.js CHANGED
@@ -21,7 +21,6 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  import React, { useEffect, useRef, useState } from 'react';
22
22
  import useStorage, { removeStorage } from './storage';
23
23
  import { BiSolidMessageDetail, BiSolidMessageX, BsFillMicFill, BsFillMicMuteFill, GrSend } from './icons';
24
- import './index.css';
25
24
  export default function Chat(_a) {
26
25
  var { name, peerId, remotePeerId, peerOptions, text = true, voice = true, dialogOptions, onError = () => console.error("Can not access microphone!"), children } = _a, props = __rest(_a, ["name", "peerId", "remotePeerId", "peerOptions", "text", "voice", "dialogOptions", "onError", "children"]);
27
26
  const [peer, setPeer] = useState();
@@ -132,48 +131,39 @@ export default function Chat(_a) {
132
131
  if (container)
133
132
  container.scrollTop = container.scrollHeight;
134
133
  }, [dialog, opponentName, messages]);
135
- return <div className='main' {...props}>
136
- {typeof children === 'function' ? children({ notification, messages, addMessage, dialogRef, audio, setAudio }) : <>
137
- {text && <div>
138
- {dialog ? <BiSolidMessageX onClick={() => setDialog(false)}/>
139
- : <div className='notification'>
140
- <BiSolidMessageDetail onClick={() => {
141
- setNotification(false);
142
- setDialog(true);
143
- }}/>
144
- {notification && <span className='badge'/>}
145
- </div>}
146
- <dialog ref={dialogRef} className={`${dialog ? 'dialog' : ''} position-${(dialogOptions === null || dialogOptions === void 0 ? void 0 : dialogOptions.position) || 'center'}`} style={dialogOptions === null || dialogOptions === void 0 ? void 0 : dialogOptions.style}>
147
- <div className='heading'>Chat</div>
148
- <hr />
149
- <div>
150
- <div ref={containerRef} className='message-container'>
151
- {opponentName && messages.map(({ id, text }, i) => <div key={i}>
152
- <strong>{id === peerId ? 'You' : opponentName}: </strong>
153
- <span>{text}</span>
154
- </div>)}
155
- </div>
156
- <hr />
157
- <form className='input-container' onSubmit={e => {
158
- var _a;
159
- e.preventDefault();
160
- const text = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value;
161
- if (text) {
162
- inputRef.current.value = '';
163
- addMessage({ id: peerId, text }, true);
164
- }
165
- }}>
166
- <input ref={inputRef} className='input' placeholder='Enter a message'/>
167
- <button type='submit'><GrSend /></button>
168
- </form>
169
- </div>
170
- </dialog>
171
- </div>}
172
- {voice && <div>
173
- {audio ? <BsFillMicFill title="Turn mic off" onClick={() => setAudio(false)}/> : <BsFillMicMuteFill title="Turn mic on" onClick={() => setAudio(true)}/>}
174
- </div>}
175
- </>}
176
- {voice && audio && <audio ref={streamRef} autoPlay style={{ display: 'none' }}/>}
177
- </div>;
134
+ return React.createElement("div", Object.assign({ className: 'rpc-main' }, props),
135
+ typeof children === 'function' ? children({ notification, messages, addMessage, dialogRef, audio, setAudio }) : React.createElement(React.Fragment, null,
136
+ text && React.createElement("div", null,
137
+ dialog ? React.createElement(BiSolidMessageX, { onClick: () => setDialog(false) })
138
+ : React.createElement("div", { className: 'rpc-notification' },
139
+ React.createElement(BiSolidMessageDetail, { onClick: () => {
140
+ setNotification(false);
141
+ setDialog(true);
142
+ } }),
143
+ notification && React.createElement("span", { className: 'rpc-badge' })),
144
+ React.createElement("dialog", { ref: dialogRef, className: `${dialog ? 'dialog' : ''} position-${(dialogOptions === null || dialogOptions === void 0 ? void 0 : dialogOptions.position) || 'center'}`, style: dialogOptions === null || dialogOptions === void 0 ? void 0 : dialogOptions.style },
145
+ React.createElement("div", { className: 'rpc-heading' }, "Chat"),
146
+ React.createElement("hr", null),
147
+ React.createElement("div", null,
148
+ React.createElement("div", { ref: containerRef, className: 'rpc-message-container' }, opponentName && messages.map(({ id, text }, i) => React.createElement("div", { key: i },
149
+ React.createElement("strong", null,
150
+ id === peerId ? 'You' : opponentName,
151
+ ": "),
152
+ React.createElement("span", null, text)))),
153
+ React.createElement("hr", null),
154
+ React.createElement("form", { className: 'rpc-input-container', onSubmit: e => {
155
+ var _a;
156
+ e.preventDefault();
157
+ const text = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value;
158
+ if (text) {
159
+ inputRef.current.value = '';
160
+ addMessage({ id: peerId, text }, true);
161
+ }
162
+ } },
163
+ React.createElement("input", { ref: inputRef, className: 'rpc-input', placeholder: 'Enter a message' }),
164
+ React.createElement("button", { type: 'submit' },
165
+ React.createElement(GrSend, null)))))),
166
+ voice && React.createElement("div", null, audio ? React.createElement(BsFillMicFill, { title: "Turn mic off", onClick: () => setAudio(false) }) : React.createElement(BsFillMicMuteFill, { title: "Turn mic on", onClick: () => setAudio(true) }))),
167
+ voice && audio && React.createElement("audio", { ref: streamRef, autoPlay: true, style: { display: 'none' } }));
178
168
  }
179
- export const cleanStorage = () => removeStorage('rpc-messages');
169
+ export const clearChat = () => removeStorage('rpc-messages');
@@ -1,14 +1,14 @@
1
- .main {
1
+ .rpc-main {
2
2
  display: flex;
3
3
  align-items: center;
4
4
  column-gap: 0.5rem;
5
5
  }
6
6
 
7
- .notification {
7
+ .rpc-notification {
8
8
  position: relative;
9
9
  }
10
10
 
11
- .notification .badge {
11
+ .rpc-notification .rpc-badge {
12
12
  background-color: red;
13
13
  position: absolute;
14
14
  top: 0.25rem;
@@ -18,7 +18,7 @@
18
18
  border-radius: 100%;
19
19
  }
20
20
 
21
- .dialog {
21
+ .rpc-dialog {
22
22
  display: flex;
23
23
  flex-direction: column;
24
24
  row-gap: 0.25rem;
@@ -28,43 +28,54 @@
28
28
  outline: 2px solid white;
29
29
  border-radius: 0.25rem;
30
30
  font-size: smaller;
31
+ }
32
+
33
+ .rpc-position-left {
34
+ left: 0.5rem;
35
+ translate: -100%;
36
+ }
37
+
38
+ .rpc-position-center {
31
39
  translate: -50%;
32
- left: 50%;
33
40
  }
34
41
 
35
- .message-container {
42
+ .rpc-position-right {
43
+ left: 0.5rem;
44
+ }
45
+
46
+ .rpc-message-container {
36
47
  height: 6rem;
37
48
  overflow-y: scroll;
38
49
  padding-inline: 0.5rem;
39
50
  margin-bottom: 0.25rem;
40
51
  }
41
52
 
42
- .message-container::-webkit-scrollbar {
53
+ .rpc-message-container::-webkit-scrollbar {
43
54
  width: 2.5px;
44
55
  }
45
56
 
46
- .message-container::-webkit-scrollbar-track {
57
+ .rpc-message-container::-webkit-scrollbar-track {
47
58
  background: gray;
48
59
  }
49
60
 
50
- .message-container::-webkit-scrollbar-thumb {
61
+ .rpc-message-container::-webkit-scrollbar-thumb {
51
62
  background-color: white;
52
63
  }
53
64
 
54
- .heading {
65
+ .rpc-heading {
55
66
  text-align: center;
56
67
  font-weight: bold;
57
68
  padding-inline: 0.5rem;
58
69
  }
59
70
 
60
- .input-container {
71
+ .rpc-input-container {
61
72
  display: flex;
62
73
  column-gap: 0.25rem;
63
74
  padding-inline: 0.5rem;
64
75
  padding-block: 0.4rem;
65
76
  }
66
77
 
67
- .input {
78
+ .rpc-input {
68
79
  background-color: black;
69
80
  border: none;
70
81
  outline: 1px solid rgba(255, 255, 255, 0.8);
@@ -72,6 +83,14 @@
72
83
  padding-inline: 0.25rem;
73
84
  }
74
85
 
75
- .input:focus {
86
+ .rpc-input:focus {
76
87
  outline: 2px solid white;
88
+ }
89
+
90
+ .rpc-scale-down {
91
+ scale: calc(2/3);
92
+ }
93
+
94
+ .rpc-invert {
95
+ filter: invert(100%);
77
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-peer-chat",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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",
package/build/icons.css DELETED
@@ -1,11 +0,0 @@
1
- * {
2
- -webkit-tap-highlight-color: transparent;
3
- }
4
-
5
- .scale-down {
6
- scale: calc(2/3);
7
- }
8
-
9
- .invert {
10
- filter: invert(100%);
11
- }