react-select-media-devices-modal 1.2.1 → 1.2.3

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,17 +1,17 @@
1
- import c, { useState as f, useEffect as w, useRef as Z, useMemo as K } from "react";
1
+ import c, { useState as L, useEffect as w, useRef as Z, useMemo as K } from "react";
2
2
  const y = () => {
3
- const [g, p] = f([]);
4
- return [g, () => {
3
+ const [s, g] = L([]);
4
+ return [s, () => {
5
5
  (async () => {
6
- const o = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), m = await navigator.mediaDevices.enumerateDevices();
7
- p(m), o.getTracks().forEach((B) => B.stop());
6
+ const o = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), r = await navigator.mediaDevices.enumerateDevices();
7
+ g(r), o.getTracks().forEach((B) => B.stop());
8
8
  })();
9
9
  }];
10
- }, ue = ({ name: g, value: p, style: L }) => /* @__PURE__ */ c.createElement("option", { style: L, value: p }, g), H = ({ devices: g, label: p, selectedDevice: L, style: o, onChange: m }) => {
11
- if (g === void 0) return /* @__PURE__ */ c.createElement(c.Fragment, null);
10
+ }, ae = ({ name: s, value: g, style: f }) => /* @__PURE__ */ c.createElement("option", { style: f, value: g }, s), U = ({ devices: s, label: g, selectedDevice: f, style: o, onChange: r }) => {
11
+ if (s === void 0) return /* @__PURE__ */ c.createElement(c.Fragment, null);
12
12
  const B = (E) => {
13
- m(E.target.value);
14
- }, G = `device-select-${p.toLowerCase().replace(/\s/g, "-")}`, I = {
13
+ r(E.target.value);
14
+ }, H = `device-select-${g.toLowerCase().replace(/\s/g, "-")}`, I = {
15
15
  deviceList: {
16
16
  paddingTop: "8px"
17
17
  },
@@ -26,39 +26,39 @@ const y = () => {
26
26
  width: "100%"
27
27
  },
28
28
  deviceItems: {}
29
- }, A = {
29
+ }, V = {
30
30
  deviceList: o ? { ...I.deviceList, ...o.deviceList } : I.deviceList,
31
31
  label: o ? { ...I.label, ...o.label } : I.label,
32
32
  select: o ? { ...I.select, ...o.select } : I.select,
33
33
  deviceItems: o ? { ...I.deviceItems, ...o.deviceItems } : I.deviceItems
34
34
  };
35
- return /* @__PURE__ */ c.createElement("div", { style: A.deviceList }, /* @__PURE__ */ c.createElement("label", { style: A.label, htmlFor: G }, p), /* @__PURE__ */ c.createElement("select", { style: A.select, id: G, onChange: B, defaultValue: L == null ? void 0 : L.deviceId }, g.map((E, e) => /* @__PURE__ */ c.createElement(ue, { style: A.deviceItems, value: E.deviceId, name: E.label, key: e }))));
36
- }, J = ({ children: g, disabled: p, style: L, onClick: o }) => {
37
- const m = {
35
+ return /* @__PURE__ */ c.createElement("div", { style: V.deviceList }, /* @__PURE__ */ c.createElement("label", { style: V.label, htmlFor: H }, g), /* @__PURE__ */ c.createElement("select", { style: V.select, id: H, onChange: B, defaultValue: f?.deviceId }, s.map((E, e) => /* @__PURE__ */ c.createElement(ae, { style: V.deviceItems, value: E.deviceId, name: E.label, key: e }))));
36
+ }, J = ({ children: s, disabled: g, style: f, onClick: o }) => {
37
+ const r = {
38
38
  borderRadius: "4px",
39
39
  height: "32px",
40
40
  paddingLeft: "16px",
41
41
  paddingRight: "16px",
42
42
  backgroundColor: "white",
43
43
  borderWidth: "1px"
44
- }, B = L ? { ...m, ...L } : m;
45
- return /* @__PURE__ */ c.createElement("button", { onClick: o, disabled: p, style: B }, g);
44
+ }, B = f ? { ...r, ...f } : r;
45
+ return /* @__PURE__ */ c.createElement("button", { onClick: o, disabled: g, style: B }, s);
46
46
  }, ve = ({
47
- isSelectAudioInput: g = !0,
48
- isSelectAudioOutput: p = !0,
49
- isSelectVideoInput: L = !0,
47
+ isSelectAudioInput: s = !0,
48
+ isSelectAudioOutput: g = !0,
49
+ isSelectVideoInput: f = !0,
50
50
  open: o,
51
- audioInputDeviceLabel: m = "audio input device",
51
+ audioInputDeviceLabel: r = "audio input device",
52
52
  audioOutputDeviceLabel: B = "audio output device",
53
- videoInputDeviceLabel: G = "video input device",
53
+ videoInputDeviceLabel: H = "video input device",
54
54
  confirmButtonText: I = "Confirm",
55
- cancelButtonText: A = "Cancel",
55
+ cancelButtonText: V = "Cancel",
56
56
  allowOutsideClick: E = !0,
57
57
  style: e,
58
- onDeviceSelected: i,
58
+ onDeviceSelected: t,
59
59
  onDeviceSelectCanceled: $
60
60
  }) => {
61
- const [k, h] = y(), [V, M] = f(), [W, R] = f(), [x, T] = f(), Q = k.filter((r) => r.kind === "audioinput"), F = k.filter((r) => r.kind === "audiooutput"), j = k.filter((r) => r.kind === "videoinput"), d = {
61
+ const [k, h] = y(), [S, A] = L(), [j, M] = L(), [R, G] = L(), Q = k.filter((v) => v.kind === "audioinput"), W = k.filter((v) => v.kind === "audiooutput"), T = k.filter((v) => v.kind === "videoinput"), d = {
62
62
  background: {
63
63
  position: "fixed",
64
64
  top: 0,
@@ -90,7 +90,7 @@ const y = () => {
90
90
  confirmButton: {
91
91
  marginLeft: "4px"
92
92
  }
93
- }, [l, b] = f({
93
+ }, [p, b] = L({
94
94
  background: e ? { ...d.background, ...e.background } : d.background,
95
95
  modal: e ? { ...d.modal, ...e.modal } : d.modal,
96
96
  deviceLists: e ? { ...d.deviceLists, ...e.deviceLists } : d.deviceLists,
@@ -117,90 +117,90 @@ const y = () => {
117
117
  o ? (navigator.mediaDevices.addEventListener("devicechange", h), h()) : navigator.mediaDevices.removeEventListener("devicechange", h);
118
118
  }, [o]);
119
119
  const D = () => {
120
- i({
121
- audioInput: V !== void 0 ? V : Q[0],
122
- audioOutput: W !== void 0 ? W : F[0],
123
- videoInput: x !== void 0 ? x : j[0]
120
+ t({
121
+ audioInput: S !== void 0 ? S : Q[0],
122
+ audioOutput: j !== void 0 ? j : W[0],
123
+ videoInput: R !== void 0 ? R : T[0]
124
124
  });
125
125
  }, _ = () => {
126
126
  $();
127
- }, n = (r) => {
128
- M(Q.find((O) => O.deviceId === r));
129
- }, v = (r) => {
130
- R(F.find((O) => O.deviceId === r));
131
- }, U = (r) => {
132
- T(j.find((O) => O.deviceId === r));
127
+ }, n = (v) => {
128
+ A(Q.find((x) => x.deviceId === v));
129
+ }, l = (v) => {
130
+ M(W.find((x) => x.deviceId === v));
131
+ }, F = (v) => {
132
+ G(T.find((x) => x.deviceId === v));
133
133
  }, q = () => {
134
134
  $();
135
135
  };
136
- return o ? /* @__PURE__ */ c.createElement("div", { style: l.background, ...E ? { onClick: q } : {} }, /* @__PURE__ */ c.createElement(
136
+ return o ? /* @__PURE__ */ c.createElement("div", { style: p.background, ...E ? { onClick: q } : {} }, /* @__PURE__ */ c.createElement(
137
137
  "div",
138
138
  {
139
- style: l.modal,
139
+ style: p.modal,
140
140
  ...E ? {
141
- onClick: (r) => r.stopPropagation()
141
+ onClick: (v) => v.stopPropagation()
142
142
  } : {}
143
143
  },
144
- /* @__PURE__ */ c.createElement("div", { style: l.deviceLists }, g && /* @__PURE__ */ c.createElement(
145
- H,
144
+ /* @__PURE__ */ c.createElement("div", { style: p.deviceLists }, s && /* @__PURE__ */ c.createElement(
145
+ U,
146
146
  {
147
- style: l == null ? void 0 : l.audioInputDeviceList,
148
- label: m,
147
+ style: p?.audioInputDeviceList,
148
+ label: r,
149
149
  devices: Q,
150
- selectedDevice: V,
150
+ selectedDevice: S,
151
151
  onChange: n
152
152
  }
153
- ), p && /* @__PURE__ */ c.createElement(
154
- H,
153
+ ), g && /* @__PURE__ */ c.createElement(
154
+ U,
155
155
  {
156
- style: l == null ? void 0 : l.audioOutputDeviceList,
156
+ style: p?.audioOutputDeviceList,
157
157
  label: B,
158
- devices: F,
159
- selectedDevice: W,
160
- onChange: v
158
+ devices: W,
159
+ selectedDevice: j,
160
+ onChange: l
161
161
  }
162
- ), L && /* @__PURE__ */ c.createElement(
163
- H,
162
+ ), f && /* @__PURE__ */ c.createElement(
163
+ U,
164
164
  {
165
- style: l == null ? void 0 : l.videoInputDeviceList,
166
- label: G,
167
- devices: j,
168
- selectedDevice: x,
169
- onChange: U
165
+ style: p?.videoInputDeviceList,
166
+ label: H,
167
+ devices: T,
168
+ selectedDevice: R,
169
+ onChange: F
170
170
  }
171
171
  )),
172
- /* @__PURE__ */ c.createElement("div", { style: l.buttons }, /* @__PURE__ */ c.createElement(J, { style: l.cancelButton, onClick: _ }, A), /* @__PURE__ */ c.createElement(J, { style: l.confirmButton, onClick: D }, I))
172
+ /* @__PURE__ */ c.createElement("div", { style: p.buttons }, /* @__PURE__ */ c.createElement(J, { style: p.cancelButton, onClick: _ }, V), /* @__PURE__ */ c.createElement(J, { style: p.confirmButton, onClick: D }, I))
173
173
  )) : /* @__PURE__ */ c.createElement(c.Fragment, null);
174
174
  }, P = () => {
175
- const [g, p] = f();
175
+ const [s, g] = L();
176
176
  return w(() => () => {
177
- g !== void 0 && g.getTracks().forEach((m) => m.stop());
178
- }, []), [g, (m) => {
179
- m.kind !== "audiooutput" && (async () => {
177
+ s !== void 0 && s.getTracks().forEach((r) => r.stop());
178
+ }, []), [s, (r) => {
179
+ r.kind !== "audiooutput" && (async () => {
180
180
  const B = await navigator.mediaDevices.getUserMedia(
181
- m.kind === "audioinput" ? { video: !1, audio: { deviceId: m.deviceId } } : { video: { deviceId: m.deviceId }, audio: !1 }
181
+ r.kind === "audioinput" ? { video: !1, audio: { deviceId: r.deviceId } } : { video: { deviceId: r.deviceId }, audio: !1 }
182
182
  );
183
- p(B);
183
+ g(B);
184
184
  })();
185
185
  }, () => {
186
- g !== void 0 && (g.getTracks().forEach((m) => m.stop()), p(void 0));
186
+ s !== void 0 && (s.getTracks().forEach((r) => r.stop()), g(void 0));
187
187
  }];
188
188
  }, re = ({
189
- isSelectAudioInput: g = !0,
190
- isSelectAudioOutput: p = !0,
191
- isSelectVideoInput: L = !0,
189
+ isSelectAudioInput: s = !0,
190
+ isSelectAudioOutput: g = !0,
191
+ isSelectVideoInput: f = !0,
192
192
  open: o,
193
- audioInputDeviceLabel: m = "audio input device",
193
+ audioInputDeviceLabel: r = "audio input device",
194
194
  audioOutputDeviceLabel: B = "audio output device",
195
- videoInputDeviceLabel: G = "video input device",
195
+ videoInputDeviceLabel: H = "video input device",
196
196
  confirmButtonText: I = "Confirm",
197
- cancelButtonText: A = "Cancel",
197
+ cancelButtonText: V = "Cancel",
198
198
  allowOutsideClick: E = !0,
199
199
  style: e,
200
- onDeviceSelected: i,
200
+ onDeviceSelected: t,
201
201
  onDeviceSelectCanceled: $
202
202
  }) => {
203
- const [k, h] = y(), [V, M] = f(), [W, R] = f(), [x, T] = f(), [Q, F, j] = P(), d = Z(), l = K(() => k.filter((u) => u.kind === "audioinput"), [k]), b = K(() => k.filter((u) => u.kind === "audiooutput"), [k]), D = K(() => k.filter((u) => u.kind === "videoinput"), [k]), _ = matchMedia("(max-width: 640px)"), n = {
203
+ const [k, h] = y(), [S, A] = L(), [j, M] = L(), [R, G] = L(), [Q, W, T] = P(), d = Z(null), p = K(() => k.filter((a) => a.kind === "audioinput"), [k]), b = K(() => k.filter((a) => a.kind === "audiooutput"), [k]), D = K(() => k.filter((a) => a.kind === "videoinput"), [k]), _ = matchMedia("(max-width: 640px)"), n = {
204
204
  background: {
205
205
  position: "fixed",
206
206
  top: 0,
@@ -253,7 +253,7 @@ const y = () => {
253
253
  confirmButton: {
254
254
  marginLeft: "4px"
255
255
  }
256
- }, [v, U] = f({
256
+ }, [l, F] = L({
257
257
  background: e ? { ...n.background, ...e.background } : n.background,
258
258
  modal: e ? { ...n.modal, ...e.modal } : n.modal,
259
259
  deviceSelectContainer: e ? { ...n.deviceSelectContainer, ...e.deviceSelectContainer } : n.deviceSelectContainer,
@@ -268,7 +268,7 @@ const y = () => {
268
268
  confirmButton: e ? { ...n.confirmButton, ...e.confirmButton } : n.confirmButton
269
269
  });
270
270
  w(() => {
271
- U({
271
+ F({
272
272
  background: e ? { ...n.background, ...e.background } : n.background,
273
273
  modal: e ? { ...n.modal, ...e.modal } : n.modal,
274
274
  deviceSelectContainer: e ? { ...n.deviceSelectContainer, ...e.deviceSelectContainer } : n.deviceSelectContainer,
@@ -283,109 +283,109 @@ const y = () => {
283
283
  confirmButton: e ? { ...n.confirmButton, ...e.confirmButton } : n.confirmButton
284
284
  });
285
285
  }, [e]), w(() => {
286
- const u = () => {
287
- _.matches ? U({
288
- ...v,
286
+ const a = () => {
287
+ _.matches ? F({
288
+ ...l,
289
289
  deviceSelectContainer: {
290
290
  display: "grid",
291
291
  gridTemplateColumns: "100%"
292
292
  }
293
- }) : U({
294
- ...v,
293
+ }) : F({
294
+ ...l,
295
295
  deviceSelectContainer: {
296
296
  display: "grid",
297
297
  gridTemplateColumns: "50% 50%"
298
298
  }
299
299
  });
300
300
  };
301
- return _.addEventListener("change", u), () => {
302
- _.removeEventListener("change", u);
301
+ return _.addEventListener("change", a), () => {
302
+ _.removeEventListener("change", a);
303
303
  };
304
304
  }, []), w(() => {
305
305
  o ? (navigator.mediaDevices.addEventListener("devicechange", h), h()) : navigator.mediaDevices.removeEventListener("devicechange", h);
306
306
  }, [o]), w(() => {
307
307
  if (D.length < 1) return;
308
- const u = D.find((S) => S.deviceId === (x == null ? void 0 : x.deviceId)) ?? D[0];
309
- F(u);
308
+ const a = D.find((O) => O.deviceId === R?.deviceId) ?? D[0];
309
+ W(a);
310
310
  }, [D]);
311
311
  const q = () => {
312
- j(), i({
313
- audioInput: V !== void 0 ? V : l[0],
314
- audioOutput: W !== void 0 ? W : b[0],
315
- videoInput: x !== void 0 ? x : D[0]
312
+ T(), t({
313
+ audioInput: S !== void 0 ? S : p[0],
314
+ audioOutput: j !== void 0 ? j : b[0],
315
+ videoInput: R !== void 0 ? R : D[0]
316
316
  });
317
- }, r = () => {
318
- j(), $();
319
- }, O = (u) => {
320
- M(l.find((S) => S.deviceId === u));
321
- }, t = (u) => {
322
- R(b.find((S) => S.deviceId === u));
323
- }, s = (u) => {
324
- const S = D.find((Y) => Y.deviceId === u);
325
- T(S), F(S);
317
+ }, v = () => {
318
+ T(), $();
319
+ }, x = (a) => {
320
+ A(p.find((O) => O.deviceId === a));
321
+ }, i = (a) => {
322
+ M(b.find((O) => O.deviceId === a));
323
+ }, m = (a) => {
324
+ const O = D.find((Y) => Y.deviceId === a);
325
+ G(O), W(O);
326
326
  };
327
327
  w(() => {
328
- const { current: u } = d;
329
- u && (u.srcObject !== null && u.srcObject instanceof MediaStream && (u.srcObject.getTracks().forEach((S) => S.stop()), u.pause()), u.srcObject = Q, u.play());
328
+ const { current: a } = d;
329
+ a && (a.srcObject !== null && a.srcObject instanceof MediaStream && (a.srcObject.getTracks().forEach((O) => O.stop()), a.pause()), a.srcObject = Q, a.play());
330
330
  }, [Q]);
331
331
  const N = () => {
332
- j(), $();
332
+ T(), $();
333
333
  };
334
- return o ? /* @__PURE__ */ c.createElement("div", { style: v.background, ...E ? { onClick: N } : {} }, /* @__PURE__ */ c.createElement(
334
+ return o ? /* @__PURE__ */ c.createElement("div", { style: l.background, ...E ? { onClick: N } : {} }, /* @__PURE__ */ c.createElement(
335
335
  "div",
336
336
  {
337
- style: v.modal,
337
+ style: l.modal,
338
338
  ...E ? {
339
- onClick: (u) => u.stopPropagation()
339
+ onClick: (a) => a.stopPropagation()
340
340
  } : {}
341
341
  },
342
- /* @__PURE__ */ c.createElement("div", { style: v.deviceSelectContainer }, /* @__PURE__ */ c.createElement("div", { style: v.preview }, /* @__PURE__ */ c.createElement("video", { style: v.previewVideo, ref: d, autoPlay: !0, muted: !0, playsInline: !0 })), /* @__PURE__ */ c.createElement("div", { style: v.deviceLists }, g && /* @__PURE__ */ c.createElement(
343
- H,
342
+ /* @__PURE__ */ c.createElement("div", { style: l.deviceSelectContainer }, /* @__PURE__ */ c.createElement("div", { style: l.preview }, /* @__PURE__ */ c.createElement("video", { style: l.previewVideo, ref: d, autoPlay: !0, muted: !0, playsInline: !0 })), /* @__PURE__ */ c.createElement("div", { style: l.deviceLists }, s && /* @__PURE__ */ c.createElement(
343
+ U,
344
344
  {
345
- style: v.audioInputDeviceList,
346
- label: m,
347
- devices: l,
348
- selectedDevice: V,
349
- onChange: O
345
+ style: l.audioInputDeviceList,
346
+ label: r,
347
+ devices: p,
348
+ selectedDevice: S,
349
+ onChange: x
350
350
  }
351
- ), p && /* @__PURE__ */ c.createElement(
352
- H,
351
+ ), g && /* @__PURE__ */ c.createElement(
352
+ U,
353
353
  {
354
- style: v == null ? void 0 : v.audioOutputDeviceList,
354
+ style: l?.audioOutputDeviceList,
355
355
  label: B,
356
356
  devices: b,
357
- selectedDevice: W,
358
- onChange: t
357
+ selectedDevice: j,
358
+ onChange: i
359
359
  }
360
- ), L && /* @__PURE__ */ c.createElement(
361
- H,
360
+ ), f && /* @__PURE__ */ c.createElement(
361
+ U,
362
362
  {
363
- style: v == null ? void 0 : v.videoInputDeviceList,
364
- label: G,
363
+ style: l?.videoInputDeviceList,
364
+ label: H,
365
365
  devices: D,
366
- selectedDevice: x,
367
- onChange: s
366
+ selectedDevice: R,
367
+ onChange: m
368
368
  }
369
369
  ))),
370
- /* @__PURE__ */ c.createElement("div", { style: v.buttons }, /* @__PURE__ */ c.createElement(J, { style: v.cancelButton, onClick: r }, A), /* @__PURE__ */ c.createElement(J, { style: v.confirmButton, onClick: q }, I))
370
+ /* @__PURE__ */ c.createElement("div", { style: l.buttons }, /* @__PURE__ */ c.createElement(J, { style: l.cancelButton, onClick: v }, V), /* @__PURE__ */ c.createElement(J, { style: l.confirmButton, onClick: q }, I))
371
371
  )) : /* @__PURE__ */ c.createElement(c.Fragment, null);
372
372
  }, se = ({
373
- isSelectAudioInput: g = !0,
374
- isSelectAudioOutput: p = !0,
375
- isSelectVideoInput: L = !0,
373
+ isSelectAudioInput: s = !0,
374
+ isSelectAudioOutput: g = !0,
375
+ isSelectVideoInput: f = !0,
376
376
  open: o,
377
- audioInputDeviceLabel: m = "audio input device",
377
+ audioInputDeviceLabel: r = "audio input device",
378
378
  audioOutputDeviceLabel: B = "audio output device",
379
- videoInputDeviceLabel: G = "video input device",
379
+ videoInputDeviceLabel: H = "video input device",
380
380
  confirmButtonText: I = "Confirm",
381
- cancelButtonText: A = "Cancel",
381
+ cancelButtonText: V = "Cancel",
382
382
  recordingButtonText: E = "Recording",
383
383
  allowOutsideClick: e = !0,
384
- style: i,
384
+ style: t,
385
385
  onDeviceSelected: $,
386
386
  onDeviceSelectCanceled: k
387
387
  }) => {
388
- const [h, V] = y(), [M, W] = f(), [R, x] = f(), [T, Q] = f(), [F, j, d] = P(), l = Z(), b = Z(), [D, _] = f(), [n, v] = f(!1), U = K(() => h.filter((a) => a.kind === "audioinput"), [h]), q = K(() => h.filter((a) => a.kind === "audiooutput"), [h]), r = K(() => h.filter((a) => a.kind === "videoinput"), [h]), O = matchMedia("(max-width: 640px)"), t = {
388
+ const [h, S] = y(), [A, j] = L(), [M, R] = L(), [G, Q] = L(), [W, T, d] = P(), p = Z(null), b = Z(null), [D, _] = L(), [n, l] = L(!1), F = K(() => h.filter((u) => u.kind === "audioinput"), [h]), q = K(() => h.filter((u) => u.kind === "audiooutput"), [h]), v = K(() => h.filter((u) => u.kind === "videoinput"), [h]), x = matchMedia("(max-width: 640px)"), i = {
389
389
  background: {
390
390
  position: "fixed",
391
391
  top: 0,
@@ -402,7 +402,7 @@ const y = () => {
402
402
  padding: "16px",
403
403
  borderRadius: "8px"
404
404
  },
405
- deviceSelectContainer: O.matches ? {
405
+ deviceSelectContainer: x.matches ? {
406
406
  display: "grid",
407
407
  gridTemplateColumns: "100%"
408
408
  } : {
@@ -442,159 +442,159 @@ const y = () => {
442
442
  confirmButton: {
443
443
  marginLeft: "4px"
444
444
  }
445
- }, [s, N] = f({
446
- background: i ? { ...t.background, ...i.background } : t.background,
447
- modal: i ? { ...t.modal, ...i.modal } : t.modal,
448
- deviceSelectContainer: i ? { ...t.deviceSelectContainer, ...i.deviceSelectContainer } : t.deviceSelectContainer,
449
- preview: i ? { ...t.preview, ...i.preview } : t.preview,
450
- previewVideo: i ? { ...t.previewVideo, ...i.previewVideo } : t.previewVideo,
451
- previewAudio: i ? { ...t.previewAudio, ...i.previewAudio } : t.previewAudio,
452
- deviceLists: i ? { ...t.deviceLists, ...i.deviceLists } : t.deviceLists,
453
- recordingButtons: i ? { ...t.recordingButtons, ...i.recordingButtons } : t.recordingButtons,
454
- recordingButton: i ? { ...t.recordingButton, ...i.recordingButton } : t.recordingButton,
455
- audioInputDeviceList: i ? { ...t.audioInputDeviceList, ...i.audioInputDeviceList } : t.audioInputDeviceList,
456
- audioOutputDeviceList: i ? { ...t.audioOutputDeviceList, ...i.audioOutputDeviceList } : t.audioOutputDeviceList,
457
- videoInputDeviceList: i ? { ...t.videoInputDeviceList, ...i.videoInputDeviceList } : t.videoInputDeviceList,
458
- buttons: i ? { ...t.buttons, ...i.buttons } : t.buttons,
459
- cancelButton: i ? { ...t.cancelButton, ...i.cancelButton } : t.cancelButton,
460
- confirmButton: i ? { ...t.confirmButton, ...i.confirmButton } : t.confirmButton
445
+ }, [m, N] = L({
446
+ background: t ? { ...i.background, ...t.background } : i.background,
447
+ modal: t ? { ...i.modal, ...t.modal } : i.modal,
448
+ deviceSelectContainer: t ? { ...i.deviceSelectContainer, ...t.deviceSelectContainer } : i.deviceSelectContainer,
449
+ preview: t ? { ...i.preview, ...t.preview } : i.preview,
450
+ previewVideo: t ? { ...i.previewVideo, ...t.previewVideo } : i.previewVideo,
451
+ previewAudio: t ? { ...i.previewAudio, ...t.previewAudio } : i.previewAudio,
452
+ deviceLists: t ? { ...i.deviceLists, ...t.deviceLists } : i.deviceLists,
453
+ recordingButtons: t ? { ...i.recordingButtons, ...t.recordingButtons } : i.recordingButtons,
454
+ recordingButton: t ? { ...i.recordingButton, ...t.recordingButton } : i.recordingButton,
455
+ audioInputDeviceList: t ? { ...i.audioInputDeviceList, ...t.audioInputDeviceList } : i.audioInputDeviceList,
456
+ audioOutputDeviceList: t ? { ...i.audioOutputDeviceList, ...t.audioOutputDeviceList } : i.audioOutputDeviceList,
457
+ videoInputDeviceList: t ? { ...i.videoInputDeviceList, ...t.videoInputDeviceList } : i.videoInputDeviceList,
458
+ buttons: t ? { ...i.buttons, ...t.buttons } : i.buttons,
459
+ cancelButton: t ? { ...i.cancelButton, ...t.cancelButton } : i.cancelButton,
460
+ confirmButton: t ? { ...i.confirmButton, ...t.confirmButton } : i.confirmButton
461
461
  });
462
462
  w(() => {
463
463
  N({
464
- background: i ? { ...t.background, ...i.background } : t.background,
465
- modal: i ? { ...t.modal, ...i.modal } : t.modal,
466
- deviceSelectContainer: i ? { ...t.deviceSelectContainer, ...i.deviceSelectContainer } : t.deviceSelectContainer,
467
- preview: i ? { ...t.preview, ...i.preview } : t.preview,
468
- previewVideo: i ? { ...t.previewVideo, ...i.previewVideo } : t.previewVideo,
469
- previewAudio: i ? { ...t.previewAudio, ...i.previewAudio } : t.previewAudio,
470
- deviceLists: i ? { ...t.deviceLists, ...i.deviceLists } : t.deviceLists,
471
- recordingButtons: i ? { ...t.recordingButtons, ...i.recordingButtons } : t.recordingButtons,
472
- recordingButton: i ? { ...t.recordingButton, ...i.recordingButton } : t.recordingButton,
473
- audioInputDeviceList: i ? { ...t.audioInputDeviceList, ...i.audioInputDeviceList } : t.audioInputDeviceList,
474
- audioOutputDeviceList: i ? { ...t.audioOutputDeviceList, ...i.audioOutputDeviceList } : t.audioOutputDeviceList,
475
- videoInputDeviceList: i ? { ...t.videoInputDeviceList, ...i.videoInputDeviceList } : t.videoInputDeviceList,
476
- buttons: i ? { ...t.buttons, ...i.buttons } : t.buttons,
477
- cancelButton: i ? { ...t.cancelButton, ...i.cancelButton } : t.cancelButton,
478
- confirmButton: i ? { ...t.confirmButton, ...i.confirmButton } : t.confirmButton
464
+ background: t ? { ...i.background, ...t.background } : i.background,
465
+ modal: t ? { ...i.modal, ...t.modal } : i.modal,
466
+ deviceSelectContainer: t ? { ...i.deviceSelectContainer, ...t.deviceSelectContainer } : i.deviceSelectContainer,
467
+ preview: t ? { ...i.preview, ...t.preview } : i.preview,
468
+ previewVideo: t ? { ...i.previewVideo, ...t.previewVideo } : i.previewVideo,
469
+ previewAudio: t ? { ...i.previewAudio, ...t.previewAudio } : i.previewAudio,
470
+ deviceLists: t ? { ...i.deviceLists, ...t.deviceLists } : i.deviceLists,
471
+ recordingButtons: t ? { ...i.recordingButtons, ...t.recordingButtons } : i.recordingButtons,
472
+ recordingButton: t ? { ...i.recordingButton, ...t.recordingButton } : i.recordingButton,
473
+ audioInputDeviceList: t ? { ...i.audioInputDeviceList, ...t.audioInputDeviceList } : i.audioInputDeviceList,
474
+ audioOutputDeviceList: t ? { ...i.audioOutputDeviceList, ...t.audioOutputDeviceList } : i.audioOutputDeviceList,
475
+ videoInputDeviceList: t ? { ...i.videoInputDeviceList, ...t.videoInputDeviceList } : i.videoInputDeviceList,
476
+ buttons: t ? { ...i.buttons, ...t.buttons } : i.buttons,
477
+ cancelButton: t ? { ...i.cancelButton, ...t.cancelButton } : i.cancelButton,
478
+ confirmButton: t ? { ...i.confirmButton, ...t.confirmButton } : i.confirmButton
479
479
  });
480
- }, [i]), w(() => {
481
- const a = () => {
482
- O.matches ? N({
483
- ...s,
480
+ }, [t]), w(() => {
481
+ const u = () => {
482
+ x.matches ? N({
483
+ ...m,
484
484
  deviceSelectContainer: {
485
485
  display: "grid",
486
486
  gridTemplateColumns: "100%"
487
487
  }
488
488
  }) : N({
489
- ...s,
489
+ ...m,
490
490
  deviceSelectContainer: {
491
491
  display: "grid",
492
492
  gridTemplateColumns: "50% 50%"
493
493
  }
494
494
  });
495
495
  };
496
- return O.addEventListener("change", a), () => {
497
- O.removeEventListener("change", a);
496
+ return x.addEventListener("change", u), () => {
497
+ x.removeEventListener("change", u);
498
498
  };
499
499
  }, []), w(() => {
500
- o ? (navigator.mediaDevices.addEventListener("devicechange", V), V()) : navigator.mediaDevices.removeEventListener("devicechange", V);
500
+ o ? (navigator.mediaDevices.addEventListener("devicechange", S), S()) : navigator.mediaDevices.removeEventListener("devicechange", S);
501
501
  }, [o]), w(() => {
502
- if (r.length < 1) return;
503
- const a = r.find((C) => C.deviceId === (T == null ? void 0 : T.deviceId)) ?? r[0];
504
- j(a);
505
- }, [r]);
506
- const u = () => {
502
+ if (v.length < 1) return;
503
+ const u = v.find((C) => C.deviceId === G?.deviceId) ?? v[0];
504
+ T(u);
505
+ }, [v]);
506
+ const a = () => {
507
507
  !D || !b || (D.state === "recording" && (D.removeEventListener("dataavailable", () => {
508
508
  }), D.removeEventListener("stop", () => {
509
- }), D.stop(), D.stream.getTracks().forEach((a) => a.stop())), b.current.src = "", b.current.pause(), d());
510
- }, S = () => {
511
- u(), $({
512
- audioInput: M !== void 0 ? M : U[0],
513
- audioOutput: R !== void 0 ? R : q[0],
514
- videoInput: T !== void 0 ? T : r[0]
509
+ }), D.stop(), D.stream.getTracks().forEach((u) => u.stop())), b.current.src = "", b.current.pause(), d());
510
+ }, O = () => {
511
+ a(), $({
512
+ audioInput: A !== void 0 ? A : F[0],
513
+ audioOutput: M !== void 0 ? M : q[0],
514
+ videoInput: G !== void 0 ? G : v[0]
515
515
  });
516
516
  }, Y = () => {
517
- u(), k();
518
- }, ee = (a) => {
519
- W(U.find((C) => C.deviceId === a));
520
- }, ie = async (a) => {
521
- x(q.find((C) => C.deviceId === a)), await b.current.setSinkId(a);
522
- }, te = (a) => {
523
- const C = r.find((z) => z.deviceId === a);
524
- Q(C), j(C);
517
+ a(), k();
518
+ }, ee = (u) => {
519
+ j(F.find((C) => C.deviceId === u));
520
+ }, te = async (u) => {
521
+ R(q.find((C) => C.deviceId === u)), await b.current.setSinkId(u);
522
+ }, ie = (u) => {
523
+ const C = v.find((z) => z.deviceId === u);
524
+ Q(C), T(C);
525
525
  }, ne = async () => {
526
- const a = await navigator.mediaDevices.getUserMedia({
527
- audio: M && M.deviceId !== "" ? {
528
- deviceId: M.deviceId
526
+ const u = await navigator.mediaDevices.getUserMedia({
527
+ audio: A && A.deviceId !== "" ? {
528
+ deviceId: A.deviceId
529
529
  } : !0,
530
530
  video: !1
531
531
  });
532
532
  let C = [];
533
- const z = new MediaRecorder(a);
533
+ const z = new MediaRecorder(u);
534
534
  z.addEventListener("dataavailable", (X) => {
535
535
  C.push(X.data);
536
536
  }), z.addEventListener("stop", async (X) => {
537
- if (v(!1), !b.current) return;
537
+ if (l(!1), !b.current) return;
538
538
  const de = new Blob(C, { type: "audio/ogg; codecs=opus" });
539
539
  C = [];
540
- const ae = URL.createObjectURL(de);
541
- b.current.src = ae, R && R.deviceId !== "" && await b.current.setSinkId(R.deviceId);
542
- }), z.start(), _(z), v(!0), setTimeout(() => {
543
- z.stop(), a.getTracks().forEach((X) => X.stop());
540
+ const ue = URL.createObjectURL(de);
541
+ b.current.src = ue, M && M.deviceId !== "" && await b.current.setSinkId(M.deviceId);
542
+ }), z.start(), _(z), l(!0), setTimeout(() => {
543
+ z.stop(), u.getTracks().forEach((X) => X.stop());
544
544
  }, 5e3);
545
545
  };
546
546
  w(() => {
547
- const { current: a } = l;
548
- a && (a.srcObject !== null && a.srcObject instanceof MediaStream && (a.srcObject.getTracks().forEach((C) => C.stop()), a.pause()), a.srcObject = F, a.play());
549
- }, [F]);
547
+ const { current: u } = p;
548
+ u && (u.srcObject !== null && u.srcObject instanceof MediaStream && (u.srcObject.getTracks().forEach((C) => C.stop()), u.pause()), u.srcObject = W, u.play());
549
+ }, [W]);
550
550
  const ce = () => {
551
- u(), k();
551
+ a(), k();
552
552
  };
553
- return o ? /* @__PURE__ */ c.createElement("div", { style: s.background, ...e ? { onClick: ce } : {} }, /* @__PURE__ */ c.createElement(
553
+ return o ? /* @__PURE__ */ c.createElement("div", { style: m.background, ...e ? { onClick: ce } : {} }, /* @__PURE__ */ c.createElement(
554
554
  "div",
555
555
  {
556
- style: s.modal,
556
+ style: m.modal,
557
557
  ...e ? {
558
- onClick: (a) => a.stopPropagation()
558
+ onClick: (u) => u.stopPropagation()
559
559
  } : {}
560
560
  },
561
- /* @__PURE__ */ c.createElement("div", { style: s.deviceSelectContainer }, /* @__PURE__ */ c.createElement("div", { style: s.preview }, /* @__PURE__ */ c.createElement("video", { style: s.previewVideo, ref: l, autoPlay: !0, muted: !0, playsInline: !0 }), /* @__PURE__ */ c.createElement("audio", { style: s.previewAudio, ref: b, autoPlay: !0, playsInline: !0, controls: !0 })), /* @__PURE__ */ c.createElement("div", { style: s.deviceLists }, g && /* @__PURE__ */ c.createElement(c.Fragment, null, /* @__PURE__ */ c.createElement(
562
- H,
561
+ /* @__PURE__ */ c.createElement("div", { style: m.deviceSelectContainer }, /* @__PURE__ */ c.createElement("div", { style: m.preview }, /* @__PURE__ */ c.createElement("video", { style: m.previewVideo, ref: p, autoPlay: !0, muted: !0, playsInline: !0 }), /* @__PURE__ */ c.createElement("audio", { style: m.previewAudio, ref: b, autoPlay: !0, playsInline: !0, controls: !0 })), /* @__PURE__ */ c.createElement("div", { style: m.deviceLists }, s && /* @__PURE__ */ c.createElement(c.Fragment, null, /* @__PURE__ */ c.createElement(
562
+ U,
563
563
  {
564
- style: s.audioInputDeviceList,
565
- label: m,
566
- devices: U,
567
- selectedDevice: M,
564
+ style: m.audioInputDeviceList,
565
+ label: r,
566
+ devices: F,
567
+ selectedDevice: A,
568
568
  onChange: ee
569
569
  }
570
- ), /* @__PURE__ */ c.createElement("div", { style: s.recordingButtons }, /* @__PURE__ */ c.createElement(
570
+ ), /* @__PURE__ */ c.createElement("div", { style: m.recordingButtons }, /* @__PURE__ */ c.createElement(
571
571
  J,
572
572
  {
573
- style: s.recordingButton,
573
+ style: m.recordingButton,
574
574
  onClick: ne,
575
575
  disabled: n
576
576
  },
577
577
  E
578
- ))), p && /* @__PURE__ */ c.createElement(
579
- H,
578
+ ))), g && /* @__PURE__ */ c.createElement(
579
+ U,
580
580
  {
581
- style: s == null ? void 0 : s.audioOutputDeviceList,
581
+ style: m?.audioOutputDeviceList,
582
582
  label: B,
583
583
  devices: q,
584
- selectedDevice: R,
585
- onChange: ie
584
+ selectedDevice: M,
585
+ onChange: te
586
586
  }
587
- ), L && /* @__PURE__ */ c.createElement(
588
- H,
587
+ ), f && /* @__PURE__ */ c.createElement(
588
+ U,
589
589
  {
590
- style: s == null ? void 0 : s.videoInputDeviceList,
591
- label: G,
592
- devices: r,
593
- selectedDevice: T,
594
- onChange: te
590
+ style: m?.videoInputDeviceList,
591
+ label: H,
592
+ devices: v,
593
+ selectedDevice: G,
594
+ onChange: ie
595
595
  }
596
596
  ))),
597
- /* @__PURE__ */ c.createElement("div", { style: s.buttons }, /* @__PURE__ */ c.createElement(J, { style: s.cancelButton, onClick: Y }, A), /* @__PURE__ */ c.createElement(J, { style: s.confirmButton, onClick: S }, I))
597
+ /* @__PURE__ */ c.createElement("div", { style: m.buttons }, /* @__PURE__ */ c.createElement(J, { style: m.cancelButton, onClick: Y }, V), /* @__PURE__ */ c.createElement(J, { style: m.confirmButton, onClick: O }, I))
598
598
  )) : /* @__PURE__ */ c.createElement(c.Fragment, null);
599
599
  };
600
600
  export {
@@ -1 +1 @@
1
- (function(j,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(j=typeof globalThis<"u"?globalThis:j||self,e(j.ReactSelectMediaDevicesModal={},j.React))})(this,function(j,e){"use strict";const X=()=>{const[g,f]=e.useState([]);return[g,()=>{(async()=>{const a=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),m=await navigator.mediaDevices.enumerateDevices();f(m),a.getTracks().forEach(C=>C.stop())})()}]},y=({name:g,value:f,style:p})=>e.createElement("option",{style:p,value:f},g),W=({devices:g,label:f,selectedDevice:p,style:a,onChange:m})=>{if(g===void 0)return e.createElement(e.Fragment,null);const C=E=>{m(E.target.value)},G=`device-select-${f.toLowerCase().replace(/\s/g,"-")}`,L={deviceList:{paddingTop:"8px"},label:{},select:{marginTop:"4px",borderRadius:"4px",height:"32px",display:"flex",alignItems:"center",justifyContent:"right",width:"100%"},deviceItems:{}},O={deviceList:a?{...L.deviceList,...a.deviceList}:L.deviceList,label:a?{...L.label,...a.label}:L.label,select:a?{...L.select,...a.select}:L.select,deviceItems:a?{...L.deviceItems,...a.deviceItems}:L.deviceItems};return e.createElement("div",{style:O.deviceList},e.createElement("label",{style:O.label,htmlFor:G},f),e.createElement("select",{style:O.select,id:G,onChange:C,defaultValue:p==null?void 0:p.deviceId},g.map((E,i)=>e.createElement(y,{style:O.deviceItems,value:E.deviceId,name:E.label,key:i}))))},_=({children:g,disabled:f,style:p,onClick:a})=>{const m={borderRadius:"4px",height:"32px",paddingLeft:"16px",paddingRight:"16px",backgroundColor:"white",borderWidth:"1px"},C=p?{...m,...p}:m;return e.createElement("button",{onClick:a,disabled:f,style:C},g)},R=({isSelectAudioInput:g=!0,isSelectAudioOutput:f=!0,isSelectVideoInput:p=!0,open:a,audioInputDeviceLabel:m="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:G="video input device",confirmButtonText:L="Confirm",cancelButtonText:O="Cancel",allowOutsideClick:E=!0,style:i,onDeviceSelected:t,onDeviceSelectCanceled:$})=>{const[B,I]=X(),[x,M]=e.useState(),[F,V]=e.useState(),[k,T]=e.useState(),Q=B.filter(r=>r.kind==="audioinput"),U=B.filter(r=>r.kind==="audiooutput"),A=B.filter(r=>r.kind==="videoinput"),c={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px",minWidth:"270px"},deviceLists:{display:"grid"},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[l,h]=e.useState({background:i?{...c.background,...i.background}:c.background,modal:i?{...c.modal,...i.modal}:c.modal,deviceLists:i?{...c.deviceLists,...i.deviceLists}:c.deviceLists,audioInputDeviceList:i?{...c.audioInputDeviceList,...i.audioInputDeviceList}:{},audioOutputDeviceList:i?{...c.audioOutputDeviceList,...i.audioOutputDeviceList}:{},videoInputDeviceList:i?{...c.videoInputDeviceList,...i.videoInputDeviceList}:{},buttons:i?{...c.buttons,...i.buttons}:c.buttons,cancelButton:i?{...c.cancelButton,...i.cancelButton}:c.cancelButton,confirmButton:i?{...c.confirmButton,...i.confirmButton}:c.confirmButton});e.useEffect(()=>{h({background:i?{...c.background,...i.background}:c.background,modal:i?{...c.modal,...i.modal}:c.modal,deviceLists:i?{...c.deviceLists,...i.deviceLists}:c.deviceLists,audioInputDeviceList:i?{...c.audioInputDeviceList,...i.audioInputDeviceList}:{},audioOutputDeviceList:i?{...c.audioOutputDeviceList,...i.audioOutputDeviceList}:{},videoInputDeviceList:i?{...c.videoInputDeviceList,...i.videoInputDeviceList}:{},buttons:i?{...c.buttons,...i.buttons}:c.buttons,cancelButton:i?{...c.cancelButton,...i.cancelButton}:c.cancelButton,confirmButton:i?{...c.confirmButton,...i.confirmButton}:c.confirmButton})},[i]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",I),I()):navigator.mediaDevices.removeEventListener("devicechange",I)},[a]);const D=()=>{t({audioInput:x!==void 0?x:Q[0],audioOutput:F!==void 0?F:U[0],videoInput:k!==void 0?k:A[0]})},q=()=>{$()},d=r=>{M(Q.find(w=>w.deviceId===r))},v=r=>{V(U.find(w=>w.deviceId===r))},H=r=>{T(A.find(w=>w.deviceId===r))},z=()=>{$()};return a?e.createElement("div",{style:l.background,...E?{onClick:z}:{}},e.createElement("div",{style:l.modal,...E?{onClick:r=>r.stopPropagation()}:{}},e.createElement("div",{style:l.deviceLists},g&&e.createElement(W,{style:l==null?void 0:l.audioInputDeviceList,label:m,devices:Q,selectedDevice:x,onChange:d}),f&&e.createElement(W,{style:l==null?void 0:l.audioOutputDeviceList,label:C,devices:U,selectedDevice:F,onChange:v}),p&&e.createElement(W,{style:l==null?void 0:l.videoInputDeviceList,label:G,devices:A,selectedDevice:k,onChange:H})),e.createElement("div",{style:l.buttons},e.createElement(_,{style:l.cancelButton,onClick:q},O),e.createElement(_,{style:l.confirmButton,onClick:D},L)))):e.createElement(e.Fragment,null)},Z=()=>{const[g,f]=e.useState();return e.useEffect(()=>()=>{g!==void 0&&g.getTracks().forEach(m=>m.stop())},[]),[g,m=>{m.kind!=="audiooutput"&&(async()=>{const C=await navigator.mediaDevices.getUserMedia(m.kind==="audioinput"?{video:!1,audio:{deviceId:m.deviceId}}:{video:{deviceId:m.deviceId},audio:!1});f(C)})()},()=>{g!==void 0&&(g.getTracks().forEach(m=>m.stop()),f(void 0))}]},P=({isSelectAudioInput:g=!0,isSelectAudioOutput:f=!0,isSelectVideoInput:p=!0,open:a,audioInputDeviceLabel:m="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:G="video input device",confirmButtonText:L="Confirm",cancelButtonText:O="Cancel",allowOutsideClick:E=!0,style:i,onDeviceSelected:t,onDeviceSelectCanceled:$})=>{const[B,I]=X(),[x,M]=e.useState(),[F,V]=e.useState(),[k,T]=e.useState(),[Q,U,A]=Z(),c=e.useRef(),l=e.useMemo(()=>B.filter(o=>o.kind==="audioinput"),[B]),h=e.useMemo(()=>B.filter(o=>o.kind==="audiooutput"),[B]),D=e.useMemo(()=>B.filter(o=>o.kind==="videoinput"),[B]),q=matchMedia("(max-width: 640px)"),d={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px"},deviceSelectContainer:q.matches?{display:"grid",gridTemplateColumns:"100%"}:{display:"grid",gridTemplateColumns:"50% 50%"},preview:{minWidth:"270px",minHeight:"180px",maxWidth:"270px",maxHeight:"180px",marginRight:"4px"},previewVideo:{width:"270px",height:"180px"},deviceLists:{display:"grid",minWidth:"270px",marginLeft:"8px"},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[v,H]=e.useState({background:i?{...d.background,...i.background}:d.background,modal:i?{...d.modal,...i.modal}:d.modal,deviceSelectContainer:i?{...d.deviceSelectContainer,...i.deviceSelectContainer}:d.deviceSelectContainer,preview:i?{...d.preview,...i.preview}:d.preview,previewVideo:i?{...d.previewVideo,...i.previewVideo}:d.previewVideo,deviceLists:i?{...d.deviceLists,...i.deviceLists}:d.deviceLists,audioInputDeviceList:i?{...d.audioInputDeviceList,...i.audioInputDeviceList}:d.audioInputDeviceList,audioOutputDeviceList:i?{...d.audioOutputDeviceList,...i.audioOutputDeviceList}:d.audioOutputDeviceList,videoInputDeviceList:i?{...d.videoInputDeviceList,...i.videoInputDeviceList}:d.videoInputDeviceList,buttons:i?{...d.buttons,...i.buttons}:d.buttons,cancelButton:i?{...d.cancelButton,...i.cancelButton}:d.cancelButton,confirmButton:i?{...d.confirmButton,...i.confirmButton}:d.confirmButton});e.useEffect(()=>{H({background:i?{...d.background,...i.background}:d.background,modal:i?{...d.modal,...i.modal}:d.modal,deviceSelectContainer:i?{...d.deviceSelectContainer,...i.deviceSelectContainer}:d.deviceSelectContainer,preview:i?{...d.preview,...i.preview}:d.preview,previewVideo:i?{...d.previewVideo,...i.previewVideo}:d.previewVideo,deviceLists:i?{...d.deviceLists,...i.deviceLists}:d.deviceLists,audioInputDeviceList:i?{...d.audioInputDeviceList,...i.audioInputDeviceList}:d.audioInputDeviceList,audioOutputDeviceList:i?{...d.audioOutputDeviceList,...i.audioOutputDeviceList}:d.audioOutputDeviceList,videoInputDeviceList:i?{...d.videoInputDeviceList,...i.videoInputDeviceList}:d.videoInputDeviceList,buttons:i?{...d.buttons,...i.buttons}:d.buttons,cancelButton:i?{...d.cancelButton,...i.cancelButton}:d.cancelButton,confirmButton:i?{...d.confirmButton,...i.confirmButton}:d.confirmButton})},[i]),e.useEffect(()=>{const o=()=>{q.matches?H({...v,deviceSelectContainer:{display:"grid",gridTemplateColumns:"100%"}}):H({...v,deviceSelectContainer:{display:"grid",gridTemplateColumns:"50% 50%"}})};return q.addEventListener("change",o),()=>{q.removeEventListener("change",o)}},[]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",I),I()):navigator.mediaDevices.removeEventListener("devicechange",I)},[a]),e.useEffect(()=>{if(D.length<1)return;const o=D.find(S=>S.deviceId===(k==null?void 0:k.deviceId))??D[0];U(o)},[D]);const z=()=>{A(),t({audioInput:x!==void 0?x:l[0],audioOutput:F!==void 0?F:h[0],videoInput:k!==void 0?k:D[0]})},r=()=>{A(),$()},w=o=>{M(l.find(S=>S.deviceId===o))},n=o=>{V(h.find(S=>S.deviceId===o))},s=o=>{const S=D.find(Y=>Y.deviceId===o);T(S),U(S)};e.useEffect(()=>{const{current:o}=c;o&&(o.srcObject!==null&&o.srcObject instanceof MediaStream&&(o.srcObject.getTracks().forEach(S=>S.stop()),o.pause()),o.srcObject=Q,o.play())},[Q]);const K=()=>{A(),$()};return a?e.createElement("div",{style:v.background,...E?{onClick:K}:{}},e.createElement("div",{style:v.modal,...E?{onClick:o=>o.stopPropagation()}:{}},e.createElement("div",{style:v.deviceSelectContainer},e.createElement("div",{style:v.preview},e.createElement("video",{style:v.previewVideo,ref:c,autoPlay:!0,muted:!0,playsInline:!0})),e.createElement("div",{style:v.deviceLists},g&&e.createElement(W,{style:v.audioInputDeviceList,label:m,devices:l,selectedDevice:x,onChange:w}),f&&e.createElement(W,{style:v==null?void 0:v.audioOutputDeviceList,label:C,devices:h,selectedDevice:F,onChange:n}),p&&e.createElement(W,{style:v==null?void 0:v.videoInputDeviceList,label:G,devices:D,selectedDevice:k,onChange:s}))),e.createElement("div",{style:v.buttons},e.createElement(_,{style:v.cancelButton,onClick:r},O),e.createElement(_,{style:v.confirmButton,onClick:z},L)))):e.createElement(e.Fragment,null)},ee=({isSelectAudioInput:g=!0,isSelectAudioOutput:f=!0,isSelectVideoInput:p=!0,open:a,audioInputDeviceLabel:m="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:G="video input device",confirmButtonText:L="Confirm",cancelButtonText:O="Cancel",recordingButtonText:E="Recording",allowOutsideClick:i=!0,style:t,onDeviceSelected:$,onDeviceSelectCanceled:B})=>{const[I,x]=X(),[M,F]=e.useState(),[V,k]=e.useState(),[T,Q]=e.useState(),[U,A,c]=Z(),l=e.useRef(),h=e.useRef(),[D,q]=e.useState(),[d,v]=e.useState(!1),H=e.useMemo(()=>I.filter(u=>u.kind==="audioinput"),[I]),z=e.useMemo(()=>I.filter(u=>u.kind==="audiooutput"),[I]),r=e.useMemo(()=>I.filter(u=>u.kind==="videoinput"),[I]),w=matchMedia("(max-width: 640px)"),n={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px"},deviceSelectContainer:w.matches?{display:"grid",gridTemplateColumns:"100%"}:{display:"grid",gridTemplateColumns:"50% 50%"},preview:{minWidth:"270px",minHeight:"180px",maxWidth:"270px",marginRight:"4px"},previewVideo:{width:"270px",height:"180px"},previewAudio:{width:"270px"},deviceLists:{display:"grid",minWidth:"270px",marginLeft:"8px"},recordingButtons:{},recordingButton:{},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[s,K]=e.useState({background:t?{...n.background,...t.background}:n.background,modal:t?{...n.modal,...t.modal}:n.modal,deviceSelectContainer:t?{...n.deviceSelectContainer,...t.deviceSelectContainer}:n.deviceSelectContainer,preview:t?{...n.preview,...t.preview}:n.preview,previewVideo:t?{...n.previewVideo,...t.previewVideo}:n.previewVideo,previewAudio:t?{...n.previewAudio,...t.previewAudio}:n.previewAudio,deviceLists:t?{...n.deviceLists,...t.deviceLists}:n.deviceLists,recordingButtons:t?{...n.recordingButtons,...t.recordingButtons}:n.recordingButtons,recordingButton:t?{...n.recordingButton,...t.recordingButton}:n.recordingButton,audioInputDeviceList:t?{...n.audioInputDeviceList,...t.audioInputDeviceList}:n.audioInputDeviceList,audioOutputDeviceList:t?{...n.audioOutputDeviceList,...t.audioOutputDeviceList}:n.audioOutputDeviceList,videoInputDeviceList:t?{...n.videoInputDeviceList,...t.videoInputDeviceList}:n.videoInputDeviceList,buttons:t?{...n.buttons,...t.buttons}:n.buttons,cancelButton:t?{...n.cancelButton,...t.cancelButton}:n.cancelButton,confirmButton:t?{...n.confirmButton,...t.confirmButton}:n.confirmButton});e.useEffect(()=>{K({background:t?{...n.background,...t.background}:n.background,modal:t?{...n.modal,...t.modal}:n.modal,deviceSelectContainer:t?{...n.deviceSelectContainer,...t.deviceSelectContainer}:n.deviceSelectContainer,preview:t?{...n.preview,...t.preview}:n.preview,previewVideo:t?{...n.previewVideo,...t.previewVideo}:n.previewVideo,previewAudio:t?{...n.previewAudio,...t.previewAudio}:n.previewAudio,deviceLists:t?{...n.deviceLists,...t.deviceLists}:n.deviceLists,recordingButtons:t?{...n.recordingButtons,...t.recordingButtons}:n.recordingButtons,recordingButton:t?{...n.recordingButton,...t.recordingButton}:n.recordingButton,audioInputDeviceList:t?{...n.audioInputDeviceList,...t.audioInputDeviceList}:n.audioInputDeviceList,audioOutputDeviceList:t?{...n.audioOutputDeviceList,...t.audioOutputDeviceList}:n.audioOutputDeviceList,videoInputDeviceList:t?{...n.videoInputDeviceList,...t.videoInputDeviceList}:n.videoInputDeviceList,buttons:t?{...n.buttons,...t.buttons}:n.buttons,cancelButton:t?{...n.cancelButton,...t.cancelButton}:n.cancelButton,confirmButton:t?{...n.confirmButton,...t.confirmButton}:n.confirmButton})},[t]),e.useEffect(()=>{const u=()=>{w.matches?K({...s,deviceSelectContainer:{display:"grid",gridTemplateColumns:"100%"}}):K({...s,deviceSelectContainer:{display:"grid",gridTemplateColumns:"50% 50%"}})};return w.addEventListener("change",u),()=>{w.removeEventListener("change",u)}},[]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",x),x()):navigator.mediaDevices.removeEventListener("devicechange",x)},[a]),e.useEffect(()=>{if(r.length<1)return;const u=r.find(b=>b.deviceId===(T==null?void 0:T.deviceId))??r[0];A(u)},[r]);const o=()=>{!D||!h||(D.state==="recording"&&(D.removeEventListener("dataavailable",()=>{}),D.removeEventListener("stop",()=>{}),D.stop(),D.stream.getTracks().forEach(u=>u.stop())),h.current.src="",h.current.pause(),c())},S=()=>{o(),$({audioInput:M!==void 0?M:H[0],audioOutput:V!==void 0?V:z[0],videoInput:T!==void 0?T:r[0]})},Y=()=>{o(),B()},ie=u=>{F(H.find(b=>b.deviceId===u))},te=async u=>{k(z.find(b=>b.deviceId===u)),await h.current.setSinkId(u)},ne=u=>{const b=r.find(J=>J.deviceId===u);Q(b),A(b)},de=async()=>{const u=await navigator.mediaDevices.getUserMedia({audio:M&&M.deviceId!==""?{deviceId:M.deviceId}:!0,video:!1});let b=[];const J=new MediaRecorder(u);J.addEventListener("dataavailable",N=>{b.push(N.data)}),J.addEventListener("stop",async N=>{if(v(!1),!h.current)return;const ue=new Blob(b,{type:"audio/ogg; codecs=opus"});b=[];const oe=URL.createObjectURL(ue);h.current.src=oe,V&&V.deviceId!==""&&await h.current.setSinkId(V.deviceId)}),J.start(),q(J),v(!0),setTimeout(()=>{J.stop(),u.getTracks().forEach(N=>N.stop())},5e3)};e.useEffect(()=>{const{current:u}=l;u&&(u.srcObject!==null&&u.srcObject instanceof MediaStream&&(u.srcObject.getTracks().forEach(b=>b.stop()),u.pause()),u.srcObject=U,u.play())},[U]);const ce=()=>{o(),B()};return a?e.createElement("div",{style:s.background,...i?{onClick:ce}:{}},e.createElement("div",{style:s.modal,...i?{onClick:u=>u.stopPropagation()}:{}},e.createElement("div",{style:s.deviceSelectContainer},e.createElement("div",{style:s.preview},e.createElement("video",{style:s.previewVideo,ref:l,autoPlay:!0,muted:!0,playsInline:!0}),e.createElement("audio",{style:s.previewAudio,ref:h,autoPlay:!0,playsInline:!0,controls:!0})),e.createElement("div",{style:s.deviceLists},g&&e.createElement(e.Fragment,null,e.createElement(W,{style:s.audioInputDeviceList,label:m,devices:H,selectedDevice:M,onChange:ie}),e.createElement("div",{style:s.recordingButtons},e.createElement(_,{style:s.recordingButton,onClick:de,disabled:d},E))),f&&e.createElement(W,{style:s==null?void 0:s.audioOutputDeviceList,label:C,devices:z,selectedDevice:V,onChange:te}),p&&e.createElement(W,{style:s==null?void 0:s.videoInputDeviceList,label:G,devices:r,selectedDevice:T,onChange:ne}))),e.createElement("div",{style:s.buttons},e.createElement(_,{style:s.cancelButton,onClick:Y},O),e.createElement(_,{style:s.confirmButton,onClick:S},L)))):e.createElement(e.Fragment,null)};j.SelectMediaDevicesModal=R,j.SelectMediaDevicesPreviewModal=P,j.SelectMediaDevicesRecordingModal=ee,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
1
+ (function(A,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(A=typeof globalThis<"u"?globalThis:A||self,e(A.ReactSelectMediaDevicesModal={},A.React))})(this,function(A,e){"use strict";const X=()=>{const[s,g]=e.useState([]);return[s,()=>{(async()=>{const a=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),r=await navigator.mediaDevices.enumerateDevices();g(r),a.getTracks().forEach(C=>C.stop())})()}]},y=({name:s,value:g,style:D})=>e.createElement("option",{style:D,value:g},s),j=({devices:s,label:g,selectedDevice:D,style:a,onChange:r})=>{if(s===void 0)return e.createElement(e.Fragment,null);const C=E=>{r(E.target.value)},H=`device-select-${g.toLowerCase().replace(/\s/g,"-")}`,L={deviceList:{paddingTop:"8px"},label:{},select:{marginTop:"4px",borderRadius:"4px",height:"32px",display:"flex",alignItems:"center",justifyContent:"right",width:"100%"},deviceItems:{}},x={deviceList:a?{...L.deviceList,...a.deviceList}:L.deviceList,label:a?{...L.label,...a.label}:L.label,select:a?{...L.select,...a.select}:L.select,deviceItems:a?{...L.deviceItems,...a.deviceItems}:L.deviceItems};return e.createElement("div",{style:x.deviceList},e.createElement("label",{style:x.label,htmlFor:H},g),e.createElement("select",{style:x.select,id:H,onChange:C,defaultValue:D?.deviceId},s.map((E,i)=>e.createElement(y,{style:x.deviceItems,value:E.deviceId,name:E.label,key:i}))))},_=({children:s,disabled:g,style:D,onClick:a})=>{const r={borderRadius:"4px",height:"32px",paddingLeft:"16px",paddingRight:"16px",backgroundColor:"white",borderWidth:"1px"},C=D?{...r,...D}:r;return e.createElement("button",{onClick:a,disabled:g,style:C},s)},R=({isSelectAudioInput:s=!0,isSelectAudioOutput:g=!0,isSelectVideoInput:D=!0,open:a,audioInputDeviceLabel:r="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:H="video input device",confirmButtonText:L="Confirm",cancelButtonText:x="Cancel",allowOutsideClick:E=!0,style:i,onDeviceSelected:t,onDeviceSelectCanceled:$})=>{const[B,I]=X(),[S,O]=e.useState(),[W,M]=e.useState(),[V,G]=e.useState(),Q=B.filter(v=>v.kind==="audioinput"),F=B.filter(v=>v.kind==="audiooutput"),T=B.filter(v=>v.kind==="videoinput"),c={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px",minWidth:"270px"},deviceLists:{display:"grid"},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[f,h]=e.useState({background:i?{...c.background,...i.background}:c.background,modal:i?{...c.modal,...i.modal}:c.modal,deviceLists:i?{...c.deviceLists,...i.deviceLists}:c.deviceLists,audioInputDeviceList:i?{...c.audioInputDeviceList,...i.audioInputDeviceList}:{},audioOutputDeviceList:i?{...c.audioOutputDeviceList,...i.audioOutputDeviceList}:{},videoInputDeviceList:i?{...c.videoInputDeviceList,...i.videoInputDeviceList}:{},buttons:i?{...c.buttons,...i.buttons}:c.buttons,cancelButton:i?{...c.cancelButton,...i.cancelButton}:c.cancelButton,confirmButton:i?{...c.confirmButton,...i.confirmButton}:c.confirmButton});e.useEffect(()=>{h({background:i?{...c.background,...i.background}:c.background,modal:i?{...c.modal,...i.modal}:c.modal,deviceLists:i?{...c.deviceLists,...i.deviceLists}:c.deviceLists,audioInputDeviceList:i?{...c.audioInputDeviceList,...i.audioInputDeviceList}:{},audioOutputDeviceList:i?{...c.audioOutputDeviceList,...i.audioOutputDeviceList}:{},videoInputDeviceList:i?{...c.videoInputDeviceList,...i.videoInputDeviceList}:{},buttons:i?{...c.buttons,...i.buttons}:c.buttons,cancelButton:i?{...c.cancelButton,...i.cancelButton}:c.cancelButton,confirmButton:i?{...c.confirmButton,...i.confirmButton}:c.confirmButton})},[i]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",I),I()):navigator.mediaDevices.removeEventListener("devicechange",I)},[a]);const p=()=>{t({audioInput:S!==void 0?S:Q[0],audioOutput:W!==void 0?W:F[0],videoInput:V!==void 0?V:T[0]})},q=()=>{$()},d=v=>{O(Q.find(k=>k.deviceId===v))},l=v=>{M(F.find(k=>k.deviceId===v))},U=v=>{G(T.find(k=>k.deviceId===v))},z=()=>{$()};return a?e.createElement("div",{style:f.background,...E?{onClick:z}:{}},e.createElement("div",{style:f.modal,...E?{onClick:v=>v.stopPropagation()}:{}},e.createElement("div",{style:f.deviceLists},s&&e.createElement(j,{style:f?.audioInputDeviceList,label:r,devices:Q,selectedDevice:S,onChange:d}),g&&e.createElement(j,{style:f?.audioOutputDeviceList,label:C,devices:F,selectedDevice:W,onChange:l}),D&&e.createElement(j,{style:f?.videoInputDeviceList,label:H,devices:T,selectedDevice:V,onChange:U})),e.createElement("div",{style:f.buttons},e.createElement(_,{style:f.cancelButton,onClick:q},x),e.createElement(_,{style:f.confirmButton,onClick:p},L)))):e.createElement(e.Fragment,null)},Z=()=>{const[s,g]=e.useState();return e.useEffect(()=>()=>{s!==void 0&&s.getTracks().forEach(r=>r.stop())},[]),[s,r=>{r.kind!=="audiooutput"&&(async()=>{const C=await navigator.mediaDevices.getUserMedia(r.kind==="audioinput"?{video:!1,audio:{deviceId:r.deviceId}}:{video:{deviceId:r.deviceId},audio:!1});g(C)})()},()=>{s!==void 0&&(s.getTracks().forEach(r=>r.stop()),g(void 0))}]},P=({isSelectAudioInput:s=!0,isSelectAudioOutput:g=!0,isSelectVideoInput:D=!0,open:a,audioInputDeviceLabel:r="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:H="video input device",confirmButtonText:L="Confirm",cancelButtonText:x="Cancel",allowOutsideClick:E=!0,style:i,onDeviceSelected:t,onDeviceSelectCanceled:$})=>{const[B,I]=X(),[S,O]=e.useState(),[W,M]=e.useState(),[V,G]=e.useState(),[Q,F,T]=Z(),c=e.useRef(null),f=e.useMemo(()=>B.filter(o=>o.kind==="audioinput"),[B]),h=e.useMemo(()=>B.filter(o=>o.kind==="audiooutput"),[B]),p=e.useMemo(()=>B.filter(o=>o.kind==="videoinput"),[B]),q=matchMedia("(max-width: 640px)"),d={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px"},deviceSelectContainer:q.matches?{display:"grid",gridTemplateColumns:"100%"}:{display:"grid",gridTemplateColumns:"50% 50%"},preview:{minWidth:"270px",minHeight:"180px",maxWidth:"270px",maxHeight:"180px",marginRight:"4px"},previewVideo:{width:"270px",height:"180px"},deviceLists:{display:"grid",minWidth:"270px",marginLeft:"8px"},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[l,U]=e.useState({background:i?{...d.background,...i.background}:d.background,modal:i?{...d.modal,...i.modal}:d.modal,deviceSelectContainer:i?{...d.deviceSelectContainer,...i.deviceSelectContainer}:d.deviceSelectContainer,preview:i?{...d.preview,...i.preview}:d.preview,previewVideo:i?{...d.previewVideo,...i.previewVideo}:d.previewVideo,deviceLists:i?{...d.deviceLists,...i.deviceLists}:d.deviceLists,audioInputDeviceList:i?{...d.audioInputDeviceList,...i.audioInputDeviceList}:d.audioInputDeviceList,audioOutputDeviceList:i?{...d.audioOutputDeviceList,...i.audioOutputDeviceList}:d.audioOutputDeviceList,videoInputDeviceList:i?{...d.videoInputDeviceList,...i.videoInputDeviceList}:d.videoInputDeviceList,buttons:i?{...d.buttons,...i.buttons}:d.buttons,cancelButton:i?{...d.cancelButton,...i.cancelButton}:d.cancelButton,confirmButton:i?{...d.confirmButton,...i.confirmButton}:d.confirmButton});e.useEffect(()=>{U({background:i?{...d.background,...i.background}:d.background,modal:i?{...d.modal,...i.modal}:d.modal,deviceSelectContainer:i?{...d.deviceSelectContainer,...i.deviceSelectContainer}:d.deviceSelectContainer,preview:i?{...d.preview,...i.preview}:d.preview,previewVideo:i?{...d.previewVideo,...i.previewVideo}:d.previewVideo,deviceLists:i?{...d.deviceLists,...i.deviceLists}:d.deviceLists,audioInputDeviceList:i?{...d.audioInputDeviceList,...i.audioInputDeviceList}:d.audioInputDeviceList,audioOutputDeviceList:i?{...d.audioOutputDeviceList,...i.audioOutputDeviceList}:d.audioOutputDeviceList,videoInputDeviceList:i?{...d.videoInputDeviceList,...i.videoInputDeviceList}:d.videoInputDeviceList,buttons:i?{...d.buttons,...i.buttons}:d.buttons,cancelButton:i?{...d.cancelButton,...i.cancelButton}:d.cancelButton,confirmButton:i?{...d.confirmButton,...i.confirmButton}:d.confirmButton})},[i]),e.useEffect(()=>{const o=()=>{q.matches?U({...l,deviceSelectContainer:{display:"grid",gridTemplateColumns:"100%"}}):U({...l,deviceSelectContainer:{display:"grid",gridTemplateColumns:"50% 50%"}})};return q.addEventListener("change",o),()=>{q.removeEventListener("change",o)}},[]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",I),I()):navigator.mediaDevices.removeEventListener("devicechange",I)},[a]),e.useEffect(()=>{if(p.length<1)return;const o=p.find(w=>w.deviceId===V?.deviceId)??p[0];F(o)},[p]);const z=()=>{T(),t({audioInput:S!==void 0?S:f[0],audioOutput:W!==void 0?W:h[0],videoInput:V!==void 0?V:p[0]})},v=()=>{T(),$()},k=o=>{O(f.find(w=>w.deviceId===o))},n=o=>{M(h.find(w=>w.deviceId===o))},m=o=>{const w=p.find(Y=>Y.deviceId===o);G(w),F(w)};e.useEffect(()=>{const{current:o}=c;o&&(o.srcObject!==null&&o.srcObject instanceof MediaStream&&(o.srcObject.getTracks().forEach(w=>w.stop()),o.pause()),o.srcObject=Q,o.play())},[Q]);const K=()=>{T(),$()};return a?e.createElement("div",{style:l.background,...E?{onClick:K}:{}},e.createElement("div",{style:l.modal,...E?{onClick:o=>o.stopPropagation()}:{}},e.createElement("div",{style:l.deviceSelectContainer},e.createElement("div",{style:l.preview},e.createElement("video",{style:l.previewVideo,ref:c,autoPlay:!0,muted:!0,playsInline:!0})),e.createElement("div",{style:l.deviceLists},s&&e.createElement(j,{style:l.audioInputDeviceList,label:r,devices:f,selectedDevice:S,onChange:k}),g&&e.createElement(j,{style:l?.audioOutputDeviceList,label:C,devices:h,selectedDevice:W,onChange:n}),D&&e.createElement(j,{style:l?.videoInputDeviceList,label:H,devices:p,selectedDevice:V,onChange:m}))),e.createElement("div",{style:l.buttons},e.createElement(_,{style:l.cancelButton,onClick:v},x),e.createElement(_,{style:l.confirmButton,onClick:z},L)))):e.createElement(e.Fragment,null)},ee=({isSelectAudioInput:s=!0,isSelectAudioOutput:g=!0,isSelectVideoInput:D=!0,open:a,audioInputDeviceLabel:r="audio input device",audioOutputDeviceLabel:C="audio output device",videoInputDeviceLabel:H="video input device",confirmButtonText:L="Confirm",cancelButtonText:x="Cancel",recordingButtonText:E="Recording",allowOutsideClick:i=!0,style:t,onDeviceSelected:$,onDeviceSelectCanceled:B})=>{const[I,S]=X(),[O,W]=e.useState(),[M,V]=e.useState(),[G,Q]=e.useState(),[F,T,c]=Z(),f=e.useRef(null),h=e.useRef(null),[p,q]=e.useState(),[d,l]=e.useState(!1),U=e.useMemo(()=>I.filter(u=>u.kind==="audioinput"),[I]),z=e.useMemo(()=>I.filter(u=>u.kind==="audiooutput"),[I]),v=e.useMemo(()=>I.filter(u=>u.kind==="videoinput"),[I]),k=matchMedia("(max-width: 640px)"),n={background:{position:"fixed",top:0,left:0,width:"100%",height:"100%",backgroundColor:"rgba(0, 0, 0, 0.3)",display:"flex",alignItems:"center",justifyContent:"center"},modal:{background:"white",padding:"16px",borderRadius:"8px"},deviceSelectContainer:k.matches?{display:"grid",gridTemplateColumns:"100%"}:{display:"grid",gridTemplateColumns:"50% 50%"},preview:{minWidth:"270px",minHeight:"180px",maxWidth:"270px",marginRight:"4px"},previewVideo:{width:"270px",height:"180px"},previewAudio:{width:"270px"},deviceLists:{display:"grid",minWidth:"270px",marginLeft:"8px"},recordingButtons:{},recordingButton:{},audioInputDeviceList:{},audioOutputDeviceList:{},videoInputDeviceList:{},buttons:{paddingTop:"16px",display:"flex",alignItems:"center",justifyContent:"right"},cancelButton:{},confirmButton:{marginLeft:"4px"}},[m,K]=e.useState({background:t?{...n.background,...t.background}:n.background,modal:t?{...n.modal,...t.modal}:n.modal,deviceSelectContainer:t?{...n.deviceSelectContainer,...t.deviceSelectContainer}:n.deviceSelectContainer,preview:t?{...n.preview,...t.preview}:n.preview,previewVideo:t?{...n.previewVideo,...t.previewVideo}:n.previewVideo,previewAudio:t?{...n.previewAudio,...t.previewAudio}:n.previewAudio,deviceLists:t?{...n.deviceLists,...t.deviceLists}:n.deviceLists,recordingButtons:t?{...n.recordingButtons,...t.recordingButtons}:n.recordingButtons,recordingButton:t?{...n.recordingButton,...t.recordingButton}:n.recordingButton,audioInputDeviceList:t?{...n.audioInputDeviceList,...t.audioInputDeviceList}:n.audioInputDeviceList,audioOutputDeviceList:t?{...n.audioOutputDeviceList,...t.audioOutputDeviceList}:n.audioOutputDeviceList,videoInputDeviceList:t?{...n.videoInputDeviceList,...t.videoInputDeviceList}:n.videoInputDeviceList,buttons:t?{...n.buttons,...t.buttons}:n.buttons,cancelButton:t?{...n.cancelButton,...t.cancelButton}:n.cancelButton,confirmButton:t?{...n.confirmButton,...t.confirmButton}:n.confirmButton});e.useEffect(()=>{K({background:t?{...n.background,...t.background}:n.background,modal:t?{...n.modal,...t.modal}:n.modal,deviceSelectContainer:t?{...n.deviceSelectContainer,...t.deviceSelectContainer}:n.deviceSelectContainer,preview:t?{...n.preview,...t.preview}:n.preview,previewVideo:t?{...n.previewVideo,...t.previewVideo}:n.previewVideo,previewAudio:t?{...n.previewAudio,...t.previewAudio}:n.previewAudio,deviceLists:t?{...n.deviceLists,...t.deviceLists}:n.deviceLists,recordingButtons:t?{...n.recordingButtons,...t.recordingButtons}:n.recordingButtons,recordingButton:t?{...n.recordingButton,...t.recordingButton}:n.recordingButton,audioInputDeviceList:t?{...n.audioInputDeviceList,...t.audioInputDeviceList}:n.audioInputDeviceList,audioOutputDeviceList:t?{...n.audioOutputDeviceList,...t.audioOutputDeviceList}:n.audioOutputDeviceList,videoInputDeviceList:t?{...n.videoInputDeviceList,...t.videoInputDeviceList}:n.videoInputDeviceList,buttons:t?{...n.buttons,...t.buttons}:n.buttons,cancelButton:t?{...n.cancelButton,...t.cancelButton}:n.cancelButton,confirmButton:t?{...n.confirmButton,...t.confirmButton}:n.confirmButton})},[t]),e.useEffect(()=>{const u=()=>{k.matches?K({...m,deviceSelectContainer:{display:"grid",gridTemplateColumns:"100%"}}):K({...m,deviceSelectContainer:{display:"grid",gridTemplateColumns:"50% 50%"}})};return k.addEventListener("change",u),()=>{k.removeEventListener("change",u)}},[]),e.useEffect(()=>{a?(navigator.mediaDevices.addEventListener("devicechange",S),S()):navigator.mediaDevices.removeEventListener("devicechange",S)},[a]),e.useEffect(()=>{if(v.length<1)return;const u=v.find(b=>b.deviceId===G?.deviceId)??v[0];T(u)},[v]);const o=()=>{!p||!h||(p.state==="recording"&&(p.removeEventListener("dataavailable",()=>{}),p.removeEventListener("stop",()=>{}),p.stop(),p.stream.getTracks().forEach(u=>u.stop())),h.current.src="",h.current.pause(),c())},w=()=>{o(),$({audioInput:O!==void 0?O:U[0],audioOutput:M!==void 0?M:z[0],videoInput:G!==void 0?G:v[0]})},Y=()=>{o(),B()},ie=u=>{W(U.find(b=>b.deviceId===u))},te=async u=>{V(z.find(b=>b.deviceId===u)),await h.current.setSinkId(u)},ne=u=>{const b=v.find(J=>J.deviceId===u);Q(b),T(b)},de=async()=>{const u=await navigator.mediaDevices.getUserMedia({audio:O&&O.deviceId!==""?{deviceId:O.deviceId}:!0,video:!1});let b=[];const J=new MediaRecorder(u);J.addEventListener("dataavailable",N=>{b.push(N.data)}),J.addEventListener("stop",async N=>{if(l(!1),!h.current)return;const ue=new Blob(b,{type:"audio/ogg; codecs=opus"});b=[];const oe=URL.createObjectURL(ue);h.current.src=oe,M&&M.deviceId!==""&&await h.current.setSinkId(M.deviceId)}),J.start(),q(J),l(!0),setTimeout(()=>{J.stop(),u.getTracks().forEach(N=>N.stop())},5e3)};e.useEffect(()=>{const{current:u}=f;u&&(u.srcObject!==null&&u.srcObject instanceof MediaStream&&(u.srcObject.getTracks().forEach(b=>b.stop()),u.pause()),u.srcObject=F,u.play())},[F]);const ce=()=>{o(),B()};return a?e.createElement("div",{style:m.background,...i?{onClick:ce}:{}},e.createElement("div",{style:m.modal,...i?{onClick:u=>u.stopPropagation()}:{}},e.createElement("div",{style:m.deviceSelectContainer},e.createElement("div",{style:m.preview},e.createElement("video",{style:m.previewVideo,ref:f,autoPlay:!0,muted:!0,playsInline:!0}),e.createElement("audio",{style:m.previewAudio,ref:h,autoPlay:!0,playsInline:!0,controls:!0})),e.createElement("div",{style:m.deviceLists},s&&e.createElement(e.Fragment,null,e.createElement(j,{style:m.audioInputDeviceList,label:r,devices:U,selectedDevice:O,onChange:ie}),e.createElement("div",{style:m.recordingButtons},e.createElement(_,{style:m.recordingButton,onClick:de,disabled:d},E))),g&&e.createElement(j,{style:m?.audioOutputDeviceList,label:C,devices:z,selectedDevice:M,onChange:te}),D&&e.createElement(j,{style:m?.videoInputDeviceList,label:H,devices:v,selectedDevice:G,onChange:ne}))),e.createElement("div",{style:m.buttons},e.createElement(_,{style:m.cancelButton,onClick:Y},x),e.createElement(_,{style:m.confirmButton,onClick:w},L)))):e.createElement(e.Fragment,null)};A.SelectMediaDevicesModal=R,A.SelectMediaDevicesPreviewModal=P,A.SelectMediaDevicesRecordingModal=ee,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- export declare const useGetMediaStream: () => [MediaStream, (device: MediaDeviceInfo) => void, () => void];
1
+ export declare const useGetMediaStream: () => [MediaStream | undefined, (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.2.1",
4
+ "version": "1.2.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -41,29 +41,27 @@
41
41
  "test:e2e:watch": "vitest watch -c vitest.e2e.config.ts"
42
42
  },
43
43
  "dependencies": {
44
- "react": "^18.2.0",
45
- "react-dom": "^18.2.0",
46
- "react-router-dom": "^6.14.0"
44
+ "react": "^19.0.0",
45
+ "react-dom": "^19.0.0",
46
+ "react-router-dom": "^7.0.1"
47
47
  },
48
48
  "devDependencies": {
49
- "@mdx-js/react": "^3.0.1",
50
49
  "@playwright/test": "^1.35.1",
51
- "@rollup/plugin-typescript": "^11.1.1",
50
+ "@rollup/plugin-typescript": "^12.1.0",
52
51
  "@testing-library/jest-dom": "^6.4.6",
53
52
  "@testing-library/react": "^16.0.0",
54
53
  "@testing-library/user-event": "^14.4.3",
55
- "@types/node": "^22.0.0",
56
- "@types/react": "^18.2.14",
57
- "@vitejs/plugin-react": "^4.0.1",
58
- "@vitest/coverage-v8": "^2.0.0",
59
- "@vitest/ui": "^2.0.0",
60
- "jsdom": "^25.0.0",
54
+ "@types/node": "^24.1.0",
55
+ "@types/react": "^19.0.1",
56
+ "@vitejs/plugin-react": "^5.0.2",
57
+ "@vitest/coverage-v8": "^4.0.6",
58
+ "@vitest/ui": "^4.0.6",
59
+ "jsdom": "^27.0.0",
61
60
  "playwright": "^1.35.1",
62
- "rimraf": "^6.0.1",
63
- "serve": "^14.2.0",
64
- "vite": "^5.3.1",
65
- "vite-pages-theme-doc": "^5.0.0",
66
- "vite-plugin-react-pages": "^5.0.0",
67
- "vitest": "^2.0.0"
61
+ "vite": "^7.0.6",
62
+ "vitest": "^4.0.6"
63
+ },
64
+ "peerDependencies": {
65
+ "tslib": "^2.8.1"
68
66
  }
69
67
  }