react-select-media-devices-modal 1.0.7 → 1.1.0

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