Coder Social home page Coder Social logo

kadoshita / react-select-media-devices-modal Goto Github PK

View Code? Open in Web Editor NEW
10.0 3.0 2.0 1.35 MB

A React component library for select media devices

Home Page: https://kadoshita.github.io/react-select-media-devices-modal/

License: MIT License

JavaScript 4.77% HTML 0.31% TypeScript 94.92%
component getusermedia mediadevices react enumeratedevices webrtc

react-select-media-devices-modal's Introduction

react-select-media-devices-modal

npm version Test E2E Test Release Deploy to GitHub Pages License: MIT

A React component library for select media devices.

Features

  • Select audio input, audio output, and video input device.
  • Show preview media stream get from selected device.
  • Record sample audio stream and play.

Demo

https://kadoshita.github.io/react-select-media-devices-modal/example/

Installation

npm install --save react-select-media-devices-modal

Usage

SelectMediaDevicesModal

import { useState } from 'react';
import { SelectMediaDevicesModal } from 'react-select-media-devices-modal';

function App() {
    const [modalOpen, setModalOpen] = useState(false);

    const handleDeviceSelected = (devices) => {
        setModalOpen(false);
        console.log(devices);
    };

    const handleDeviceSelectCanceled = () => {
        setModalOpen(false);
    };

    return (
        <div>
            <button onClick={() => setModalOpen((current) => !current)}>Select Device</button>
            <SelectMediaDevicesModal
                isSelectAudioInput
                isSelectAudioOutput
                isSelectVideoInput
                open={modalOpen}
                audioInputDeviceLabel="Audio input device"
                audioOutputDeviceLabel="Audio output device"
                videoInputDeviceLabel="Video input device"
                confirmButtonText="Confirm"
                cancelButtonText="Cancel"
                allowOutsideClick={false}
                onDeviceSelected={handleDeviceSelected}
                onDeviceSelectCanceled={handleDeviceSelectCanceled}
            ></SelectMediaDevicesModal>
        </div>
    );
}

export default App;

SelectMediaDevicesPreviewModal

import { useState } from 'react';
import { SelectMediaDevicesPreviewModal } from 'react-select-media-devices-modal';

function App() {
    const [modalOpen, setModalOpen] = useState(false);

    const handleDeviceSelected = (devices) => {
        setModalOpen(false);
        console.log(devices);
    };

    const handleDeviceSelectCanceled = () => {
        setModalOpen(false);
    };

    return (
        <div>
            <button onClick={() => setModalOpen((current) => !current)}>Select Device</button>
            <SelectMediaDevicesPreviewModal
                isSelectAudioInput
                isSelectAudioOutput
                isSelectVideoInput
                open={modalOpen}
                audioInputDeviceLabel="Audio input device"
                audioOutputDeviceLabel="Audio output device"
                videoInputDeviceLabel="Video input device"
                confirmButtonText="Confirm"
                cancelButtonText="Cancel"
                allowOutsideClick={false}
                onDeviceSelected={handleDeviceSelected}
                onDeviceSelectCanceled={handleDeviceSelectCanceled}
            ></SelectMediaDevicesPreviewModal>
        </div>
    );
}

export default App;

SelectMediaDevicesRecordingModal

import { useState } from 'react';
import { SelectMediaDevicesRecordingModal } from 'react-select-media-devices-modal';

function App() {
    const [modalOpen, setModalOpen] = useState(false);

    const handleDeviceSelected = (devices) => {
        setModalOpen(false);
        console.log(devices);
    };

    const handleDeviceSelectCanceled = () => {
        setModalOpen(false);
    };

    return (
        <div>
            <button onClick={() => setModalOpen((current) => !current)}>Select Device</button>
            <SelectMediaDevicesRecordingModal
                isSelectAudioInput
                isSelectAudioOutput
                isSelectVideoInput
                open={modalOpen}
                audioInputDeviceLabel="Audio input device"
                audioOutputDeviceLabel="Audio output device"
                videoInputDeviceLabel="Video input device"
                confirmButtonText="Confirm"
                cancelButtonText="Cancel"
                recordingButtonText="Recording"
                allowOutsideClick={false}
                onDeviceSelected={handleDeviceSelected}
                onDeviceSelectCanceled={handleDeviceSelectCanceled}
            ></SelectMediaDevicesRecordingModal>
        </div>
    );
}

export default App;

Props

SelectMediaDevicesModalProps

