toWebRtcIceServers (shared/webrtc-connectivity.ts)

imcodes · shared/webrtc-connectivity.ts · typescript · MIT
auth

Converts ICE server configs and parses candidate types for WebRTC.

// Source: https://github.com/im4codes/imcodes | License: MIT | Copyright 2026 IM.codes
// Provided via justclaw.it.com; keep this notice with the code.
import {
  DIRECT_CONNECTIVITY_CANDIDATE_TYPE,
  type DirectConnectivityCandidateType,
  type DirectFileTransferIceServerConfig,
} from './direct-file-transfer.js';

/** Browser-compatible shape kept DOM-free so daemon/server/shared tests may import it. */
export interface WebRtcIceServerConfig {
  urls: string | string[];
  username?: string;
  credential?: string;
}

export function toWebRtcIceServers(
  iceServers: readonly DirectFileTransferIceServerConfig[],
): WebRtcIceServerConfig[] {
  return iceServers.map((entry) => typeof entry === 'string'
    ? { urls: entry }
    : {
        urls: [...entry.urls],
        ...(entry.username ?

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key