react-select-media-devices-modal 0.0.1 → 0.0.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.
- package/dist/react-select-media-devices-modal.mjs +94 -0
- package/dist/react-select-media-devices-modal.umd.js +1 -0
- package/dist/style.css +1 -0
- package/dist/types/SelectMediaDevicesModal/components/button/index.d.ts +8 -0
- package/dist/types/SelectMediaDevicesModal/components/deviceItem/index.d.ts +7 -0
- package/dist/types/SelectMediaDevicesModal/components/deviceList/index.d.ts +8 -0
- package/dist/types/SelectMediaDevicesModal/hooks/getDevices.d.ts +1 -0
- package/dist/types/SelectMediaDevicesModal/index.d.ts +21 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +10 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import e, { useState as l, useEffect as w } from "react";
|
|
2
|
+
const G = "_background_a8nxk_1", P = "_modal_a8nxk_13", R = "_deviceLists_a8nxk_19", S = "_buttons_a8nxk_23", T = "_chancelButton_a8nxk_30", U = "_confirmButton_a8nxk_32", o = {
|
|
3
|
+
background: G,
|
|
4
|
+
modal: P,
|
|
5
|
+
deviceLists: R,
|
|
6
|
+
buttons: S,
|
|
7
|
+
chancelButton: T,
|
|
8
|
+
confirmButton: U
|
|
9
|
+
}, q = () => {
|
|
10
|
+
const [n, c] = l([]);
|
|
11
|
+
return [n, () => {
|
|
12
|
+
(async () => {
|
|
13
|
+
const s = await navigator.mediaDevices.getUserMedia({ audio: !0, video: !0 }), i = await navigator.mediaDevices.enumerateDevices();
|
|
14
|
+
c(i), s.getTracks().forEach((u) => u.stop());
|
|
15
|
+
})();
|
|
16
|
+
}];
|
|
17
|
+
}, z = ({ name: n, value: c }) => /* @__PURE__ */ e.createElement("option", { value: c }, n), g = ({ devices: n, label: c, onChange: a }) => {
|
|
18
|
+
if (n === void 0)
|
|
19
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
20
|
+
const s = (i) => {
|
|
21
|
+
a(i.target.value);
|
|
22
|
+
};
|
|
23
|
+
return /* @__PURE__ */ e.createElement(e.Fragment, null, /* @__PURE__ */ e.createElement("label", { htmlFor: "device-select" }, c), /* @__PURE__ */ e.createElement("select", { name: "device-select", onChange: s }, n.map((i, u) => /* @__PURE__ */ e.createElement(z, { value: i.deviceId, name: i.label, key: u }))));
|
|
24
|
+
}, _ = ({ className: n, children: c, onClick: a }) => /* @__PURE__ */ e.createElement("button", { onClick: a, className: [n].filter(Boolean).join(" ") }, c), J = ({
|
|
25
|
+
isSelectAudioInput: n = !0,
|
|
26
|
+
isSelectAudioOutput: c = !0,
|
|
27
|
+
isSelectVideoInput: a = !0,
|
|
28
|
+
open: s,
|
|
29
|
+
audioInputDeviceLabel: i = "audio input device",
|
|
30
|
+
audioOutputDeviceLabel: u = "audio output device",
|
|
31
|
+
videoInputDeviceLabel: C = "video input device",
|
|
32
|
+
ConfirmButtonText: I = "Confirm",
|
|
33
|
+
CancelButtonText: b = "Cancel",
|
|
34
|
+
allowOutsideClick: D = !0,
|
|
35
|
+
onDeviceSelected: B,
|
|
36
|
+
onDeviceSelectCanceled: k
|
|
37
|
+
}) => {
|
|
38
|
+
const [r, x] = q(), [h, N] = l(), [E, L] = l(), [f, O] = l(), v = r.filter((t) => t.kind === "audioinput"), m = r.filter((t) => t.kind === "audiooutput"), p = r.filter((t) => t.kind === "videoinput");
|
|
39
|
+
w(() => {
|
|
40
|
+
x();
|
|
41
|
+
}, []);
|
|
42
|
+
const A = () => {
|
|
43
|
+
B({
|
|
44
|
+
audioInput: h !== void 0 ? h : v[0],
|
|
45
|
+
audioOutput: E !== void 0 ? E : m[0],
|
|
46
|
+
videoInput: f !== void 0 ? f : p[0]
|
|
47
|
+
});
|
|
48
|
+
}, F = () => {
|
|
49
|
+
k();
|
|
50
|
+
}, M = (t) => {
|
|
51
|
+
N(v.find((d) => d.deviceId === t));
|
|
52
|
+
}, y = (t) => {
|
|
53
|
+
L(m.find((d) => d.deviceId === t));
|
|
54
|
+
}, V = (t) => {
|
|
55
|
+
O(p.find((d) => d.deviceId === t));
|
|
56
|
+
}, j = () => {
|
|
57
|
+
k();
|
|
58
|
+
};
|
|
59
|
+
return s ? /* @__PURE__ */ e.createElement("div", { className: o.background, ...D ? { onClick: j } : {} }, /* @__PURE__ */ e.createElement(
|
|
60
|
+
"div",
|
|
61
|
+
{
|
|
62
|
+
className: o.modal,
|
|
63
|
+
...D ? {
|
|
64
|
+
onClick: (t) => t.stopPropagation()
|
|
65
|
+
} : {}
|
|
66
|
+
},
|
|
67
|
+
/* @__PURE__ */ e.createElement("div", { className: o.deviceLists }, n && /* @__PURE__ */ e.createElement(
|
|
68
|
+
g,
|
|
69
|
+
{
|
|
70
|
+
label: i,
|
|
71
|
+
devices: v,
|
|
72
|
+
onChange: M
|
|
73
|
+
}
|
|
74
|
+
), c && /* @__PURE__ */ e.createElement(
|
|
75
|
+
g,
|
|
76
|
+
{
|
|
77
|
+
label: u,
|
|
78
|
+
devices: m,
|
|
79
|
+
onChange: y
|
|
80
|
+
}
|
|
81
|
+
), a && /* @__PURE__ */ e.createElement(
|
|
82
|
+
g,
|
|
83
|
+
{
|
|
84
|
+
label: C,
|
|
85
|
+
devices: p,
|
|
86
|
+
onChange: V
|
|
87
|
+
}
|
|
88
|
+
)),
|
|
89
|
+
/* @__PURE__ */ e.createElement("div", { className: o.buttons }, /* @__PURE__ */ e.createElement(_, { className: o.cancelButton, onClick: F }, b), /* @__PURE__ */ e.createElement(_, { className: o.confirmButton, onClick: A }, I))
|
|
90
|
+
)) : /* @__PURE__ */ e.createElement(e.Fragment, null);
|
|
91
|
+
};
|
|
92
|
+
export {
|
|
93
|
+
J as SelectMediaDevicesModal
|
|
94
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(c,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],e):(c=typeof globalThis<"u"?globalThis:c||self,e(c.ReactSelectMediaDevicesModal={},c.React))})(this,function(c,e){"use strict";const s={background:"_background_a8nxk_1",modal:"_modal_a8nxk_13",deviceLists:"_deviceLists_a8nxk_19",buttons:"_buttons_a8nxk_23",chancelButton:"_chancelButton_a8nxk_30",confirmButton:"_confirmButton_a8nxk_32"},_=()=>{const[n,i]=e.useState([]);return[n,()=>{(async()=>{const u=await navigator.mediaDevices.getUserMedia({audio:!0,video:!0}),o=await navigator.mediaDevices.enumerateDevices();i(o),u.getTracks().forEach(d=>d.stop())})()}]},C=({name:n,value:i})=>e.createElement("option",{value:i},n),r=({devices:n,label:i,onChange:a})=>{if(n===void 0)return e.createElement(e.Fragment,null);const u=o=>{a(o.target.value)};return e.createElement(e.Fragment,null,e.createElement("label",{htmlFor:"device-select"},i),e.createElement("select",{name:"device-select",onChange:u},n.map((o,d)=>e.createElement(C,{value:o.deviceId,name:o.label,key:d}))))},g=({className:n,children:i,onClick:a})=>e.createElement("button",{onClick:a,className:[n].filter(Boolean).join(" ")},i),I=({isSelectAudioInput:n=!0,isSelectAudioOutput:i=!0,isSelectVideoInput:a=!0,open:u,audioInputDeviceLabel:o="audio input device",audioOutputDeviceLabel:d="audio output device",videoInputDeviceLabel:B="video input device",ConfirmButtonText:x="Confirm",CancelButtonText:M="Cancel",allowOutsideClick:h=!0,onDeviceSelected:S,onDeviceSelectCanceled:D})=>{const[v,L]=_(),[k,N]=e.useState(),[E,y]=e.useState(),[b,O]=e.useState(),m=v.filter(t=>t.kind==="audioinput"),p=v.filter(t=>t.kind==="audiooutput"),f=v.filter(t=>t.kind==="videoinput");e.useEffect(()=>{L()},[]);const A=()=>{S({audioInput:k!==void 0?k:m[0],audioOutput:E!==void 0?E:p[0],videoInput:b!==void 0?b:f[0]})},F=()=>{D()},T=t=>{N(m.find(l=>l.deviceId===t))},j=t=>{y(p.find(l=>l.deviceId===t))},P=t=>{O(f.find(l=>l.deviceId===t))},V=()=>{D()};return u?e.createElement("div",{className:s.background,...h?{onClick:V}:{}},e.createElement("div",{className:s.modal,...h?{onClick:t=>t.stopPropagation()}:{}},e.createElement("div",{className:s.deviceLists},n&&e.createElement(r,{label:o,devices:m,onChange:T}),i&&e.createElement(r,{label:d,devices:p,onChange:j}),a&&e.createElement(r,{label:B,devices:f,onChange:P})),e.createElement("div",{className:s.buttons},e.createElement(g,{className:s.cancelButton,onClick:F},M),e.createElement(g,{className:s.confirmButton,onClick:A},x)))):e.createElement(e.Fragment,null)};c.SelectMediaDevicesModal=I,Object.defineProperty(c,Symbol.toStringTag,{value:"Module"})});
|
package/dist/style.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
._background_a8nxk_1{position:fixed;top:0;left:0;width:100%;height:100%;background-color:#0000004d;display:flex;align-items:center;justify-content:center}._modal_a8nxk_13{background:white;padding:16px;border-radius:8px}._deviceLists_a8nxk_19{display:grid}._buttons_a8nxk_23{padding-top:8px;display:flex;align-items:center;justify-content:right}._confirmButton_a8nxk_32{margin-left:4px}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface DeviceListProps {
|
|
3
|
+
devices: MediaDeviceInfo[];
|
|
4
|
+
label: string;
|
|
5
|
+
onChange: (deviceId: string) => void;
|
|
6
|
+
}
|
|
7
|
+
declare const DeviceList: ({ devices, label, onChange }: DeviceListProps) => JSX.Element;
|
|
8
|
+
export default DeviceList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useGetDevices: () => [MediaDeviceInfo[], () => void];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
interface SelectMediaDevicesModalProps {
|
|
3
|
+
isSelectAudioInput: boolean;
|
|
4
|
+
isSelectAudioOutput: boolean;
|
|
5
|
+
isSelectVideoInput: boolean;
|
|
6
|
+
open: boolean;
|
|
7
|
+
audioInputDeviceLabel: string;
|
|
8
|
+
audioOutputDeviceLabel: string;
|
|
9
|
+
videoInputDeviceLabel: string;
|
|
10
|
+
ConfirmButtonText: string;
|
|
11
|
+
CancelButtonText: string;
|
|
12
|
+
allowOutsideClick: boolean;
|
|
13
|
+
onDeviceSelected: (devices: {
|
|
14
|
+
audioInput?: MediaDeviceInfo;
|
|
15
|
+
audioOutput?: MediaDeviceInfo;
|
|
16
|
+
videoInput?: MediaDeviceInfo;
|
|
17
|
+
}) => void;
|
|
18
|
+
onDeviceSelectCanceled: () => void;
|
|
19
|
+
}
|
|
20
|
+
declare const SelectMediaDevicesModal: ({ isSelectAudioInput, isSelectAudioOutput, isSelectVideoInput, open, audioInputDeviceLabel, audioOutputDeviceLabel, videoInputDeviceLabel, ConfirmButtonText, CancelButtonText, allowOutsideClick, onDeviceSelected, onDeviceSelectCanceled, }: SelectMediaDevicesModalProps) => JSX.Element;
|
|
21
|
+
export default SelectMediaDevicesModal;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as SelectMediaDevicesModal } from './SelectMediaDevicesModal';
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-select-media-devices-modal",
|
|
3
3
|
"description": "A React component library for select media devices",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
|
+
"license": "MIT",
|
|
5
6
|
"main": "./dist/react-select-media-devices-modal.umd.js",
|
|
6
7
|
"module": "./dist/react-select-media-devices-modal.mjs",
|
|
7
8
|
"types": "./dist/types/index.d.ts",
|
|
@@ -15,6 +16,14 @@
|
|
|
15
16
|
"files": [
|
|
16
17
|
"dist"
|
|
17
18
|
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"react",
|
|
21
|
+
"modal",
|
|
22
|
+
"compoennt",
|
|
23
|
+
"mediadevices",
|
|
24
|
+
"getusermedia",
|
|
25
|
+
"enumeratedevices"
|
|
26
|
+
],
|
|
18
27
|
"scripts": {
|
|
19
28
|
"dev": "vite serve example",
|
|
20
29
|
"build": "vite build"
|