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