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
74 lines • 4.1 kB
JavaScript
import { connectSendTransportScreen as sharedConnectSendTransportScreen } from 'mediasfu-shared';
const connectLocalSendTransportScreen = async ({ stream, parameters, }) => {
try {
let { localScreenProducer, localProducerTransport, updateLocalScreenProducer, updateLocalProducerTransport, device, } = parameters;
// Find VP9 codec for local screen share
const codec = device?.rtpCapabilities?.codecs?.find((codec) => codec.mimeType.toLowerCase() === 'video/vp9');
// Produce local screen share data
if (localProducerTransport) {
localScreenProducer = await localProducerTransport.produce({
track: stream.getVideoTracks()[0],
codec,
appData: { mediaTag: 'screen-video' },
});
// Update the local producer and transport objects
updateLocalScreenProducer?.(localScreenProducer);
updateLocalProducerTransport?.(localProducerTransport);
}
}
catch (error) {
console.error('Error connecting local screen transport:', error);
throw error; // Re-throw to propagate the error
}
};
/**
* Sets up and connects a screen sharing transport for sending video streams.
*
* This function supports both a primary and a local screen producer, delegating local handling to a separate function.
*
* @param {ConnectSendTransportScreenOptions} options - The configuration options for setting up the screen transport.
* @param {'all' | 'local' | 'remote'} [options.targetOption] - The target option for connecting the transport.
* @param {MediaStream} options.stream - The screen stream to be shared.
* @param {ConnectSendTransportScreenParameters} options.parameters - The parameters required for setting up the screen transport.
* @param {Producer | null} options.parameters.screenProducer - The screen producer object to be updated.
* @param {Device | null} options.parameters.device - The device object for media capabilities.
* @param {ProducerOptions} options.parameters.screenParams - The parameters for the screen producer.
* @param {Transport | null} options.parameters.producerTransport - The producer transport object.
* @param {ProducerOptions} options.parameters.params - The parameters for the producer.
* @param {Function} options.parameters.updateScreenProducer - The function to update the screen producer object.
* @param {Function} options.parameters.updateProducerTransport - The function to update the producer transport object.
* @param {Function} [options.parameters.updateLocalScreenProducer] - The function to update the local screen producer object.
* @param {Function} [options.parameters.updateLocalProducerTransport] - The function to update the local producer transport object.
* @param {Function} options.parameters.getUpdatedAllParams - The function to get updated parameters.
* @param {Object} [options.parameters.*] - Additional parameters for future use.
*
* @returns {Promise<void>} - A promise that resolves once the screen transport is successfully connected and set up.
*
* @throws Will throw an error if there is an issue with the connection or setup process.
*
* @example
* ```typescript
* await connectSendTransportScreen({
* stream: screenStream,
* targetOption: 'all',
* parameters: {
* screenProducer: null,
* localScreenProducer: null,
* device: mediaDevice,
* screenParams: { encodings: [{ maxBitrate: 1500000 }] },
* producerTransport: sendTransport,
* localProducerTransport: localSendTransport,
* params: { track: screenStream.getVideoTracks()[0] },
* updateScreenProducer: setScreenProducer,
* updateLocalScreenProducer: setLocalScreenProducer,
* updateProducerTransport: setProducerTransport,
* updateLocalProducerTransport: setLocalProducerTransport,
* getUpdatedAllParams: getParams,
* },
* });
* ```
*/
export const connectSendTransportScreen = async (options) => {
await sharedConnectSendTransportScreen(options);
};
//# sourceMappingURL=connectSendTransportScreen.js.map