mediasfu-reactnative-expo
Version:
mediasfu-reactnative-expo – Expo-managed React Native WebRTC SDK for video conferencing, webinars, live streaming, broadcast, screen sharing, whiteboard, chat, recording, live subtitles, translation, and AI agent rooms on iOS, Android, and web. Prebuilt r
37 lines • 1.56 kB
JavaScript
/**
* Creates a mediasoup client device with the provided RTP capabilities.
*
* @param {CreateDeviceClientOptions} options - The options for creating the device client.
* @param {RTPCapabilities} options.rtpCapabilities - The RTP capabilities required for the device.
* @returns {Promise<Device | null>} A promise that resolves to the created Device or null if creation fails.
* @throws {Error} Throws an error if the required parameters are not provided or if device creation is not supported.
*
* @example
* const device = await createDeviceClient({ rtpCapabilities });
* if (device) {
* console.log("Device created successfully");
* } else {
* console.log("Failed to create device");
* }
*/
export const createDeviceClient = async ({ rtpCapabilities, }) => {
try {
if (!rtpCapabilities) {
throw new Error('Both rtpCapabilities and mediasoupClient must be provided.');
}
const mediasoupClient = require('mediasoup-client');
const device = new mediasoupClient.Device();
rtpCapabilities.headerExtensions = rtpCapabilities.headerExtensions?.filter((ext) => ext.uri !== 'urn:3gpp:video-orientation');
await device.load({
routerRtpCapabilities: rtpCapabilities,
});
return device;
}
catch (error) {
if (error instanceof Error && error.name === 'UnsupportedError') {
console.error('Device creation is not supported by this browser.');
}
throw error;
}
};
//# sourceMappingURL=createDeviceClient.js.map