カメラ、マイクの選択
デバイスのリストを取得する
JavaScript SDKの SkyWayStreamFactory
から提供される、以下のメソッドを利用します。
SkyWayStreamFactory.enumerateDevices()
SkyWayStreamFactory.enumerateInputVideoDevices()
SkyWayStreamFactory.enumerateInputAudioDevices()
SkyWayStreamFactory.enumerateOutputAudioDevices()
- APIリファレンス(Roomライブラリ)
- APIリファレンス(Coreライブラリ)
以下のコードで、映像入力、音声入力、音声出力のデバイスリストを取得できます。
import { SkyWayStreamFactory } from "@skyway-sdk/room"; // 全てのデバイスを取得 const devices = await SkyWayStreamFactory.enumerateDevices(); // 種類ごとにデバイスを取得 const videoInputDevices = await SkyWayStreamFactory.enumerateInputVideoDevices(); const audioInputDevices = await SkyWayStreamFactory.enumerateInputAudioDevices(); const audioOutputDevices = await SkyWayStreamFactory.enumerateOutputAudioDevices();
各メソッドを呼び出す前に createMicrophoneAudioAndCameraStream()
、createMicrophoneAudioStream()
、 createCameraVideoStream()
のいずれかのメソッドを呼び出してデバイスの使用許可を取得すると、デバイス名を取得できます。
ユーザーがデバイスを区別できるように、デバイス名を表示してデバイスを選択する UI を実装することをお勧めします。
入力デバイスを指定する
取得したデバイスの情報のうち、deviceId
を用いて、入力デバイスを指定できます。
映像、音声のストリームを取得する際に、deviceId
を指定することで、指定したデバイスからの映像・音声を取得できます。
const selectedVideoInputDeviceId = videoInputDevices[0].deviceId; const selectedAudioInputDeviceId = audioInputDevices[0].deviceId; const { audio, video } = await SkyWayStreamFactory.createMicrophoneAudioAndCameraStream({ video: { deviceId: selectedVideoInputDeviceId }, audio: { deviceId: selectedAudioInputDeviceId } });
音声出力デバイスを指定する
音声出力デバイスを指定するには、setSinkId()
メソッドを利用します。
const selectedAudioOutputDeviceId = audioOutputDevices[0].deviceId; const mediaElement = document.getElementById('media-element'); await mediaElement.setSinkId(selectedAudioOutputDeviceId);