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