const isNode = typeof window === 'undefined'; export interface RTCPeerConnectionWrapper { createPeerConnection: (config?: RTCConfiguration) => RTCPeerConnection; } let wrtcImplementation: RTCPeerConnectionWrapper | null = null; export default async function getWebRTC(): Promise { if (!wrtcImplementation) { try { if (isNode) { console.info('getWebRTC(): Initializing Node WebRTC'); const initializeWRTC = require('./node').default; wrtcImplementation = await initializeWRTC(); } else { console.info('getWebRTC(): Initializing Browser WebRTC'); const initializeWRTC = require('./browser').default; wrtcImplementation = await initializeWRTC(); } } catch (error) { console.warn('getWebRTC(): WebRTC not available:', error); return null; } } return wrtcImplementation; }