react-select-media-devices-modal 1.1.0 → 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.
@@ -1,38 +1,38 @@
1
- import e, { useState as m, useEffect as V, 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
- background: oe,
4
- modal: ae,
5
- deviceLists: se,
6
- buttons: de,
7
- chancelButton: re,
8
- confirmButton: ue
9
- }, Q = () => {
10
- const [o, a] = m([]);
11
- return [o, () => {
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 i = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), _ = await navigator.mediaDevices.enumerateDevices();
14
- a(_), i.getTracks().forEach((E) => E.stop());
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
- }, le = ({ name: o, value: a }) => /* @__PURE__ */ e.createElement("option", { value: a }, o), ve = "_deviceList_1bfq1_1", me = "_select_1bfq1_5", W = {
18
- deviceList: ve,
19
- select: me
20
- }, S = ({ devices: o, label: a, selectedDevice: l, onChange: i }) => {
21
- if (o === void 0)
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 _ = (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
- }, pe = "_button_keu24_1", fe = {
28
- button: pe
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
- isSelectAudioInput: o = !0,
31
- isSelectAudioOutput: a = !0,
32
- isSelectVideoInput: l = !0,
33
- open: i,
34
- audioInputDeviceLabel: _ = "audio input device",
35
- audioOutputDeviceLabel: E = "audio output device",
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
+ open: c,
34
+ audioInputDeviceLabel: o = "audio input device",
35
+ audioOutputDeviceLabel: f = "audio output device",
36
36
  videoInputDeviceLabel: k = "video input device",
37
37
  confirmButtonText: j = "Confirm",
38
38
  cancelButtonText: G = "Cancel",
@@ -40,91 +40,93 @@ const oe = "_background_1djbv_1", ae = "_modal_1djbv_13", se = "_deviceLists_1dj
40
40
  onDeviceSelected: T,
41
41
  onDeviceSelectCanceled: y
42
42
  }) => {
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");
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
44
  V(() => {
45
- i ? (navigator.mediaDevices.addEventListener("devicechange", d), d()) : navigator.mediaDevices.removeEventListener("devicechange", d);
46
- }, [i]);
47
- const M = () => {
45
+ c ? (navigator.mediaDevices.addEventListener("devicechange", r), r()) : navigator.mediaDevices.removeEventListener("devicechange", r);
46
+ }, [c]);
47
+ const F = () => {
48
48
  T({
49
- audioInput: b !== void 0 ? b : $[0],
50
- audioOutput: B !== void 0 ? B : L[0],
51
- videoInput: p !== void 0 ? p : w[0]
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
- }, r = () => {
53
+ }, $ = () => {
54
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
- }, F = () => {
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
62
  y();
63
63
  };
64
- return i ? /* @__PURE__ */ e.createElement("div", { className: U.background, ...A ? { onClick: F } : {} }, /* @__PURE__ */ e.createElement(
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
68
  ...A ? {
69
- onClick: (c) => c.stopPropagation()
69
+ onClick: (a) => a.stopPropagation()
70
70
  } : {}
71
71
  },
72
- /* @__PURE__ */ e.createElement("div", { className: U.deviceLists }, o && /* @__PURE__ */ e.createElement(
73
- S,
72
+ /* @__PURE__ */ e.createElement("div", { className: U.deviceLists }, i && /* @__PURE__ */ e.createElement(
73
+ O,
74
74
  {
75
- label: _,
76
- devices: $,
77
- selectedDevice: b,
78
- onChange: s
75
+ label: o,
76
+ devices: M,
77
+ selectedDevice: h,
78
+ onChange: u
79
79
  }
80
- ), a && /* @__PURE__ */ e.createElement(
81
- S,
80
+ ), s && /* @__PURE__ */ e.createElement(
81
+ O,
82
82
  {
83
- label: E,
84
- devices: L,
85
- selectedDevice: B,
86
- onChange: x
83
+ label: f,
84
+ devices: w,
85
+ selectedDevice: L,
86
+ onChange: d
87
87
  }
88
- ), l && /* @__PURE__ */ e.createElement(
89
- S,
88
+ ), v && /* @__PURE__ */ e.createElement(
89
+ O,
90
90
  {
91
91
  label: k,
92
- devices: w,
93
- selectedDevice: p,
94
- onChange: z
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: r }, G), /* @__PURE__ */ e.createElement(P, { className: U.confirmButton, onClick: M }, j))
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
- }, 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
- deviceSelectContainer: be,
103
- preview: he,
104
- previewVideo: Ee,
105
- deviceLists: ke,
106
- buttons: Ce,
107
- chancelButton: De,
108
- confirmButton: Ie
109
- }, X = () => {
110
- const [o, a] = m();
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
+ background: _e,
101
+ modal: be,
102
+ deviceSelectContainer: he,
103
+ preview: Ee,
104
+ previewVideo: ke,
105
+ deviceLists: Ce,
106
+ buttons: De,
107
+ chancelButton: Ie,
108
+ confirmButton: Be
109
+ }, Y = () => {
110
+ const [i, s] = p();
111
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 }
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
- a(_);
118
+ s(f);
119
119
  })();
120
+ }, () => {
121
+ i !== void 0 && (i.getTracks().forEach((o) => o.stop()), s(void 0));
120
122
  }];
