AGENT SKILL

webrtc-realtime-media-streaming

Architect and deploy sub-second real-time video, audio, and data streaming using WebRTC, SFUs (Selective Forwarding Units), STUN/TURN traversal, SDP negotiation, and data channels. Trigger when implementing real-time video conferencing, live interactive streaming, or ultra-low latency peer-to-peer data synchronization.

License 许可
MIT
最近更新
2026-10-17
Stars
★ 8
Forks
1

01 前言 Front Matter

name
webrtc-realtime-media-streaming
metadata
{ "category": "Video Streaming and Media Engineering" }
description
Architect and deploy sub-second real-time video, audio, and data streaming using WebRTC, SFUs (Selective Forwarding Units), STUN/TURN traversal, SDP negotiation, and data channels. Trigger when implementing real-time video conferencing, live interactive streaming, or ultra-low latency peer-to-peer data synchronization.
compatibility
WebRTC 1.0 (W3C), RFC 8829 (JSEP), LiveKit / mediasoup / Pion

03 SKILL.md 正文

WebRTC Real-Time Media Streaming Skill Guide

This skill governs the design and deployment of ultra-low latency (<500ms) WebRTC communication pipelines, signaling protocols, and SFU topologies.


1. WebRTC SFU Topology & Signaling Flow

[ Client Peer A ]                       [ Signaling Server ]             [ SFU Media Router ]
       |                                         |                                |
       |--(1) Create Offer (SDP) --------------->|                                |
       |                                         |--(2) Relay Offer ------------->|
       |                                         |<-(3) Answer (SDP) -------------|
       |<-(4) Set Remote Description ------------|                                |
       |                                                                          |
       |========== (5) ICE Gathering & STUN/TURN Binding ========================>|
       |                                                                          |
       |>>>>>>>>>> (6) Secure SRTP Audio / Video Stream (UDP) >>>>>>>>>>>>>>>>>>>>|

2. Production Code Standards

A. WebRTC Peer Connection Manager (TypeScript)

export class WebRTCConnection {
  private pc: RTCPeerConnection;
  private localStream?: MediaStream;

  constructor(
    private readonly iceServers: RTCIceServer[],
    private readonly onTrackCallback: (track: MediaStreamTrack, streams: readonly MediaStream[]) => void,
    private readonly onIceCandidateCallback: (candidate: RTCIceCandidate) => void
  ) {
    this.pc = new RTCPeerConnection({
      iceServers: this.iceServers,
      iceTransportPolicy: "all",
      bundlePolicy: "max-bundle",
      rtcpMuxPolicy: "require",
    });

    this.registerEventHandlers();
  }

  private registerEventHandlers(): void {
    this.pc.ontrack = (event) => {
      this.onTrackCallback(event.track, event.streams);
    };

    this.pc.onicecandidate = (event) => {
      if (event.candidate) {
        this.onIceCandidateCallback(event.candidate);
      }
    };

    this.pc.onconnectionstatechange = () => {
      console.log(`[WebRTC] Connection State: ${this.pc.connectionState}`);
    };
  }

  public async startCapture(videoConstraint: boolean = true, audioConstraint: boolean = true): Promise<MediaStream> {
    this.localStream = await navigator.mediaDevices.getUserMedia({
      video: videoConstraint ? { width: { ideal: 1280 }, height: { ideal: 720 }, frameRate: { max: 30 } } : false,
      audio: audioConstraint ? { echoCancellation: true, noiseSuppression: true, autoGainControl: true } : false,
    });

    for (const track of this.localStream.getTracks()) {
      this.pc.addTrack(track, this.localStream);
    }
    return this.localStream;
  }

  public async createOffer(): Promise<RTCSessionDescriptionInit> {
    const offer = await this.pc.createOffer({
      offerToReceiveAudio: true,
      offerToReceiveVideo: true,
    });
    await this.pc.setLocalDescription(offer);
    return offer;
  }

  public async handleAnswer(answer: RTCSessionDescriptionInit): Promise<void> {
    await this.pc.setRemoteDescription(new RTCSessionDescription(answer));
  }

  public async addIceCandidate(candidateInit: RTCIceCandidateInit): Promise<void> {
    await this.pc.addIceCandidate(new RTCIceCandidate(candidateInit));
  }

  public close(): void {
    this.localStream?.getTracks().forEach((track) => track.stop());
    this.pc.close();
  }
}

3. Production Guidelines & Traversal

  1. Mandatory TURN Server: 15-20% of enterprise clients are behind symmetric NATs or corporate firewalls that block direct P2P; always configure TURN over port 443 with TLS (turns:).
  2. Audio Processing Constraints: Always enable echoCancellation: true and noiseSuppression: true in getUserMedia for conference applications.
  3. Simulcast for Multi-Party: In SFU architectures, configure WebRTC simulcast with 3 spatial layers (low, mid, high) so the SFU can forward lower bitrates to participants with constrained bandwidth.

04 同仓库更多 Skills

hamzabellouch
hamzabellouch/agent-skills

security-audit

Comprehensive security guidance, source code audit, vulnerability assessment, and penetration test review for codebases, APIs, microservices, CLI tools, libraries, and LLM-backed applications. Triggers on requests to audit a codebase, conduct security reviews, find vulnerabilities or flaws, pen-test source code, or when the user asks in Arabic (فحص أمني، تدقيق الكود أمنياً، مراجعة الثغرات، فحص أمان المشروع). Supports Guidance mode (focused review) and Full Audit mode (deterministic 6-phase harness).

★ 8
hamzabellouch
hamzabellouch/agent-skills

malware-analysis-reversing

Production malware analysis workflows, reverse engineering methodologies, isolated sandbox triage, static/dynamic binary analysis, memory forensics, and YARA detection rule authoring.

★ 8
hamzabellouch
hamzabellouch/agent-skills

application-security-pentesting

Production Application Security (AppSec) standards, OWASP Top 10 vulnerability remediation, SAST/DAST pipeline integration, secure code review, threat modeling, and defensive security posture.

★ 8
hamzabellouch
hamzabellouch/agent-skills

oauth2-oidc-security-flows

Implement enterprise OAuth 2.1 and OpenID Connect (OIDC) authorization code flow with Proof Key for Code Exchange (PKCE), state and nonce verification, refresh token rotation, token revocation, and centralized IdP federation (Keycloak, Auth0, Okta). Trigger when building secure authentication, single sign-on (SSO), or third-party delegated authorization.

★ 8
hamzabellouch
hamzabellouch/agent-skills

jwt-session-management-hardening

Harden JWT-based authentication and session lifecycles using asymmetric signing (RS256/EdDSA), JWKS rotation, strict claims validation, Redis-backed sliding window sessions, revocation lists, and secure HttpOnly cookie storage. Trigger when implementing token validation, session revocation, or hardening API authentication.

★ 8
hamzabellouch
hamzabellouch/agent-skills

soc2-compliance-automation

Best practices for implementing SOC 2 Type II compliance controls, continuous evidence collection, infrastructure policy-as-code, and automated security monitoring. Use when automating Trust Services Criteria (Security, Availability, Confidentiality, Processing Integrity, Privacy), audit logging, IAM least privilege, or CI/CD security gates.

★ 8