https://github.com/donavon/chime-devices
This package contains a React context provider and a hook around AWS Chime for capturing system audio and video devices.
https://github.com/donavon/chime-devices
audio aws aws-chime video
Last synced: 3 months ago
JSON representation
This package contains a React context provider and a hook around AWS Chime for capturing system audio and video devices.
- Host: GitHub
- URL: https://github.com/donavon/chime-devices
- Owner: donavon
- License: mit
- Created: 2020-08-18T18:42:10.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-20T18:52:21.000Z (almost 6 years ago)
- Last Synced: 2025-10-02T00:58:50.226Z (9 months ago)
- Topics: audio, aws, aws-chime, video
- Language: TypeScript
- Homepage:
- Size: 202 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @chime/devices
This package contains a React context provider and a hook around the [AWS Chime SDK](https://aws.amazon.com/chime/chime-sdk/). It allows you to get a list of audio/video devices and select a current device which it will keep in state.
## Install
This package has a peer dependency on `amazon-chime-sdk-js`.
You can install the package using npm like this.
```sh
$ npm i @chime/devices amazon-chime-sdk-js
```
or with Yarn.
```sh
$ yarn add @chime/devices amazon-chime-sdk-js
```
## Use in your code
### `ChimeDevicesProvider`
Wrap yout `` (or your components that will be using devices) in a `` as follows.
```jsx
```
Options props to `` include.
#### `deviceController`
This is an optional `DefaultDeviceController` object.
See [AWS Chime documentation](https://aws.github.io/amazon-chime-sdk-js/classes/defaultdevicecontroller.html) for more information.
You could pass a custom controller that has logging enabled, for example.
It's also used to mock during testing.
#### `initialAudioInputDeviceId`
The initial audio input device id (i.e. microphone) to use.
You could persist the user's choice and use this to initialize the selection.
If you don't specify an id, it will defaut to the first device in the list.
#### `initialAudioOutDeviceId`
The initial audio output device id (i.e. speaker) to use.
You could persist the user's choice and use this to initialize the selection.
If you don't specify an id, it will defaut to the first device in the list.
#### `initialVideoInputDeviceId`
The initial video input device id (i.e. camera) to use.
You could persist the user's choice and use this to initialize the selection.
If you don't specify an id, it will defaut to the first device in the list.
### `useChimeDevices`
You can call `useChimeDevices` in some child component which returns the following.
#### `audioInputs`
A list of audio input devices (i.e. microphones). type = `{deviceId:string, label:string}[]`
#### `audioOutputs`
A list of audio output devices (i.e. speakers).
#### `videoInputs`
A list of video input devices (i.e. cameras).
#### `currentAudioInputDeviceId`
The currently selected audio input device id or `null`.
#### `currentAudioOutputDeviceId`
The currently selected audio output device id or `null`.
#### `currentVideoInputDeviceId`
The currently selected video input device id or `null`.
#### `deviceController`
The AWS Chime SDK `DefaultDeviceController` used.
#### `setAudioInput`
A function to set the current audio input. Pass the `deviceId` of the new audio input.
#### `setAudioOutput`
A function to set the current audio output. Pass the `deviceId` of the new audio output.
#### `setVideoInput`
A function to set the current video input. Pass the `deviceId` of
the new video input.
### Example using `useChimeDevices`
```jsx
const AudioInputDevices = () => {
const {
audioInputs,
currentAudioInputDeviceId,
setAudioInput,
} = useChimeDevices();
return (
- setAudioInput(deviceId)}>
{label}
{deviceId === currentAudioInputDeviceId && '[selected]'}
{audioInputs.map(({ deviceId, label }) => (
))}
);
};
```
## Sample code live!
You can see an example running live on
[CodeSandbox](https://codesandbox.io/s/mystifying-noether-2qwrp)
## License
For use under the MIT [License](./LICENSE)