121
- }, Pe = ({
122
- isSelectAudioInput: o = !0,
123
- isSelectAudioOutput: a = !0,
124
- isSelectVideoInput: l = !0,
125
- open: i,
126
- audioInputDeviceLabel: _ = "audio input device",
127
- audioOutputDeviceLabel: E = "audio output device",
123
+ }, Te = ({
124
+ isSelectAudioInput: i = !0,
125
+ isSelectAudioOutput: s = !0,
126
+ isSelectVideoInput: v = !0,
127
+ open: c,
128
+ audioInputDeviceLabel: o = "audio input device",
129
+ audioOutputDeviceLabel: f = "audio output device",
128
130
  videoInputDeviceLabel: k = "video input device",
129
131
  confirmButtonText: j = "Confirm",
130
132
  cancelButtonText: G = "Cancel",
@@ -132,203 +134,203 @@ const oe = "_background_1djbv_1", ae = "_modal_1djbv_13", se = "_deviceLists_1dj
132
134
  onDeviceSelected: T,
133
135
  onDeviceSelectCanceled: y
134
136
  }) => {
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]);
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]);
136
138
  V(() => {
137
- i ? (navigator.mediaDevices.addEventListener("devicechange", d), d()) : navigator.mediaDevices.removeEventListener("devicechange", d);
138
- }, [i]), V(() => {
139
- if (s.length < 1)
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 n = s.find((f) => f.deviceId === (p == null ? void 0 : p.deviceId)) ?? s[0];
142
- L(n);
143
- }, [s]);
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: b !== void 0 ? b : M[0],
147
- audioOutput: B !== void 0 ? B : r[0],
148
- videoInput: p !== void 0 ? p : s[0]
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
- y();
152
- }, F = (n) => {
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);
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
162
  V(() => {
161
- const { current: n } = w;
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
- }, [$]);
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]);
164
166
  const N = () => {
165
- y();
167
+ B(), y();
166
168
  };
167
- return i ? /* @__PURE__ */ e.createElement("div", { className: O.background, ...A ? { onClick: N } : {} }, /* @__PURE__ */ e.createElement(
169
+ return c ? /* @__PURE__ */ e.createElement("div", { className: S.background, ...A ? { onClick: N } : {} }, /* @__PURE__ */ e.createElement(
168
170
  "div",
169
171
  {
170
- className: O.modal,
172
+ className: S.modal,
171
173
  ...A ? {
172
174
  onClick: (n) => n.stopPropagation()
173
175
  } : {}
174
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
+ /* @__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: M,
180
- selectedDevice: b,
181
- onChange: F
180
+ label: o,
181
+ devices: $,
182
+ selectedDevice: h,
183
+ onChange: a
182
184
  }
183
- ), a && /* @__PURE__ */ e.createElement(
184
- S,
185
+ ), s && /* @__PURE__ */ e.createElement(
186
+ O,
185
187
  {
186
- label: E,
187
- devices: r,
188
- selectedDevice: B,
189
- onChange: c
188
+ label: f,
189
+ devices: u,
190
+ selectedDevice: L,
191
+ onChange: E
190
192
  }
191
- ), l && /* @__PURE__ */ e.createElement(
192
- S,
193
+ ), v && /* @__PURE__ */ e.createElement(
194
+ O,
193
195
  {
194
196
  label: k,
195
- devices: s,
196
- selectedDevice: p,
197
- onChange: h
197
+ devices: d,
198
+ selectedDevice: g,
199
+ onChange: H
198
200
  }
199
201
  ))),
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))
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
- }, 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
- background: Be,
204
- modal: Le,
205
- deviceSelectContainer: we,
206
- preview: Ne,
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,
206
+ modal: we,
207
+ deviceSelectContainer: Ne,
208
+ preview: Se,
207
209
  previewVideo: Oe,
208
- previewAudio: Se,
210
+ previewAudio: Me,
209
211
  deviceLists: $e,
210
- buttons: Me,
211
- chancelButton: Ve,
212
- confirmButton: je,
213
- recordingButton: Ae
214
- }, Te = ({
215
- isSelectAudioInput: o = !0,
216
- isSelectAudioOutput: a = !0,
217
- isSelectVideoInput: l = !0,
218
- open: i,
219
- audioInputDeviceLabel: _ = "audio input device",
220
- audioOutputDeviceLabel: E = "audio output device",
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,
220
+ open: c,
221
+ audioInputDeviceLabel: o = "audio input device",
222
+ audioOutputDeviceLabel: f = "audio output device",
221
223
  videoInputDeviceLabel: k = "video input device",
222
224
  confirmButtonText: j = "Confirm",
223
225
  cancelButtonText: G = "Cancel",
224
226
  recordingButtonText: A = "Recording",
225
227
  allowOutsideClick: T = !0,
226
228
  onDeviceSelected: y,
227
- onDeviceSelectCanceled: v
229
+ onDeviceSelectCanceled: m
228
230
  }) => {
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]);
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]);
230
232
  V(() => {
231
- i ? (navigator.mediaDevices.addEventListener("devicechange", b), b()) : navigator.mediaDevices.removeEventListener("devicechange", b);
232
- }, [i]), V(() => {
233
+ c ? (navigator.mediaDevices.addEventListener("devicechange", h), h()) : navigator.mediaDevices.removeEventListener("devicechange", h);
234
+ }, [c]), V(() => {
233
235
  if (N.length < 1)
234
236
  return;
235
- const t = N.find((u) => u.deviceId === (I == null ? void 0 : I.deviceId)) ?? N[0];
236
- w(t);
237
+ const t = N.find((l) => l.deviceId === (I == null ? void 0 : I.deviceId)) ?? N[0];
238
+ B(t);
237
239
  }, [N]);
