UNPKG

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

84 lines 2.65 kB
import { connectSocket as sharedConnectSocket, connectLocalSocket as sharedConnectLocalSocket, disconnectSocket as sharedDisconnectSocket, } from 'mediasfu-shared'; /** * Connects to a media socket using the provided connection options. * * @param {ConnectSocketOptions} options - The connection options. * @param {string} options.apiUserName - The API username. * @param {string} [options.apiKey] - The API key (optional if apiToken is provided). * @param {string} [options.apiToken] - The API token (optional if apiKey is provided). * @param {string} options.link - The socket link. * * @returns {Promise<Socket>} A promise that resolves to the connected socket. * * @example * ```typescript * const options = { * apiUserName: 'user123', * apiKey: 'yourApiKeyHere', * link: 'https://socketlink.com', * }; * * try { * const socket = await connectSocket(options); * console.log('Connected to socket:', socket); * } catch (error) { * console.error('Failed to connect to socket:', error); * } * ``` */ async function connectSocket({ apiUserName, apiKey, apiToken, link }) { return sharedConnectSocket({ apiUserName, apiKey, apiToken, link, }); } /** * Connects to a local media socket using the provided connection options. * * @param {ConnectLocalSocketOptions} options - The connection options. * @param {string} options.link - The socket link. * * @returns {Promise<ResponseLocalConnection>} A promise that resolves to the connected socket and data. * * @example * ```typescript * const options = { * link: 'http://localhost:3000', * }; * * try { * const { socket, data } = await connectLocalSocket(options); * console.log('Connected to socket:', socket, data); * } catch (error) { * console.error('Failed to connect to socket:', error); * } * ``` */ async function connectLocalSocket({ link }) { return sharedConnectLocalSocket({ link }); } /** * Disconnects from the socket. * * @param {Socket} socket - The socket instance to disconnect. * @returns {Promise<boolean>} - A promise that resolves once the socket is disconnected. * * @example * ```typescript * const options = { socket: socketInstance }; * * try { * const isDisconnected = await disconnectSocket(options); * console.log('Disconnected:', isDisconnected); * } catch (error) { * console.error('Failed to disconnect:', error); * } * ``` */ async function disconnectSocket({ socket }) { return sharedDisconnectSocket({ socket: socket }); } export { connectSocket, disconnectSocket, connectLocalSocket }; //# sourceMappingURL=SocketManager.js.map