UNPKG

react-native-whip-whep

Version:

An implementation of WHIP and WHEP protocols functionalities for React Native.

85 lines 3.35 kB
import { requireNativeModule } from "expo-modules-core"; export const ReceivableEvents = { WhepPeerConnectionStateChanged: "WhepPeerConnectionStateChanged", WhipPeerConnectionStateChanged: "WhipPeerConnectionStateChanged", ReconnectionStatusChanged: "ReconnectionStatusChanged", Warning: "Warning", }; const nativeModule = requireNativeModule("ReactNativeMobileWhepClient"); export class WhipClient { configurationOptions; preferredVideoCodecs; preferredAudioCodecs; isInitialized = false; constructor(configurationOptions, preferredVideoCodecs = [], preferredAudioCodecs = []) { this.configurationOptions = configurationOptions; this.preferredVideoCodecs = preferredVideoCodecs; this.preferredAudioCodecs = preferredAudioCodecs; this.initializeIfNeeded(); } initializeIfNeeded() { if (!this.isInitialized) { nativeModule.createWhipClient(this.configurationOptions, this.preferredVideoCodecs, this.preferredAudioCodecs); this.isInitialized = true; } } async connect(connectOptions) { this.initializeIfNeeded(); await nativeModule.connectWhip(connectOptions.serverUrl, connectOptions.authToken); } async disconnect() { await nativeModule.disconnectWhip(); this.isInitialized = false; } async cleanup() { nativeModule.cleanupWhip(); } static getSupportedAudioCodecs() { return nativeModule.getSupportedSenderAudioCodecsNames(); } static getSupportedVideoCodecs() { return nativeModule.getSupportedSenderVideoCodecsNames(); } } export class WhepClient { configurationOptions; preferredVideoCodecs; preferredAudioCodecs; isInitialized = false; constructor(configurationOptions, preferredVideoCodecs = [], preferredAudioCodecs = []) { this.configurationOptions = configurationOptions; this.preferredVideoCodecs = preferredVideoCodecs; this.preferredAudioCodecs = preferredAudioCodecs; this.initializeIfNeeded(); } initializeIfNeeded() { if (!this.isInitialized) { nativeModule.createWhepClient(this.configurationOptions, this.preferredVideoCodecs, this.preferredAudioCodecs); this.isInitialized = true; } } /** * Connects to the WHEP server defined while creating WHEP client. * Allows user to receive video and audio stream. */ async connect(connectOptions) { this.initializeIfNeeded(); await nativeModule.connectWhep(connectOptions.serverUrl, connectOptions.authToken); } /** * Disconnects from the WHEP server defined while creating WHEP client. * Frees the resources. */ async disconnect() { await nativeModule.disconnectWhep(); this.isInitialized = false; } } /** Gives access to the cameras available on the device.*/ export const cameras = nativeModule.cameras; /** Gives access to the current state of the WHEP peer connection. */ export const whepPeerConnectionState = nativeModule.whepPeerConnectionState; /** Gives access to the current state of the WHIP peer connection. */ export const whipPeerConnectionState = nativeModule.whipPeerConnectionState; export default nativeModule; //# sourceMappingURL=ReactNativeMobileWhepClientModule.js.map