mediasfu-reactnative
Version:
MediaSFU Prebuilt React Native SDK
43 lines • 1.85 kB
JavaScript
import * as mediasoupClient from 'mediasoup-client';
/**
* 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 {
// Validate input parameters
if (!rtpCapabilities) {
throw new Error('Both rtpCapabilities and mediasoupClient must be provided.');
}
// Create a mediasoup client device
const device = new mediasoupClient.Device();
// Remove orientation capabilities
rtpCapabilities.headerExtensions = rtpCapabilities.headerExtensions.filter((ext) => ext.uri !== 'urn:3gpp:video-orientation');
// Load the provided RTP capabilities into the device
await device.load({
routerRtpCapabilities: rtpCapabilities,
});
return device;
}
catch (error) {
// Handle specific errors, e.g., UnsupportedError
if (error && error.name === 'UnsupportedError') {
// Handle unsupported device creation
console.error('Device creation is not supported by this browser.');
}
throw error; // Propagate other errors
}
};
//# sourceMappingURL=createDeviceClient.js.map