Name Type Default Description
isSelectAudioInput boolean true Flag that select an audio input device or not.
isSelectAudioOutput boolean true Flag that select an audio output device or not.
isSelectVideoInput boolean true Flag that select a video input device or not.
open boolean false Flag that open the modal or not.
audioInputDeviceLabel string 'audio input device' Label for list of audio input devices.
audioOutputDeviceLabel string 'audio output device' Label for list of audio output devices.
videoInputDeviceLabel string 'video input device' Label for list of video input devices.
confirmButtonText string 'Confirm' Label for the confirm button.
cancelButtonText string 'Cancel' Label for the cancel button.
allowOutsideClick boolean true Flag that cancel selection when clicking outside of the modal.
onDeviceSelected function (devices: { audioInput?: MediaDeviceInfo; audioOutput?: MediaDeviceInfo; videoInput?: MediaDeviceInfo; }) => void Handler function called when devices are selected.
onDeviceSelectCanceled function () => void Handler function called when selection canceled.

SelectMediaDevicesPreviewModalProps

Name Type Default Description
isSelectAudioInput boolean true Flag that select an audio input device or not.
isSelectAudioOutput boolean true Flag that select an audio output device or not.
isSelectVideoInput boolean true Flag that select a video input device or not.
open boolean false Flag that open the modal or not.
audioInputDeviceLabel string 'audio input device' Label for list of audio input devices.
audioOutputDeviceLabel string 'audio output device' Label for list of audio output devices.
videoInputDeviceLabel string 'video input device' Label for list of video input devices.
confirmButtonText string 'Confirm' Label for the confirm button.
cancelButtonText string 'Cancel' Label for the cancel button.
allowOutsideClick boolean true Flag that cancel selection when clicking outside of the modal.
onDeviceSelected function (devices: { audioInput?: MediaDeviceInfo; audioOutput?: MediaDeviceInfo; videoInput?: MediaDeviceInfo; }) => void Handler function called when devices are selected.
onDeviceSelectCanceled function () => void Handler function called when selection canceled.

SelectMediaDevicesRecordingModalProps

Name Type Default Description
isSelectAudioInput boolean true Flag that select an audio input device or not.
isSelectAudioOutput boolean true Flag that select an audio output device or not.
isSelectVideoInput boolean true Flag that select a video input device or not.
open boolean false Flag that open the modal or not.
audioInputDeviceLabel string 'audio input device' Label for list of audio input devices.
audioOutputDeviceLabel string 'audio output device' Label for list of audio output devices.
videoInputDeviceLabel string 'video input device' Label for list of video input devices.
confirmButtonText string 'Confirm' Label for the confirm button.
cancelButtonText string 'Cancel' Label for the cancel button.
recordingButtonText string 'Recording' Label for the recording button.
allowOutsideClick boolean true Flag that cancel selection when clicking outside of the modal.
onDeviceSelected function (devices: { audioInput?: MediaDeviceInfo; audioOutput?: MediaDeviceInfo; videoInput?: MediaDeviceInfo; }) => void Handler function called when devices are selected.
onDeviceSelectCanceled function () => void Handler function called when selection canceled.

LICENSE

MIT

Author

Yoshiki Kadoshita

Contributors

react-select-media-devices-modal's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar kadoshita avatar kounoike avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

weiliy kounoike

react-select-media-devices-modal's Issues

プレビューするとアプリ側で開いたときに解像度がVGAになってしまう

プレビュー付きのSelectMediaDevicesPreviewModal/SelectMediaDevicesRecodingModalを開くと、プレビューがカメラをデフォルト設定で開いたままなのでアプリ側で制約をかけてもデフォルト設定のままとなってしまう。
(Windows/Chromeで確認、他の環境は確認してないです)

(準備)
#36 で追加したWebcamに width: 1920, height: 1080, などの制約を追加する

(手順)

  1. 2台以上のカメラを持つマシンで上記修正をしたexampleを開く
  2. SelectMediaDevicesPreviewModalボタンを押してモーダルを開く(~RecordingModalでも同じく)
  3. 2つ目以降のカメラを選択し、Confirmでモーダルを閉じる

こうするとアプリ側で表示している(Webcamコンポーネント)カメラの解像度がデフォルトのVGAのままとなってしまう。
手順3.で1つ目のカメラを選択した場合は、先にアプリ側で開いているため問題が発生しません。
また、手順2.でプレビューの無いSelectMediaDevicesModalを使うときちんと1920x1080で表示されます。

上記は解像度で試しましたが、フレームレートや最近追加さればbackground-blurとかもどうなるのか確認が必要な気がします

複数デバイスがあったときの2回目以降の選択で1つ目のデバイスを選んだときの結果がおかしい

CameraAとCameraBの2つがあったとき、

  1. モーダルを開く
  2. CameraBを選択する
  3. Confirmを押す
  4. モーダルを開く
  5. そのままConfirmを押す

と、モーダルではドロップダウンでCameraAが選択されているので、Confirmを押した時点でCameraAがinputDevicesのvideoInputになっていることを期待するが、実際にはCameraBになっている。
(例はvideoInputで説明したがaudioInput/audioOutputも同様)

どちらかというと4.の時点でモーダルを開いたときにCameraAが選択されている状態で開くより、CameraBが選択されていて欲しいです

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.