238
240
  const n = () => {
239
- !s || !r || (s.state === "recording" && (s.removeEventListener("dataavailable", () => {
240
- }), s.removeEventListener("stop", () => {
241
- }), s.stop(), s.stream.getTracks().forEach((t) => t.stop())), r.current.src = "", r.current.pause());
242
- }, f = () => {
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
+ }, _ = () => {
243
245
  n(), y({
244
- audioInput: C !== void 0 ? C : c[0],
245
- audioOutput: D !== void 0 ? D : h[0],
246
+ audioInput: C !== void 0 ? C : E[0],
247
+ audioOutput: D !== void 0 ? D : H[0],
246
248
  videoInput: I !== void 0 ? I : N[0]
247
249
  });
248
- }, J = () => {
249
- n(), v();
250
- }, Y = (t) => {
251
- B(c.find((u) => u.deviceId === t));
252
- }, Z = async (t) => {
253
- p(h.find((u) => u.deviceId === t)), await r.current.setSinkId(t);
254
- }, ee = (t) => {
255
- const u = N.find((R) => R.deviceId === t);
256
- $(u), w(u);
257
- }, te = async () => {
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
261
  audio: C && C.deviceId !== "" ? {
260
262
  deviceId: C.deviceId
261
263
  } : !0,
262
264
  video: !1
263
265
  });
264
- let u = [];
266
+ let l = [];
265
267
  const R = new MediaRecorder(t);
266
- R.addEventListener("dataavailable", (H) => {
267
- u.push(H.data);
268
- }), R.addEventListener("stop", async (H) => {
269
- if (F(!1), !r.current)
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 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
- }), R.start(), x(R), F(!0), setTimeout(() => {
276
- R.stop(), t.getTracks().forEach((H) => H.stop());
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
281
  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
- const ne = () => {
284
- n(), 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 i ? /* @__PURE__ */ e.createElement("div", { className: g.background, ...T ? { onClick: ne } : {} }, /* @__PURE__ */ e.createElement(
288
+ return c ? /* @__PURE__ */ e.createElement("div", { className: b.background, ...T ? { onClick: ie } : {} }, /* @__PURE__ */ e.createElement(
287
289
  "div",
288
290
  {
289
- className: g.modal,
291
+ className: b.modal,
290
292
  ...T ? {
291
293
  onClick: (t) => t.stopPropagation()
292
294
  } : {}
293
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
+ /* @__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: c,
299
+ label: o,
300
+ devices: E,
299
301
  selectedDevice: C,
300
- onChange: Y
302
+ onChange: Z
301
303
  }
302
- ), /* @__PURE__ */ e.createElement("div", { className: g.buttons }, /* @__PURE__ */ e.createElement(
304
+ ), /* @__PURE__ */ e.createElement("div", { className: b.buttons }, /* @__PURE__ */ e.createElement(
303
305
  P,
304
306
  {
305
- className: g.recordingButton,
306
- onClick: te,
307
+ className: b.recordingButton,
308
+ onClick: ne,
307
309
  disabled: z
308
310
  },
309
311
  A
310
- ))), a && /* @__PURE__ */ e.createElement(
311
- S,
312
+ ))), s && /* @__PURE__ */ e.createElement(
313
+ O,
312
314
  {
313
- label: E,
314
- devices: h,
315
+ label: f,
316
+ devices: H,
315
317
  selectedDevice: D,
316
- onChange: Z
318
+ onChange: ee
317
319
  }
318
- ), l && /* @__PURE__ */ e.createElement(
319
- S,
320
+ ), v && /* @__PURE__ */ e.createElement(
321
+ O,
320
322
  {
321
323
  label: k,
322
324
  devices: N,
323
325
  selectedDevice: I,
324
- onChange: ee
326
+ onChange: te
325
327
  }
326
328
  ))),
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))
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
- Re as SelectMediaDevicesModal,
332
- Pe as SelectMediaDevicesPreviewModal,
333
- Te as SelectMediaDevicesRecordingModal
333
+ Pe as SelectMediaDevicesModal,
334
+ Te as SelectMediaDevicesPreviewModal,
335
+ Fe as SelectMediaDevicesRecordingModal
334
336
  };
@@ -1 +1 @@
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"})});
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];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-select-media-devices-modal",
3
3
  "description": "A React component library for select media devices",
4
- "version": "1.1.0",
4
+ "version": "1.1.1",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",