react-select-media-devices-modal 1.0.7 → 1.1.0
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
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e, { useState as
|
|
1
|
+
import e, { useState as m, useEffect as V, useRef as K, useMemo as q } from "react";
|
|
2
2
|
const oe = "_background_1djbv_1", ae = "_modal_1djbv_13", se = "_deviceLists_1djbv_20", de = "_buttons_1djbv_24", re = "_chancelButton_1djbv_31", ue = "_confirmButton_1djbv_33", U = {
|
|
3
3
|
background: oe,
|
|
4
4
|
modal: ae,
|
|
@@ -7,203 +7,203 @@ const oe = "_background_1djbv_1", ae = "_modal_1djbv_13", se = "_deviceLists_1dj
|
|
|
7
7
|
chancelButton: re,
|
|
8
8
|
confirmButton: ue
|
|
9
9
|
}, Q = () => {
|
|
10
|
-
const [o, a] =
|
|
10
|
+
const [o, a] = m([]);
|
|
11
11
|
return [o, () => {
|
|
12
12
|
(async () => {
|
|
13
|
-
const
|
|
14
|
-
a(
|
|
13
|
+
const i = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), _ = await navigator.mediaDevices.enumerateDevices();
|
|
14
|
+
a(_), i.getTracks().forEach((E) => E.stop());
|
|
15
15
|
})();
|
|
16
16
|
}];
|
|
17
17
|
}, le = ({ name: o, value: a }) => /* @__PURE__ */ e.createElement("option", { value: a }, o), ve = "_deviceList_1bfq1_1", me = "_select_1bfq1_5", W = {
|
|
18
18
|
deviceList: ve,
|
|
19
19
|
select: me
|
|
20
|
-
},
|
|
20
|
+
}, S = ({ devices: o, label: a, selectedDevice: l, onChange: i }) => {
|
|
21
21
|
if (o === void 0)
|
|
22
22
|
return /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
return /* @__PURE__ */ e.createElement("div", { className: W.deviceList }, /* @__PURE__ */ e.createElement("label", { htmlFor:
|
|
23
|
+
const _ = (k) => {
|
|
24
|
+
i(k.target.value);
|
|
25
|
+
}, E = `device-select-${a.toLowerCase().replace(/\s/g, "-")}`;
|
|
26
|
+
return /* @__PURE__ */ e.createElement("div", { className: W.deviceList }, /* @__PURE__ */ e.createElement("label", { htmlFor: E }, a), /* @__PURE__ */ e.createElement("select", { className: W.select, id: E, onChange: _, defaultValue: l == null ? void 0 : l.deviceId }, o.map((k, j) => /* @__PURE__ */ e.createElement(le, { value: k.deviceId, name: k.label, key: j }))));
|
|
27
27
|
}, pe = "_button_keu24_1", fe = {
|
|
28
28
|
button: pe
|
|
29
|
-
}, P = ({ className: o, children: a, disabled:
|
|
29
|
+
}, P = ({ className: o, children: a, disabled: l, onClick: i }) => /* @__PURE__ */ e.createElement("button", { onClick: i, disabled: l, className: [fe.button, o].filter(Boolean).join(" ") }, a), Re = ({
|
|
30
30
|
isSelectAudioInput: o = !0,
|
|
31
31
|
isSelectAudioOutput: a = !0,
|
|
32
|
-
isSelectVideoInput:
|
|
33
|
-
open:
|
|
34
|
-
audioInputDeviceLabel:
|
|
35
|
-
audioOutputDeviceLabel:
|
|
36
|
-
videoInputDeviceLabel:
|
|
37
|
-
confirmButtonText:
|
|
32
|
+
isSelectVideoInput: l = !0,
|
|
33
|
+
open: i,
|
|
34
|
+
audioInputDeviceLabel: _ = "audio input device",
|
|
35
|
+
audioOutputDeviceLabel: E = "audio output device",
|
|
36
|
+
videoInputDeviceLabel: k = "video input device",
|
|
37
|
+
confirmButtonText: j = "Confirm",
|
|
38
38
|
cancelButtonText: G = "Cancel",
|
|
39
|
-
allowOutsideClick:
|
|
39
|
+
allowOutsideClick: A = !0,
|
|
40
40
|
onDeviceSelected: T,
|
|
41
|
-
onDeviceSelectCanceled:
|
|
41
|
+
onDeviceSelectCanceled: y
|
|
42
42
|
}) => {
|
|
43
|
-
const [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}, [
|
|
47
|
-
const
|
|
43
|
+
const [v, d] = Q(), [b, C] = m(), [B, D] = m(), [p, I] = m(), $ = v.filter((c) => c.kind === "audioinput"), L = v.filter((c) => c.kind === "audiooutput"), w = v.filter((c) => c.kind === "videoinput");
|
|
44
|
+
V(() => {
|
|
45
|
+
i ? (navigator.mediaDevices.addEventListener("devicechange", d), d()) : navigator.mediaDevices.removeEventListener("devicechange", d);
|
|
46
|
+
}, [i]);
|
|
47
|
+
const M = () => {
|
|
48
48
|
T({
|
|
49
|
-
audioInput:
|
|
50
|
-
audioOutput:
|
|
51
|
-
videoInput:
|
|
49
|
+
audioInput: b !== void 0 ? b : $[0],
|
|
50
|
+
audioOutput: B !== void 0 ? B : L[0],
|
|
51
|
+
videoInput: p !== void 0 ? p : w[0]
|
|
52
52
|
});
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
}, s = (
|
|
56
|
-
|
|
57
|
-
}, x = (
|
|
58
|
-
|
|
59
|
-
}, z = (
|
|
60
|
-
|
|
53
|
+
}, r = () => {
|
|
54
|
+
y();
|
|
55
|
+
}, s = (c) => {
|
|
56
|
+
C($.find((h) => h.deviceId === c));
|
|
57
|
+
}, x = (c) => {
|
|
58
|
+
D(L.find((h) => h.deviceId === c));
|
|
59
|
+
}, z = (c) => {
|
|
60
|
+
I(w.find((h) => h.deviceId === c));
|
|
61
61
|
}, F = () => {
|
|
62
|
-
|
|
62
|
+
y();
|
|
63
63
|
};
|
|
64
|
-
return
|
|
64
|
+
return i ? /* @__PURE__ */ e.createElement("div", { className: U.background, ...A ? { onClick: F } : {} }, /* @__PURE__ */ e.createElement(
|
|
65
65
|
"div",
|
|
66
66
|
{
|
|
67
67
|
className: U.modal,
|
|
68
|
-
...
|
|
69
|
-
onClick: (
|
|
68
|
+
...A ? {
|
|
69
|
+
onClick: (c) => c.stopPropagation()
|
|
70
70
|
} : {}
|
|
71
71
|
},
|
|
72
72
|
/* @__PURE__ */ e.createElement("div", { className: U.deviceLists }, o && /* @__PURE__ */ e.createElement(
|
|
73
|
-
|
|
73
|
+
S,
|
|
74
74
|
{
|
|
75
|
-
label:
|
|
76
|
-
devices:
|
|
77
|
-
selectedDevice:
|
|
75
|
+
label: _,
|
|
76
|
+
devices: $,
|
|
77
|
+
selectedDevice: b,
|
|
78
78
|
onChange: s
|
|
79
79
|
}
|
|
80
80
|
), a && /* @__PURE__ */ e.createElement(
|
|
81
|
-
|
|
81
|
+
S,
|
|
82
82
|
{
|
|
83
|
-
label:
|
|
84
|
-
devices:
|
|
85
|
-
selectedDevice:
|
|
83
|
+
label: E,
|
|
84
|
+
devices: L,
|
|
85
|
+
selectedDevice: B,
|
|
86
86
|
onChange: x
|
|
87
87
|
}
|
|
88
|
-
),
|
|
89
|
-
|
|
88
|
+
), l && /* @__PURE__ */ e.createElement(
|
|
89
|
+
S,
|
|
90
90
|
{
|
|
91
|
-
label:
|
|
91
|
+
label: k,
|
|
92
92
|
devices: w,
|
|
93
|
-
selectedDevice:
|
|
93
|
+
selectedDevice: p,
|
|
94
94
|
onChange: z
|
|
95
95
|
}
|
|
96
96
|
)),
|
|
97
|
-
/* @__PURE__ */ e.createElement("div", { className: U.buttons }, /* @__PURE__ */ e.createElement(P, { className: U.cancelButton, onClick:
|
|
97
|
+
/* @__PURE__ */ e.createElement("div", { className: U.buttons }, /* @__PURE__ */ e.createElement(P, { className: U.cancelButton, onClick: r }, G), /* @__PURE__ */ e.createElement(P, { className: U.confirmButton, onClick: M }, j))
|
|
98
98
|
)) : /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
99
|
-
},
|
|
100
|
-
background:
|
|
101
|
-
modal:
|
|
99
|
+
}, ge = "_background_kb025_1", _e = "_modal_kb025_13", be = "_deviceSelectContainer_kb025_19", he = "_preview_kb025_31", Ee = "_previewVideo_kb025_39", ke = "_deviceLists_kb025_44", Ce = "_buttons_kb025_50", De = "_chancelButton_kb025_57", Ie = "_confirmButton_kb025_59", O = {
|
|
100
|
+
background: ge,
|
|
101
|
+
modal: _e,
|
|
102
102
|
deviceSelectContainer: be,
|
|
103
|
-
preview:
|
|
104
|
-
previewVideo:
|
|
105
|
-
deviceLists:
|
|
106
|
-
buttons:
|
|
103
|
+
preview: he,
|
|
104
|
+
previewVideo: Ee,
|
|
105
|
+
deviceLists: ke,
|
|
106
|
+
buttons: Ce,
|
|
107
107
|
chancelButton: De,
|
|
108
108
|
confirmButton: Ie
|
|
109
109
|
}, X = () => {
|
|
110
|
-
const [o, a] =
|
|
111
|
-
return
|
|
112
|
-
o !== void 0 && o.getTracks().forEach((
|
|
113
|
-
}, []), [o, (
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
110
|
+
const [o, a] = m();
|
|
111
|
+
return V(() => () => {
|
|
112
|
+
o !== void 0 && o.getTracks().forEach((i) => i.stop());
|
|
113
|
+
}, []), [o, (i) => {
|
|
114
|
+
i.kind !== "audiooutput" && (async () => {
|
|
115
|
+
const _ = await navigator.mediaDevices.getUserMedia(
|
|
116
|
+
i.kind === "audioinput" ? { video: !1, audio: { deviceId: i.deviceId } } : { video: { deviceId: i.deviceId }, audio: !1 }
|
|
117
117
|
);
|
|
118
|
-
a(
|
|
118
|
+
a(_);
|
|
119
119
|
})();
|
|
120
120
|
}];
|
|
121
121
|
}, Pe = ({
|
|
122
122
|
isSelectAudioInput: o = !0,
|
|
123
123
|
isSelectAudioOutput: a = !0,
|
|
124
|
-
isSelectVideoInput:
|
|
125
|
-
open:
|
|
126
|
-
audioInputDeviceLabel:
|
|
127
|
-
audioOutputDeviceLabel:
|
|
128
|
-
videoInputDeviceLabel:
|
|
129
|
-
confirmButtonText:
|
|
124
|
+
isSelectVideoInput: l = !0,
|
|
125
|
+
open: i,
|
|
126
|
+
audioInputDeviceLabel: _ = "audio input device",
|
|
127
|
+
audioOutputDeviceLabel: E = "audio output device",
|
|
128
|
+
videoInputDeviceLabel: k = "video input device",
|
|
129
|
+
confirmButtonText: j = "Confirm",
|
|
130
130
|
cancelButtonText: G = "Cancel",
|
|
131
|
-
allowOutsideClick:
|
|
131
|
+
allowOutsideClick: A = !0,
|
|
132
132
|
onDeviceSelected: T,
|
|
133
|
-
onDeviceSelectCanceled:
|
|
133
|
+
onDeviceSelectCanceled: y
|
|
134
134
|
}) => {
|
|
135
|
-
const [
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}, [
|
|
135
|
+
const [v, d] = Q(), [b, C] = m(), [B, D] = m(), [p, I] = m(), [$, L] = X(), w = K(), M = q(() => v.filter((n) => n.kind === "audioinput"), [v]), r = q(() => v.filter((n) => n.kind === "audiooutput"), [v]), s = q(() => v.filter((n) => n.kind === "videoinput"), [v]);
|
|
136
|
+
V(() => {
|
|
137
|
+
i ? (navigator.mediaDevices.addEventListener("devicechange", d), d()) : navigator.mediaDevices.removeEventListener("devicechange", d);
|
|
138
|
+
}, [i]), V(() => {
|
|
139
139
|
if (s.length < 1)
|
|
140
140
|
return;
|
|
141
|
-
const
|
|
142
|
-
|
|
141
|
+
const n = s.find((f) => f.deviceId === (p == null ? void 0 : p.deviceId)) ?? s[0];
|
|
142
|
+
L(n);
|
|
143
143
|
}, [s]);
|
|
144
144
|
const x = () => {
|
|
145
145
|
T({
|
|
146
|
-
audioInput:
|
|
147
|
-
audioOutput:
|
|
148
|
-
videoInput:
|
|
146
|
+
audioInput: b !== void 0 ? b : M[0],
|
|
147
|
+
audioOutput: B !== void 0 ? B : r[0],
|
|
148
|
+
videoInput: p !== void 0 ? p : s[0]
|
|
149
149
|
});
|
|
150
150
|
}, z = () => {
|
|
151
|
-
|
|
151
|
+
y();
|
|
152
152
|
}, F = (n) => {
|
|
153
|
-
|
|
154
|
-
},
|
|
155
|
-
|
|
156
|
-
},
|
|
157
|
-
const
|
|
158
|
-
|
|
153
|
+
C(M.find((f) => f.deviceId === n));
|
|
154
|
+
}, c = (n) => {
|
|
155
|
+
D(r.find((f) => f.deviceId === n));
|
|
156
|
+
}, h = (n) => {
|
|
157
|
+
const f = s.find((J) => J.deviceId === n);
|
|
158
|
+
I(f), L(f);
|
|
159
159
|
};
|
|
160
|
-
|
|
160
|
+
V(() => {
|
|
161
161
|
const { current: n } = w;
|
|
162
|
-
n !== void 0 && (n.srcObject !== null && n.srcObject instanceof MediaStream && (n.srcObject.getTracks().forEach((
|
|
163
|
-
}, [
|
|
164
|
-
const
|
|
165
|
-
|
|
162
|
+
n !== void 0 && (n.srcObject !== null && n.srcObject instanceof MediaStream && (n.srcObject.getTracks().forEach((f) => f.stop()), n.pause()), n.srcObject = $, n.play());
|
|
163
|
+
}, [$]);
|
|
164
|
+
const N = () => {
|
|
165
|
+
y();
|
|
166
166
|
};
|
|
167
|
-
return
|
|
167
|
+
return i ? /* @__PURE__ */ e.createElement("div", { className: O.background, ...A ? { onClick: N } : {} }, /* @__PURE__ */ e.createElement(
|
|
168
168
|
"div",
|
|
169
169
|
{
|
|
170
|
-
className:
|
|
171
|
-
...
|
|
170
|
+
className: O.modal,
|
|
171
|
+
...A ? {
|
|
172
172
|
onClick: (n) => n.stopPropagation()
|
|
173
173
|
} : {}
|
|
174
174
|
},
|
|
175
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
176
|
-
|
|
175
|
+
/* @__PURE__ */ e.createElement("div", { className: O.deviceSelectContainer }, /* @__PURE__ */ e.createElement("div", { className: O.preview }, /* @__PURE__ */ e.createElement("video", { className: O.previewVideo, ref: w, autoPlay: !0, muted: !0, playsInline: !0 })), /* @__PURE__ */ e.createElement("div", { className: O.deviceLists }, o && /* @__PURE__ */ e.createElement(
|
|
176
|
+
S,
|
|
177
177
|
{
|
|
178
|
-
label:
|
|
179
|
-
devices:
|
|
180
|
-
selectedDevice:
|
|
178
|
+
label: _,
|
|
179
|
+
devices: M,
|
|
180
|
+
selectedDevice: b,
|
|
181
181
|
onChange: F
|
|
182
182
|
}
|
|
183
183
|
), a && /* @__PURE__ */ e.createElement(
|
|
184
|
-
|
|
184
|
+
S,
|
|
185
185
|
{
|
|
186
|
-
label:
|
|
187
|
-
devices:
|
|
188
|
-
selectedDevice:
|
|
189
|
-
onChange:
|
|
186
|
+
label: E,
|
|
187
|
+
devices: r,
|
|
188
|
+
selectedDevice: B,
|
|
189
|
+
onChange: c
|
|
190
190
|
}
|
|
191
|
-
),
|
|
192
|
-
|
|
191
|
+
), l && /* @__PURE__ */ e.createElement(
|
|
192
|
+
S,
|
|
193
193
|
{
|
|
194
|
-
label:
|
|
194
|
+
label: k,
|
|
195
195
|
devices: s,
|
|
196
|
-
selectedDevice:
|
|
197
|
-
onChange:
|
|
196
|
+
selectedDevice: p,
|
|
197
|
+
onChange: h
|
|
198
198
|
}
|
|
199
199
|
))),
|
|
200
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
200
|
+
/* @__PURE__ */ e.createElement("div", { className: O.buttons }, /* @__PURE__ */ e.createElement(P, { className: O.cancelButton, onClick: z }, G), /* @__PURE__ */ e.createElement(P, { className: O.confirmButton, onClick: x }, j))
|
|
201
201
|
)) : /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
202
|
-
}, Be = "_background_1s81f_1",
|
|
202
|
+
}, Be = "_background_1s81f_1", Le = "_modal_1s81f_13", we = "_deviceSelectContainer_1s81f_19", Ne = "_preview_1s81f_31", Oe = "_previewVideo_1s81f_39", Se = "_previewAudio_1s81f_44", $e = "_deviceLists_1s81f_48", Me = "_buttons_1s81f_54", Ve = "_chancelButton_1s81f_61", je = "_confirmButton_1s81f_63", Ae = "_recordingButton_1s81f_67", g = {
|
|
203
203
|
background: Be,
|
|
204
|
-
modal:
|
|
205
|
-
deviceSelectContainer:
|
|
206
|
-
preview:
|
|
204
|
+
modal: Le,
|
|
205
|
+
deviceSelectContainer: we,
|
|
206
|
+
preview: Ne,
|
|
207
207
|
previewVideo: Oe,
|
|
208
208
|
previewAudio: Se,
|
|
209
209
|
deviceLists: $e,
|
|
@@ -214,117 +214,117 @@ const oe = "_background_1djbv_1", ae = "_modal_1djbv_13", se = "_deviceLists_1dj
|
|
|
214
214
|
}, Te = ({
|
|
215
215
|
isSelectAudioInput: o = !0,
|
|
216
216
|
isSelectAudioOutput: a = !0,
|
|
217
|
-
isSelectVideoInput:
|
|
218
|
-
open:
|
|
219
|
-
audioInputDeviceLabel:
|
|
220
|
-
audioOutputDeviceLabel:
|
|
221
|
-
videoInputDeviceLabel:
|
|
222
|
-
confirmButtonText:
|
|
217
|
+
isSelectVideoInput: l = !0,
|
|
218
|
+
open: i,
|
|
219
|
+
audioInputDeviceLabel: _ = "audio input device",
|
|
220
|
+
audioOutputDeviceLabel: E = "audio output device",
|
|
221
|
+
videoInputDeviceLabel: k = "video input device",
|
|
222
|
+
confirmButtonText: j = "Confirm",
|
|
223
223
|
cancelButtonText: G = "Cancel",
|
|
224
|
-
recordingButtonText:
|
|
224
|
+
recordingButtonText: A = "Recording",
|
|
225
225
|
allowOutsideClick: T = !0,
|
|
226
|
-
onDeviceSelected:
|
|
227
|
-
onDeviceSelectCanceled:
|
|
226
|
+
onDeviceSelected: y,
|
|
227
|
+
onDeviceSelectCanceled: v
|
|
228
228
|
}) => {
|
|
229
|
-
const [
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}, [
|
|
233
|
-
if (
|
|
229
|
+
const [d, b] = Q(), [C, B] = m(), [D, p] = m(), [I, $] = m(), [L, w] = X(), M = K(), r = K(), [s, x] = m(), [z, F] = m(!1), c = q(() => d.filter((t) => t.kind === "audioinput"), [d]), h = q(() => d.filter((t) => t.kind === "audiooutput"), [d]), N = q(() => d.filter((t) => t.kind === "videoinput"), [d]);
|
|
230
|
+
V(() => {
|
|
231
|
+
i ? (navigator.mediaDevices.addEventListener("devicechange", b), b()) : navigator.mediaDevices.removeEventListener("devicechange", b);
|
|
232
|
+
}, [i]), V(() => {
|
|
233
|
+
if (N.length < 1)
|
|
234
234
|
return;
|
|
235
|
-
const
|
|
235
|
+
const t = N.find((u) => u.deviceId === (I == null ? void 0 : I.deviceId)) ?? N[0];
|
|
236
236
|
w(t);
|
|
237
|
-
}, [
|
|
237
|
+
}, [N]);
|
|
238
238
|
const n = () => {
|
|
239
|
-
!s || !
|
|
239
|
+
!s || !r || (s.state === "recording" && (s.removeEventListener("dataavailable", () => {
|
|
240
240
|
}), s.removeEventListener("stop", () => {
|
|
241
|
-
}), s.stop(), s.stream.getTracks().forEach((t) => t.stop())),
|
|
242
|
-
},
|
|
243
|
-
n(),
|
|
244
|
-
audioInput:
|
|
245
|
-
audioOutput:
|
|
246
|
-
videoInput:
|
|
241
|
+
}), s.stop(), s.stream.getTracks().forEach((t) => t.stop())), r.current.src = "", r.current.pause());
|
|
242
|
+
}, f = () => {
|
|
243
|
+
n(), y({
|
|
244
|
+
audioInput: C !== void 0 ? C : c[0],
|
|
245
|
+
audioOutput: D !== void 0 ? D : h[0],
|
|
246
|
+
videoInput: I !== void 0 ? I : N[0]
|
|
247
247
|
});
|
|
248
248
|
}, J = () => {
|
|
249
|
-
n(),
|
|
249
|
+
n(), v();
|
|
250
250
|
}, Y = (t) => {
|
|
251
|
-
|
|
251
|
+
B(c.find((u) => u.deviceId === t));
|
|
252
252
|
}, Z = async (t) => {
|
|
253
|
-
|
|
253
|
+
p(h.find((u) => u.deviceId === t)), await r.current.setSinkId(t);
|
|
254
254
|
}, ee = (t) => {
|
|
255
|
-
const
|
|
256
|
-
|
|
255
|
+
const u = N.find((R) => R.deviceId === t);
|
|
256
|
+
$(u), w(u);
|
|
257
257
|
}, te = async () => {
|
|
258
258
|
const t = await navigator.mediaDevices.getUserMedia({
|
|
259
|
-
audio:
|
|
260
|
-
deviceId:
|
|
259
|
+
audio: C && C.deviceId !== "" ? {
|
|
260
|
+
deviceId: C.deviceId
|
|
261
261
|
} : !0,
|
|
262
262
|
video: !1
|
|
263
263
|
});
|
|
264
|
-
let
|
|
264
|
+
let u = [];
|
|
265
265
|
const R = new MediaRecorder(t);
|
|
266
266
|
R.addEventListener("dataavailable", (H) => {
|
|
267
|
-
|
|
267
|
+
u.push(H.data);
|
|
268
268
|
}), R.addEventListener("stop", async (H) => {
|
|
269
|
-
if (F(!1), !
|
|
269
|
+
if (F(!1), !r.current)
|
|
270
270
|
return;
|
|
271
|
-
const
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
271
|
+
const ie = new Blob(u, { type: "audio/ogg; codecs=opus" });
|
|
272
|
+
u = [];
|
|
273
|
+
const ce = URL.createObjectURL(ie);
|
|
274
|
+
r.current.src = ce, D && D.deviceId !== "" && await r.current.setSinkId(D.deviceId);
|
|
275
275
|
}), R.start(), x(R), F(!0), setTimeout(() => {
|
|
276
276
|
R.stop(), t.getTracks().forEach((H) => H.stop());
|
|
277
277
|
}, 5e3);
|
|
278
278
|
};
|
|
279
|
-
|
|
280
|
-
const { current: t } =
|
|
281
|
-
t && (t.srcObject !== null && t.srcObject instanceof MediaStream && (t.srcObject.getTracks().forEach((
|
|
282
|
-
}, [
|
|
279
|
+
V(() => {
|
|
280
|
+
const { current: t } = M;
|
|
281
|
+
t && (t.srcObject !== null && t.srcObject instanceof MediaStream && (t.srcObject.getTracks().forEach((u) => u.stop()), t.pause()), t.srcObject = L, t.play());
|
|
282
|
+
}, [L]);
|
|
283
283
|
const ne = () => {
|
|
284
|
-
n(),
|
|
284
|
+
n(), v();
|
|
285
285
|
};
|
|
286
|
-
return
|
|
286
|
+
return i ? /* @__PURE__ */ e.createElement("div", { className: g.background, ...T ? { onClick: ne } : {} }, /* @__PURE__ */ e.createElement(
|
|
287
287
|
"div",
|
|
288
288
|
{
|
|
289
|
-
className:
|
|
289
|
+
className: g.modal,
|
|
290
290
|
...T ? {
|
|
291
291
|
onClick: (t) => t.stopPropagation()
|
|
292
292
|
} : {}
|
|
293
293
|
},
|
|
294
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
295
|
-
|
|
294
|
+
/* @__PURE__ */ e.createElement("div", { className: g.deviceSelectContainer }, /* @__PURE__ */ e.createElement("div", { className: g.preview }, /* @__PURE__ */ e.createElement("video", { className: g.previewVideo, ref: M, autoPlay: !0, muted: !0, playsInline: !0 }), /* @__PURE__ */ e.createElement("audio", { className: g.previewAudio, ref: r, autoPlay: !0, playsInline: !0, controls: !0 })), /* @__PURE__ */ e.createElement("div", { className: g.deviceLists }, o && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
|
|
295
|
+
S,
|
|
296
296
|
{
|
|
297
|
-
label:
|
|
298
|
-
devices:
|
|
299
|
-
selectedDevice:
|
|
297
|
+
label: _,
|
|
298
|
+
devices: c,
|
|
299
|
+
selectedDevice: C,
|
|
300
300
|
onChange: Y
|
|
301
301
|
}
|
|
302
|
-
), /* @__PURE__ */ e.createElement("div", { className:
|
|
302
|
+
), /* @__PURE__ */ e.createElement("div", { className: g.buttons }, /* @__PURE__ */ e.createElement(
|
|
303
303
|
P,
|
|
304
304
|
{
|
|
305
|
-
className:
|
|
305
|
+
className: g.recordingButton,
|
|
306
306
|
onClick: te,
|
|
307
307
|
disabled: z
|
|
308
308
|
},
|
|
309
|
-
|
|
309
|
+
A
|
|
310
310
|
))), a && /* @__PURE__ */ e.createElement(
|
|
311
|
-
|
|
311
|
+
S,
|
|
312
312
|
{
|
|
313
|
-
label:
|
|
314
|
-
devices:
|
|
315
|
-
selectedDevice:
|
|
313
|
+
label: E,
|
|
314
|
+
devices: h,
|
|
315
|
+
selectedDevice: D,
|
|
316
316
|
onChange: Z
|
|
317
317
|
}
|
|
318
|
-
),
|
|
319
|
-
|
|
318
|
+
), l && /* @__PURE__ */ e.createElement(
|
|
319
|
+
S,
|
|
320
320
|
{
|
|
321
|
-
label:
|
|
322
|
-
devices:
|
|
323
|
-
selectedDevice:
|
|
321
|
+
label: k,
|
|
322
|
+
devices: N,
|
|
323
|
+
selectedDevice: I,
|
|
324
324
|
onChange: ee
|
|
325
325
|
}
|
|
326
326
|
))),
|
|
327
|
-
/* @__PURE__ */ e.createElement("div", { className:
|
|
327
|
+
/* @__PURE__ */ e.createElement("div", { className: g.buttons }, /* @__PURE__ */ e.createElement(P, { className: g.cancelButton, onClick: J }, G), /* @__PURE__ */ e.createElement(P, { className: g.confirmButton, onClick: f }, j))
|
|
328
328
|
)) : /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
329
329
|
};
|
|
330
330
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(I,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(I=typeof globalThis<"u"?globalThis:I||self,e(I.ReactSelectMediaDevicesModal={},I.React))})(this,function(I,e){"use strict";const T={background:"_background_1djbv_1",modal:"_modal_1djbv_13",deviceLists:"_deviceLists_1djbv_20",buttons:"_buttons_1djbv_24",chancelButton:"_chancelButton_1djbv_31",confirmButton:"_confirmButton_1djbv_33"},H=()=>{const[c,s]=e.useState([]);return[c,()=>{(async()=>{const i=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),g=await navigator.mediaDevices.enumerateDevices();s(g),i.getTracks().forEach(h=>h.stop())})()}]},W=({name:c,value:s})=>e.createElement("option",{value:s},c),K={deviceList:"_deviceList_1bfq1_1",select:"_select_1bfq1_5"},S=({devices:c,label:s,selectedDevice:l,onChange:i})=>{if(c===void 0)return e.createElement(e.Fragment,null);const g=E=>{i(E.target.value)},h=`device-select-${s.toLowerCase().replace(/\s/g,"-")}`;return e.createElement("div",{className:K.deviceList},e.createElement("label",{htmlFor:h},s),e.createElement("select",{className:K.select,id:h,onChange:g,defaultValue:l==null?void 0:l.deviceId},c.map((E,V)=>e.createElement(W,{value:E.deviceId,name:E.label,key:V}))))},X={button:"_button_keu24_1"},y=({className:c,children:s,disabled:l,onClick:i})=>e.createElement("button",{onClick:i,disabled:l,className:[X.button,c].filter(Boolean).join(" ")},s),Y=({isSelectAudioInput:c=!0,isSelectAudioOutput:s=!0,isSelectVideoInput:l=!0,open:i,audioInputDeviceLabel:g="audio input device",audioOutputDeviceLabel:h="audio output device",videoInputDeviceLabel:E="video input device",confirmButtonText:V="Confirm",cancelButtonText:q="Cancel",allowOutsideClick:j=!0,onDeviceSelected:F,onDeviceSelectCanceled:A})=>{const[v,a]=H(),[_,k]=e.useState(),[w,D]=e.useState(),[f,C]=e.useState(),N=v.filter(o=>o.kind==="audioinput"),L=v.filter(o=>o.kind==="audiooutput"),$=v.filter(o=>o.kind==="videoinput");e.useEffect(()=>{i?(navigator.mediaDevices.addEventListener("devicechange",a),a()):navigator.mediaDevices.removeEventListener("devicechange",a)},[i]);const O=()=>{F({audioInput:_!==void 0?_:N[0],audioOutput:w!==void 0?w:L[0],videoInput:f!==void 0?f:$[0]})},u=()=>{A()},d=o=>{k(N.find(b=>b.deviceId===o))},G=o=>{D(L.find(b=>b.deviceId===o))},x=o=>{C($.find(b=>b.deviceId===o))},U=()=>{A()};return i?e.createElement("div",{className:T.background,...j?{onClick:U}:{}},e.createElement("div",{className:T.modal,...j?{onClick:o=>o.stopPropagation()}:{}},e.createElement("div",{className:T.deviceLists},c&&e.createElement(S,{label:g,devices:N,selectedDevice:_,onChange:d}),s&&e.createElement(S,{label:h,devices:L,selectedDevice:w,onChange:G}),l&&e.createElement(S,{label:E,devices:$,selectedDevice:f,onChange:x})),e.createElement("div",{className:T.buttons},e.createElement(y,{className:T.cancelButton,onClick:u},q),e.createElement(y,{className:T.confirmButton,onClick:O},V)))):e.createElement(e.Fragment,null)},B={background:"_background_kb025_1",modal:"_modal_kb025_13",deviceSelectContainer:"_deviceSelectContainer_kb025_19",preview:"_preview_kb025_31",previewVideo:"_previewVideo_kb025_39",deviceLists:"_deviceLists_kb025_44",buttons:"_buttons_kb025_50",chancelButton:"_chancelButton_kb025_57",confirmButton:"_confirmButton_kb025_59"},Q=()=>{const[c,s]=e.useState();return e.useEffect(()=>()=>{c!==void 0&&c.getTracks().forEach(i=>i.stop())},[]),[c,i=>{i.kind!=="audiooutput"&&(async()=>{const g=await navigator.mediaDevices.getUserMedia(i.kind==="audioinput"?{video:!1,audio:{deviceId:i.deviceId}}:{video:{deviceId:i.deviceId},audio:!1});s(g)})()}]},Z=({isSelectAudioInput:c=!0,isSelectAudioOutput:s=!0,isSelectVideoInput:l=!0,open:i,audioInputDeviceLabel:g="audio input device",audioOutputDeviceLabel:h="audio output device",videoInputDeviceLabel:E="video input device",confirmButtonText:V="Confirm",cancelButtonText:q="Cancel",allowOutsideClick:j=!0,onDeviceSelected:F,onDeviceSelectCanceled:A})=>{const[v,a]=H(),[_,k]=e.useState(),[w,D]=e.useState(),[f,C]=e.useState(),[N,L]=Q(),$=e.useRef(),O=e.useMemo(()=>v.filter(n=>n.kind==="audioinput"),[v]),u=e.useMemo(()=>v.filter(n=>n.kind==="audiooutput"),[v]),d=e.useMemo(()=>v.filter(n=>n.kind==="videoinput"),[v]);e.useEffect(()=>{i?(navigator.mediaDevices.addEventListener("devicechange",a),a()):navigator.mediaDevices.removeEventListener("devicechange",a)},[i]),e.useEffect(()=>{if(d.length<1)return;const n=d.find(p=>p.deviceId===(f==null?void 0:f.deviceId))??d[0];L(n)},[d]);const G=()=>{F({audioInput:_!==void 0?_:O[0],audioOutput:w!==void 0?w:u[0],videoInput:f!==void 0?f:d[0]})},x=()=>{A()},U=n=>{k(O.find(p=>p.deviceId===n))},o=n=>{D(u.find(p=>p.deviceId===n))},b=n=>{const p=d.find(J=>J.deviceId===n);C(p),L(p)};e.useEffect(()=>{const{current:n}=$;n!==void 0&&(n.srcObject!==null&&n.srcObject instanceof MediaStream&&(n.srcObject.getTracks().forEach(p=>p.stop()),n.pause()),n.srcObject=N,n.play())},[N]);const M=()=>{A()};return i?e.createElement("div",{className:B.background,...j?{onClick:M}:{}},e.createElement("div",{className:B.modal,...j?{onClick:n=>n.stopPropagation()}:{}},e.createElement("div",{className:B.deviceSelectContainer},e.createElement("div",{className:B.preview},e.createElement("video",{className:B.previewVideo,ref:$,autoPlay:!0,muted:!0,playsInline:!0})),e.createElement("div",{className:B.deviceLists},c&&e.createElement(S,{label:g,devices:O,selectedDevice:_,onChange:U}),s&&e.createElement(S,{label:h,devices:u,selectedDevice:w,onChange:o}),l&&e.createElement(S,{label:E,devices:d,selectedDevice:f,onChange:b}))),e.createElement("div",{className:B.buttons},e.createElement(y,{className:B.cancelButton,onClick:x},q),e.createElement(y,{className:B.confirmButton,onClick:G},V)))):e.createElement(e.Fragment,null)},m={background:"_background_1s81f_1",modal:"_modal_1s81f_13",deviceSelectContainer:"_deviceSelectContainer_1s81f_19",preview:"_preview_1s81f_31",previewVideo:"_previewVideo_1s81f_39",previewAudio:"_previewAudio_1s81f_44",deviceLists:"_deviceLists_1s81f_48",buttons:"_buttons_1s81f_54",chancelButton:"_chancelButton_1s81f_61",confirmButton:"_confirmButton_1s81f_63",recordingButton:"_recordingButton_1s81f_67"},R=({isSelectAudioInput:c=!0,isSelectAudioOutput:s=!0,isSelectVideoInput:l=!0,open:i,audioInputDeviceLabel:g="audio input device",audioOutputDeviceLabel:h="audio output device",videoInputDeviceLabel:E="video input device",confirmButtonText:V="Confirm",cancelButtonText:q="Cancel",recordingButtonText:j="Recording",allowOutsideClick:F=!0,onDeviceSelected:A,onDeviceSelectCanceled:v})=>{const[a,_]=H(),[k,w]=e.useState(),[D,f]=e.useState(),[C,N]=e.useState(),[L,$]=Q(),O=e.useRef(),u=e.useRef(),[d,G]=e.useState(),[x,U]=e.useState(!1),o=e.useMemo(()=>a.filter(t=>t.kind==="audioinput"),[a]),b=e.useMemo(()=>a.filter(t=>t.kind==="audiooutput"),[a]),M=e.useMemo(()=>a.filter(t=>t.kind==="videoinput"),[a]);e.useEffect(()=>{i?(navigator.mediaDevices.addEventListener("devicechange",_),_()):navigator.mediaDevices.removeEventListener("devicechange",_)},[i]),e.useEffect(()=>{if(M.length<1)return;const t=M.find(r=>r.deviceId===(C==null?void 0:C.deviceId))??M[0];$(t)},[M]);const n=()=>{!d||!u||(d.state==="recording"&&(d.removeEventListener("dataavailable",()=>{}),d.removeEventListener("stop",()=>{}),d.stop(),d.stream.getTracks().forEach(t=>t.stop())),u.current.src="",u.current.pause())},p=()=>{n(),A({audioInput:k!==void 0?k:o[0],audioOutput:D!==void 0?D:b[0],videoInput:C!==void 0?C:M[0]})},J=()=>{n(),v()},ee=t=>{w(o.find(r=>r.deviceId===t))},te=async t=>{f(b.find(r=>r.deviceId===t)),await u.current.setSinkId(t)},ne=t=>{const r=M.find(P=>P.deviceId===t);N(r),$(r)},ie=async()=>{const t=await navigator.mediaDevices.getUserMedia({audio:k&&k.deviceId!==""?{deviceId:k.deviceId}:!0,video:!1});let r=[];const P=new MediaRecorder(t);P.addEventListener("dataavailable",z=>{r.push(z.data)}),P.addEventListener("stop",async z=>{if(U(!1),!u.current)return;const ce=new Blob(r,{type:"audio/ogg; codecs=opus"});r=[];const se=URL.createObjectURL(ce);u.current.src=se,D&&D.deviceId!==""&&await u.current.setSinkId(D.deviceId)}),P.start(),G(P),U(!0),setTimeout(()=>{P.stop(),t.getTracks().forEach(z=>z.stop())},5e3)};e.useEffect(()=>{const{current:t}=O;t&&(t.srcObject!==null&&t.srcObject instanceof MediaStream&&(t.srcObject.getTracks().forEach(r=>r.stop()),t.pause()),t.srcObject=L,t.play())},[L]);const oe=()=>{n(),v()};return i?e.createElement("div",{className:m.background,...F?{onClick:oe}:{}},e.createElement("div",{className:m.modal,...F?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:m.deviceSelectContainer},e.createElement("div",{className:m.preview},e.createElement("video",{className:m.previewVideo,ref:O,autoPlay:!0,muted:!0,playsInline:!0}),e.createElement("audio",{className:m.previewAudio,ref:u,autoPlay:!0,playsInline:!0,controls:!0})),e.createElement("div",{className:m.deviceLists},c&&e.createElement(e.Fragment,null,e.createElement(S,{label:g,devices:o,selectedDevice:k,onChange:ee}),e.createElement("div",{className:m.buttons},e.createElement(y,{className:m.recordingButton,onClick:ie,disabled:x},j))),s&&e.createElement(S,{label:h,devices:b,selectedDevice:D,onChange:te}),l&&e.createElement(S,{label:E,devices:M,selectedDevice:C,onChange:ne}))),e.createElement("div",{className:m.buttons},e.createElement(y,{className:m.cancelButton,onClick:J},q),e.createElement(y,{className:m.confirmButton,onClick:p},V)))):e.createElement(e.Fragment,null)};I.SelectMediaDevicesModal=Y,I.SelectMediaDevicesPreviewModal=Z,I.SelectMediaDevicesRecordingModal=R,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
|