livestream-engineer

安装量: 90
排名: #8903

安装

npx skills add https://github.com/daffy0208/ai-dev-standards --skill livestream-engineer

Livestream Engineer Skill

I help you build live streaming features, implement WebRTC, and create real-time broadcasting experiences.

What I Do

Live Streaming:

WebRTC peer-to-peer video Live broadcasting Screen sharing Real-time chat

Streaming Platforms:

Twitch-style streaming Video conferencing Live events Webinars WebRTC Basics Peer-to-Peer Video Call // lib/webrtc.ts export class WebRTCConnection { private peerConnection: RTCPeerConnection private localStream: MediaStream | null = null

constructor() { this.peerConnection = new RTCPeerConnection({ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] }) }

async startLocalStream() { try { this.localStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })

  this.localStream.getTracks().forEach(track => {
    this.peerConnection.addTrack(track, this.localStream!)
  })

  return this.localStream
} catch (error) {
  console.error('Failed to get local stream:', error)
  throw error
}

}

async createOffer() { const offer = await this.peerConnection.createOffer() await this.peerConnection.setLocalDescription(offer) return offer }

async handleAnswer(answer: RTCSessionDescriptionInit) { await this.peerConnection.setRemoteDescription(answer) }

async handleOffer(offer: RTCSessionDescriptionInit) { await this.peerConnection.setRemoteDescription(offer) const answer = await this.peerConnection.createAnswer() await this.peerConnection.setLocalDescription(answer) return answer }

addIceCandidate(candidate: RTCIceCandidateInit) { return this.peerConnection.addIceCandidate(candidate) }

onTrack(callback: (stream: MediaStream) => void) { this.peerConnection.ontrack = event => { callback(event.streams[0]) } }

onIceCandidate(callback: (candidate: RTCIceCandidate) => void) { this.peerConnection.onicecandidate = event => { if (event.candidate) { callback(event.candidate) } } }

close() { this.localStream?.getTracks().forEach(track => track.stop()) this.peerConnection.close() } }

Usage:

'use client' import { useEffect, useRef, useState } from 'react' import { WebRTCConnection } from '@/lib/webrtc'

export function VideoCall() { const localVideoRef = useRef(null) const remoteVideoRef = useRef(null) const [connection] = useState(() => new WebRTCConnection())

useEffect(() => { const init = async () => { // Start local stream const stream = await connection.startLocalStream() if (localVideoRef.current) { localVideoRef.current.srcObject = stream }

  // Handle remote stream
  connection.onTrack((remoteStream) => {
    if (remoteVideoRef.current) {
      remoteVideoRef.current.srcObject = remoteStream
    }
  })

  // Handle ICE candidates
  connection.onIceCandidate((candidate) => {
    // Send candidate to other peer via signaling server
    socket.emit('ice-candidate', candidate)
  })
}

init()

return () => {
  connection.close()
}

}, [connection])

return (

You

Remote

) }

Screen Sharing 'use client' import { useRef, useState } from 'react'

export function ScreenShare() { const videoRef = useRef(null) const [sharing, setSharing] = useState(false) const [stream, setStream] = useState(null)

const startSharing = async () => { try { const mediaStream = await navigator.mediaDevices.getDisplayMedia({ video: { cursor: 'always' }, audio: false })

  setStream(mediaStream)
  if (videoRef.current) {
    videoRef.current.srcObject = mediaStream
  }
  setSharing(true)

  // Handle when user stops sharing via browser UI
  mediaStream.getVideoTracks()[0].onended = () => {
    stopSharing()
  }
} catch (error) {
  console.error('Failed to start screen sharing:', error)
}

}

const stopSharing = () => { stream?.getTracks().forEach(track => track.stop()) setStream(null) setSharing(false) }

return (

返回排行榜