UNPKG

webrtc2-config

Version:

WebRTC2 Config - Configuration management for WebRTC applications with STUN/TURN servers, ICE settings, media constraints, and cross-platform defaults

140 lines (138 loc) 3.77 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var index_exports = {}; __export(index_exports, { ConfigManager: () => ConfigManager, VERSION: () => VERSION, config: () => config, createConfig: () => createConfig, defaultConfig: () => defaultConfig, validateConfig: () => validateConfig }); module.exports = __toCommonJS(index_exports); var defaultConfig = { rtc: { iceServers: [ { urls: "stun:stun.l.google.com:19302" }, { urls: "stun:stun1.l.google.com:19302" } ], bundlePolicy: "balanced", rtcpMuxPolicy: "require" }, signaling: { url: "wss://signaling.webrtc2.com", reconnectAttempts: 5, reconnectDelay: 1e3 }, media: { video: { width: 1280, height: 720, frameRate: 30, facingMode: "user" }, audio: { echoCancellation: true, noiseSuppression: true, autoGainControl: true } }, ui: { theme: "auto", language: "en", showStats: false }, debug: { enabled: false, level: "info", logToConsole: true } }; var ConfigManager = class { constructor(initialConfig) { this.config = this.mergeConfig(defaultConfig, initialConfig || {}); } mergeConfig(base, override) { return { rtc: { ...base.rtc, ...override.rtc }, signaling: { ...base.signaling, ...override.signaling }, media: { video: { ...base.media.video, ...override.media?.video }, audio: { ...base.media.audio, ...override.media?.audio } }, ui: { ...base.ui, ...override.ui }, debug: { ...base.debug, ...override.debug } }; } get() { return { ...this.config }; } update(updates) { this.config = this.mergeConfig(this.config, updates); } reset() { this.config = { ...defaultConfig }; } // Specific getters for common use cases getRTCConfig() { return { ...this.config.rtc }; } getSignalingUrl() { return this.config.signaling.url; } getMediaConstraints() { return { video: { width: this.config.media.video.width, height: this.config.media.video.height, frameRate: this.config.media.video.frameRate, facingMode: this.config.media.video.facingMode }, audio: { echoCancellation: this.config.media.audio.echoCancellation, noiseSuppression: this.config.media.audio.noiseSuppression, autoGainControl: this.config.media.audio.autoGainControl } }; } }; var config = new ConfigManager(); function createConfig(overrides) { return new ConfigManager(overrides); } function validateConfig(config2) { if (config2.signaling?.url && !config2.signaling.url.startsWith("ws")) { return false; } if (config2.media?.video?.width && config2.media.video.width <= 0) { return false; } return true; } var VERSION = "1.0.0"; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ConfigManager, VERSION, config, createConfig, defaultConfig, validateConfig });