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 u, useEffect as L, useRef as K, useMemo as U } 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", F = {
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] = u([]);
10
+ const [o, a] = l([]);
11
11
  return [o, () => {
12
12
  (async () => {
13
- const c = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), l = await navigator.mediaDevices.enumerateDevices();
14
- a(l), c.getTracks().forEach((v) => v.stop());
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
- }, D = ({ devices: o, label: a, onChange: f }) => {
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 c = (v) => {
24
- f(v.target.value);
25
- }, l = `device-select-${a.toLowerCase().replace(/\s/g, "-")}`;
26
- return /* @__PURE__ */ e.createElement("div", { className: W.deviceList }, /* @__PURE__ */ e.createElement("label", { htmlFor: l }, a), /* @__PURE__ */ e.createElement("select", { className: W.select, id: l, onChange: c }, o.map((v, O) => /* @__PURE__ */ e.createElement(le, { value: v.deviceId, name: v.label, key: O }))));
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
- }, y = ({ className: o, children: a, disabled: f, onClick: c }) => /* @__PURE__ */ e.createElement("button", { onClick: c, disabled: f, className: [fe.button, o].filter(Boolean).join(" ") }, a), Re = ({
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: f = !0,
32
+ isSelectVideoInput: r = !0,
33
33
  open: c,
34
- audioInputDeviceLabel: l = "audio input device",
35
- audioOutputDeviceLabel: v = "audio output device",
36
- videoInputDeviceLabel: O = "video input device",
37
- confirmButtonText: q = "Confirm",
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: S = !0,
40
- onDeviceSelected: R,
41
- onDeviceSelectCanceled: $
39
+ allowOutsideClick: j = !0,
40
+ onDeviceSelected: T,
41
+ onDeviceSelectCanceled: A
42
42
  }) => {
43
- const [r, g] = Q(), [M, k] = u(), [j, h] = u(), [A, P] = u(), B = r.filter((i) => i.kind === "audioinput"), C = r.filter((i) => i.kind === "audiooutput"), E = r.filter((i) => i.kind === "videoinput");
44
- L(() => {
45
- c && g();
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 w = () => {
48
- R({
49
- audioInput: M !== void 0 ? M : B[0],
50
- audioOutput: j !== void 0 ? j : C[0],
51
- videoInput: A !== void 0 ? A : E[0]
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(B.find((_) => _.deviceId === i));
56
+ k(O.find((f) => f.deviceId === i));
57
57
  }, x = (i) => {
58
- h(C.find((_) => _.deviceId === i));
58
+ h(B.find((f) => f.deviceId === i));
59
59
  }, z = (i) => {
60
- P(E.find((_) => _.deviceId === i));
61
- }, T = () => {
62
- $();
60
+ y(w.find((f) => f.deviceId === i));
61
+ }, F = () => {
62
+ A();
63
63
  };
64
- return c ? /* @__PURE__ */ e.createElement("div", { className: F.background, ...S ? { onClick: T } : {} }, /* @__PURE__ */ e.createElement(
64
+ return c ? /* @__PURE__ */ e.createElement("div", { className: U.background, ...j ? { onClick: F } : {} }, /* @__PURE__ */ e.createElement(
65
65
  "div",
66
66
  {
67
- className: F.modal,
68
- ...S ? {
67
+ className: U.modal,
68
+ ...j ? {
69
69
  onClick: (i) => i.stopPropagation()
70
70
  } : {}
71
71
  },
72
- /* @__PURE__ */ e.createElement("div", { className: F.deviceLists }, o && /* @__PURE__ */ e.createElement(
73
- D,
72
+ /* @__PURE__ */ e.createElement("div", { className: U.deviceLists }, o && /* @__PURE__ */ e.createElement(
73
+ L,
74
74
  {
75
- label: l,
76
- devices: B,
75
+ label: p,
76
+ devices: O,
77
+ selectedDevice: E,
77
78
  onChange: s
78
79
  }
79
80
  ), a && /* @__PURE__ */ e.createElement(
80
- D,
81
+ L,
81
82
  {
82
- label: v,
83
- devices: C,
83
+ label: _,
84
+ devices: B,
85
+ selectedDevice: D,
84
86
  onChange: x
85
87
  }
86
- ), f && /* @__PURE__ */ e.createElement(
87
- D,
88
+ ), r && /* @__PURE__ */ e.createElement(
89
+ L,
88
90
  {
89
- label: O,
90
- devices: E,
91
+ label: g,
92
+ devices: w,
93
+ selectedDevice: I,
91
94
  onChange: z
92
95
  }
93
96
  )),
94
- /* @__PURE__ */ e.createElement("div", { className: F.buttons }, /* @__PURE__ */ e.createElement(y, { className: F.cancelButton, onClick: d }, G), /* @__PURE__ */ e.createElement(y, { className: F.confirmButton, onClick: w }, q))
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", Ie = "_chancelButton_kb025_57", De = "_confirmButton_kb025_59", I = {
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: Ie,
105
- confirmButton: De
107
+ chancelButton: De,
108
+ confirmButton: Ie
106
109
  }, X = () => {
107
- const [o, a] = u();
108
- return L(() => () => {
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 l = await navigator.mediaDevices.getUserMedia(
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(l);
118
+ a(p);
116
119
  })();
117
120
  }];
118
121
  }, Pe = ({
119
122
  isSelectAudioInput: o = !0,
120
123
  isSelectAudioOutput: a = !0,
121
- isSelectVideoInput: f = !0,
124
+ isSelectVideoInput: r = !0,
122
125
  open: c,
123
- audioInputDeviceLabel: l = "audio input device",
124
- audioOutputDeviceLabel: v = "audio output device",
125
- videoInputDeviceLabel: O = "video input device",
126
- confirmButtonText: q = "Confirm",
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: S = !0,
129
- onDeviceSelected: R,
130
- onDeviceSelectCanceled: $
131
+ allowOutsideClick: j = !0,
132
+ onDeviceSelected: T,
133
+ onDeviceSelectCanceled: A
131
134
  }) => {
132
- const [r, g] = Q(), [M, k] = u(), [j, h] = u(), [A, P] = u(), [B, C] = X(), E = K(), w = U(() => r.filter((n) => n.kind === "audioinput"), [r]), d = U(() => r.filter((n) => n.kind === "audiooutput"), [r]), s = U(() => r.filter((n) => n.kind === "videoinput"), [r]);
133
- L(() => {
134
- c && g();
135
- }, [c]), L(() => {
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
- C(n);
142
+ B(n);
140
143
  }, [s]);
141
144
  const x = () => {
142
- R({
143
- audioInput: M !== void 0 ? M : w[0],
144
- audioOutput: j !== void 0 ? j : d[0],
145
- videoInput: A !== void 0 ? A : s[0]
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
- }, T = (n) => {
150
- k(w.find((b) => b.deviceId === n));
151
+ A();
152
+ }, F = (n) => {
153
+ k(S.find((C) => C.deviceId === n));
151
154
  }, i = (n) => {
152
- h(d.find((b) => b.deviceId === n));
153
- }, _ = (n) => {
154
- const b = s.find((J) => J.deviceId === n);
155
- P(b), C(b);
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
- L(() => {
158
- const { current: n } = E;
159
- n !== void 0 && (n.srcObject !== null && n.srcObject instanceof MediaStream && (n.srcObject.getTracks().forEach((b) => b.stop()), n.pause()), n.srcObject = B, n.play());
160
- }, [B]);
161
- const N = () => {
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: I.background, ...S ? { onClick: N } : {} }, /* @__PURE__ */ e.createElement(
167
+ return c ? /* @__PURE__ */ e.createElement("div", { className: N.background, ...j ? { onClick: $ } : {} }, /* @__PURE__ */ e.createElement(
165
168
  "div",
166
169
  {
167
- className: I.modal,
168
- ...S ? {
170
+ className: N.modal,
171
+ ...j ? {
169
172
  onClick: (n) => n.stopPropagation()
170
173
  } : {}
171
174
  },
172
- /* @__PURE__ */ e.createElement("div", { className: I.deviceSelectContainer }, /* @__PURE__ */ e.createElement("div", { className: I.preview }, /* @__PURE__ */ e.createElement("video", { className: I.previewVideo, ref: E, autoPlay: !0, muted: !0, playsInline: !0 })), /* @__PURE__ */ e.createElement("div", { className: I.deviceLists }, o && /* @__PURE__ */ e.createElement(
173
- D,
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: l,
176
- devices: w,
177
- onChange: T
178
+ label: p,
179
+ devices: S,
180
+ selectedDevice: E,
181
+ onChange: F
178
182
  }
179
183
  ), a && /* @__PURE__ */ e.createElement(
180
- D,
184
+ L,
181
185
  {
182
- label: v,
186
+ label: _,
183
187
  devices: d,
188
+ selectedDevice: D,
184
189
  onChange: i
185
190
  }
186
- ), f && /* @__PURE__ */ e.createElement(
187
- D,
191
+ ), r && /* @__PURE__ */ e.createElement(
192
+ L,
188
193
  {
189
- label: O,
194
+ label: g,
190
195
  devices: s,
191
- onChange: _
196
+ selectedDevice: I,
197
+ onChange: f
192
198
  }
193
199
  ))),
194
- /* @__PURE__ */ e.createElement("div", { className: I.buttons }, /* @__PURE__ */ e.createElement(y, { className: I.cancelButton, onClick: z }, G), /* @__PURE__ */ e.createElement(y, { className: I.confirmButton, onClick: x }, q))
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", je = "_chancelButton_1s81f_61", Ae = "_confirmButton_1s81f_63", Ve = "_recordingButton_1s81f_67", p = {
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: je,
206
- confirmButton: Ae,
207
- recordingButton: Ve
211
+ chancelButton: Ve,
212
+ confirmButton: je,
213
+ recordingButton: Ae
208
214
  }, Te = ({
209
215
  isSelectAudioInput: o = !0,
210
216
  isSelectAudioOutput: a = !0,
211
- isSelectVideoInput: f = !0,
217
+ isSelectVideoInput: r = !0,
212
218
  open: c,
213
- audioInputDeviceLabel: l = "audio input device",
214
- audioOutputDeviceLabel: v = "audio output device",
215
- videoInputDeviceLabel: O = "video input device",
216
- confirmButtonText: q = "Confirm",
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: S = "Recording",
219
- allowOutsideClick: R = !0,
220
- onDeviceSelected: $,
221
- onDeviceSelectCanceled: r
224
+ recordingButtonText: j = "Recording",
225
+ allowOutsideClick: T = !0,
226
+ onDeviceSelected: A,
227
+ onDeviceSelectCanceled: u
222
228
  }) => {
223
- const [g, M] = Q(), [k, j] = u(), [h, A] = u(), [P, B] = u(), [C, E] = X(), w = K(), d = K(), [s, x] = u(), [z, T] = u(!1), i = U(() => g.filter((t) => t.kind === "audioinput"), [g]), _ = U(() => g.filter((t) => t.kind === "audiooutput"), [g]), N = U(() => g.filter((t) => t.kind === "videoinput"), [g]);
224
- L(() => {
225
- c && M();
226
- }, [c]), L(() => {
227
- if (N.length < 1)
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] = N;
230
- E(t);
231
- }, [N]);
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
- }, b = () => {
237
- n(), $({
242
+ }, C = () => {
243
+ n(), A({
238
244
  audioInput: k !== void 0 ? k : i[0],
239
- audioOutput: h !== void 0 ? h : _[0],
240
- videoInput: P !== void 0 ? P : N[0]
245
+ audioOutput: h !== void 0 ? h : f[0],
246
+ videoInput: y !== void 0 ? y : $[0]
241
247
  });
242
248
  }, J = () => {
243
- n(), r();
249
+ n(), u();
244
250
  }, Y = (t) => {
245
- j(i.find((m) => m.deviceId === t));
251
+ D(i.find((v) => v.deviceId === t));
246
252
  }, Z = async (t) => {
247
- A(_.find((m) => m.deviceId === t)), await d.current.setSinkId(t);
253
+ I(f.find((v) => v.deviceId === t)), await d.current.setSinkId(t);
248
254
  }, ee = (t) => {
249
- const m = N.find((V) => V.deviceId === t);
250
- B(m), E(m);
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 m = [];
259
- const V = new MediaRecorder(t);
260
- V.addEventListener("dataavailable", (H) => {
261
- m.push(H.data);
262
- }), V.addEventListener("stop", async (H) => {
263
- if (T(!1), !d.current)
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(m, { type: "audio/ogg; codecs=opus" });
266
- m = [];
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
- }), V.start(), x(V), T(!0), setTimeout(() => {
270
- V.stop(), t.getTracks().forEach((H) => H.stop());
275
+ }), R.start(), x(R), F(!0), setTimeout(() => {
276
+ R.stop(), t.getTracks().forEach((H) => H.stop());
271
277
  }, 5e3);
272
278
  };
273
- L(() => {
274
- const { current: t } = w;
275
- t && (t.srcObject !== null && t.srcObject instanceof MediaStream && (t.srcObject.getTracks().forEach((m) => m.stop()), t.pause()), t.srcObject = C, t.play());
276
- }, [C]);
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(), r();
284
+ n(), u();
279
285
  };
280
- return c ? /* @__PURE__ */ e.createElement("div", { className: p.background, ...R ? { onClick: ne } : {} }, /* @__PURE__ */ e.createElement(
286
+ return c ? /* @__PURE__ */ e.createElement("div", { className: m.background, ...T ? { onClick: ne } : {} }, /* @__PURE__ */ e.createElement(
281
287
  "div",
282
288
  {
283
- className: p.modal,
284
- ...R ? {
289
+ className: m.modal,
290
+ ...T ? {
285
291
  onClick: (t) => t.stopPropagation()
286
292
  } : {}
287
293
  },
288
- /* @__PURE__ */ e.createElement("div", { className: p.deviceSelectContainer }, /* @__PURE__ */ e.createElement("div", { className: p.preview }, /* @__PURE__ */ e.createElement("video", { className: p.previewVideo, ref: w, autoPlay: !0, muted: !0, playsInline: !0 }), /* @__PURE__ */ e.createElement("audio", { className: p.previewAudio, ref: d, autoPlay: !0, playsInline: !0, controls: !0 })), /* @__PURE__ */ e.createElement("div", { className: p.deviceLists }, o && /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement(
289
- D,
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: l,
297
+ label: p,
292
298
  devices: i,
299
+ selectedDevice: k,
293
300
  onChange: Y
294
301
  }
295
- ), /* @__PURE__ */ e.createElement("div", { className: p.buttons }, /* @__PURE__ */ e.createElement(
296
- y,
302
+ ), /* @__PURE__ */ e.createElement("div", { className: m.buttons }, /* @__PURE__ */ e.createElement(
303
+ P,
297
304
  {
298
- className: p.recordingButton,
305
+ className: m.recordingButton,
299
306
  onClick: te,
300
307
  disabled: z
301
308
  },
302
- S
309
+ j
303
310
  ))), a && /* @__PURE__ */ e.createElement(
304
- D,
311
+ L,
305
312
  {
306
- label: v,
307
- devices: _,
313
+ label: _,
314
+ devices: f,
315
+ selectedDevice: h,
308
316
  onChange: Z
309
317
  }
310
- ), f && /* @__PURE__ */ e.createElement(
311
- D,
318
+ ), r && /* @__PURE__ */ e.createElement(
319
+ L,
312
320
  {
313
- label: O,
314
- devices: N,
321
+ label: g,
322
+ devices: $,
323
+ selectedDevice: y,
315
324
  onChange: ee
316
325
  }
317
326
  ))),
318
- /* @__PURE__ */ e.createElement("div", { className: p.buttons }, /* @__PURE__ */ e.createElement(y, { className: p.cancelButton, onClick: J }, G), /* @__PURE__ */ e.createElement(y, { className: p.confirmButton, onClick: b }, q))
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(g,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(g=typeof globalThis<"u"?globalThis:g||self,e(g.ReactSelectMediaDevicesModal={},g.React))})(this,function(g,e){"use strict";const A={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}),l=await navigator.mediaDevices.enumerateDevices();s(l),i.getTracks().forEach(v=>v.stop())})()}]},W=({name:c,value:s})=>e.createElement("option",{value:s},c),K={deviceList:"_deviceList_1bfq1_1",select:"_select_1bfq1_5"},h=({devices:c,label:s,onChange:f})=>{if(c===void 0)return e.createElement(e.Fragment,null);const i=v=>{f(v.target.value)},l=`device-select-${s.toLowerCase().replace(/\s/g,"-")}`;return e.createElement("div",{className:K.deviceList},e.createElement("label",{htmlFor:l},s),e.createElement("select",{className:K.select,id:l,onChange:i},c.map((v,M)=>e.createElement(W,{value:v.deviceId,name:v.label,key:M}))))},X={button:"_button_keu24_1"},$=({className:c,children:s,disabled:f,onClick:i})=>e.createElement("button",{onClick:i,disabled:f,className:[X.button,c].filter(Boolean).join(" ")},s),Y=({isSelectAudioInput:c=!0,isSelectAudioOutput:s=!0,isSelectVideoInput:f=!0,open:i,audioInputDeviceLabel:l="audio input device",audioOutputDeviceLabel:v="audio output device",videoInputDeviceLabel:M="video input device",confirmButtonText:U="Confirm",cancelButtonText:q="Cancel",allowOutsideClick:N=!0,onDeviceSelected:P,onDeviceSelectCanceled:L})=>{const[a,_]=H(),[O,E]=e.useState(),[y,C]=e.useState(),[j,T]=e.useState(),S=a.filter(o=>o.kind==="audioinput"),D=a.filter(o=>o.kind==="audiooutput"),I=a.filter(o=>o.kind==="videoinput");e.useEffect(()=>{i&&_()},[i]);const B=()=>{P({audioInput:O!==void 0?O:S[0],audioOutput:y!==void 0?y:D[0],videoInput:j!==void 0?j:I[0]})},u=()=>{L()},d=o=>{E(S.find(p=>p.deviceId===o))},G=o=>{C(D.find(p=>p.deviceId===o))},x=o=>{T(I.find(p=>p.deviceId===o))},F=()=>{L()};return i?e.createElement("div",{className:A.background,...N?{onClick:F}:{}},e.createElement("div",{className:A.modal,...N?{onClick:o=>o.stopPropagation()}:{}},e.createElement("div",{className:A.deviceLists},c&&e.createElement(h,{label:l,devices:S,onChange:d}),s&&e.createElement(h,{label:v,devices:D,onChange:G}),f&&e.createElement(h,{label:M,devices:I,onChange:x})),e.createElement("div",{className:A.buttons},e.createElement($,{className:A.cancelButton,onClick:u},q),e.createElement($,{className:A.confirmButton,onClick:B},U)))):e.createElement(e.Fragment,null)},k={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 l=await navigator.mediaDevices.getUserMedia(i.kind==="audioinput"?{video:!1,audio:{deviceId:i.deviceId}}:{video:{deviceId:i.deviceId},audio:!1});s(l)})()}]},Z=({isSelectAudioInput:c=!0,isSelectAudioOutput:s=!0,isSelectVideoInput:f=!0,open:i,audioInputDeviceLabel:l="audio input device",audioOutputDeviceLabel:v="audio output device",videoInputDeviceLabel:M="video input device",confirmButtonText:U="Confirm",cancelButtonText:q="Cancel",allowOutsideClick:N=!0,onDeviceSelected:P,onDeviceSelectCanceled:L})=>{const[a,_]=H(),[O,E]=e.useState(),[y,C]=e.useState(),[j,T]=e.useState(),[S,D]=Q(),I=e.useRef(),B=e.useMemo(()=>a.filter(n=>n.kind==="audioinput"),[a]),u=e.useMemo(()=>a.filter(n=>n.kind==="audiooutput"),[a]),d=e.useMemo(()=>a.filter(n=>n.kind==="videoinput"),[a]);e.useEffect(()=>{i&&_()},[i]),e.useEffect(()=>{if(d.length<1)return;const[n]=d;D(n)},[d]);const G=()=>{P({audioInput:O!==void 0?O:B[0],audioOutput:y!==void 0?y:u[0],videoInput:j!==void 0?j:d[0]})},x=()=>{L()},F=n=>{E(B.find(b=>b.deviceId===n))},o=n=>{C(u.find(b=>b.deviceId===n))},p=n=>{const b=d.find(J=>J.deviceId===n);T(b),D(b)};e.useEffect(()=>{const{current:n}=I;n!==void 0&&(n.srcObject!==null&&n.srcObject instanceof MediaStream&&(n.srcObject.getTracks().forEach(b=>b.stop()),n.pause()),n.srcObject=S,n.play())},[S]);const w=()=>{L()};return i?e.createElement("div",{className:k.background,...N?{onClick:w}:{}},e.createElement("div",{className:k.modal,...N?{onClick:n=>n.stopPropagation()}:{}},e.createElement("div",{className:k.deviceSelectContainer},e.createElement("div",{className:k.preview},e.createElement("video",{className:k.previewVideo,ref:I,autoPlay:!0,muted:!0,playsInline:!0})),e.createElement("div",{className:k.deviceLists},c&&e.createElement(h,{label:l,devices:B,onChange:F}),s&&e.createElement(h,{label:v,devices:u,onChange:o}),f&&e.createElement(h,{label:M,devices:d,onChange:p}))),e.createElement("div",{className:k.buttons},e.createElement($,{className:k.cancelButton,onClick:x},q),e.createElement($,{className:k.confirmButton,onClick:G},U)))):e.createElement(e.Fragment,null)},r={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:f=!0,open:i,audioInputDeviceLabel:l="audio input device",audioOutputDeviceLabel:v="audio output device",videoInputDeviceLabel:M="video input device",confirmButtonText:U="Confirm",cancelButtonText:q="Cancel",recordingButtonText:N="Recording",allowOutsideClick:P=!0,onDeviceSelected:L,onDeviceSelectCanceled:a})=>{const[_,O]=H(),[E,y]=e.useState(),[C,j]=e.useState(),[T,S]=e.useState(),[D,I]=Q(),B=e.useRef(),u=e.useRef(),[d,G]=e.useState(),[x,F]=e.useState(!1),o=e.useMemo(()=>_.filter(t=>t.kind==="audioinput"),[_]),p=e.useMemo(()=>_.filter(t=>t.kind==="audiooutput"),[_]),w=e.useMemo(()=>_.filter(t=>t.kind==="videoinput"),[_]);e.useEffect(()=>{i&&O()},[i]),e.useEffect(()=>{if(w.length<1)return;const[t]=w;I(t)},[w]);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())},b=()=>{n(),L({audioInput:E!==void 0?E:o[0],audioOutput:C!==void 0?C:p[0],videoInput:T!==void 0?T:w[0]})},J=()=>{n(),a()},ee=t=>{y(o.find(m=>m.deviceId===t))},te=async t=>{j(p.find(m=>m.deviceId===t)),await u.current.setSinkId(t)},ne=t=>{const m=w.find(V=>V.deviceId===t);S(m),I(m)},ie=async()=>{const t=await navigator.mediaDevices.getUserMedia({audio:E&&E.deviceId!==""?{deviceId:E.deviceId}:!0,video:!1});let m=[];const V=new MediaRecorder(t);V.addEventListener("dataavailable",z=>{m.push(z.data)}),V.addEventListener("stop",async z=>{if(F(!1),!u.current)return;const ce=new Blob(m,{type:"audio/ogg; codecs=opus"});m=[];const se=URL.createObjectURL(ce);u.current.src=se,C&&C.deviceId!==""&&await u.current.setSinkId(C.deviceId)}),V.start(),G(V),F(!0),setTimeout(()=>{V.stop(),t.getTracks().forEach(z=>z.stop())},5e3)};e.useEffect(()=>{const{current:t}=B;t&&(t.srcObject!==null&&t.srcObject instanceof MediaStream&&(t.srcObject.getTracks().forEach(m=>m.stop()),t.pause()),t.srcObject=D,t.play())},[D]);const oe=()=>{n(),a()};return i?e.createElement("div",{className:r.background,...P?{onClick:oe}:{}},e.createElement("div",{className:r.modal,...P?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:r.deviceSelectContainer},e.createElement("div",{className:r.preview},e.createElement("video",{className:r.previewVideo,ref:B,autoPlay:!0,muted:!0,playsInline:!0}),e.createElement("audio",{className:r.previewAudio,ref:u,autoPlay:!0,playsInline:!0,controls:!0})),e.createElement("div",{className:r.deviceLists},c&&e.createElement(e.Fragment,null,e.createElement(h,{label:l,devices:o,onChange:ee}),e.createElement("div",{className:r.buttons},e.createElement($,{className:r.recordingButton,onClick:ie,disabled:x},N))),s&&e.createElement(h,{label:v,devices:p,onChange:te}),f&&e.createElement(h,{label:M,devices:w,onChange:ne}))),e.createElement("div",{className:r.buttons},e.createElement($,{className:r.cancelButton,onClick:J},q),e.createElement($,{className:r.confirmButton,onClick:b},U)))):e.createElement(e.Fragment,null)};g.SelectMediaDevicesModal=Y,g.SelectMediaDevicesPreviewModal=Z,g.SelectMediaDevicesRecordingModal=R,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
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;
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.0.6",
4
+ "version": "1.0.8",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",