react-select-media-devices-modal 1.0.8 → 1.1.1

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