Back to All Guides
codeAugust 13, 20268 min readRTSPLink Dev Team

Building a React WebRTC Video Player with TURN Relay Support

Create a custom React video component connecting to STUN/TURN servers for WebRTC stream playback across firewalls.

#React#WebRTC#TURN Server#TypeScript#Frontend
Live Stream Workbench

Need a live RTSP stream link right now to test this setup in VLC or OpenCV?

Test Live Stream

#1React RTCPeerConnection Setup

Configure a React hook to manage WebRTC peer connection states and TURN server ICE configurations:

React WebRTC Component
import React, { useEffect, useRef } from 'react';

export function WebRTCPlayer({ turnConfig }: { turnConfig: RTCConfiguration }) {
  const videoRef = useRef<HTMLVideoElement>(null);

  useEffect(() => {
    const pc = new RTCPeerConnection(turnConfig);
    pc.ontrack = (event) => {
      if (videoRef.current) {
        videoRef.current.srcObject = event.streams[0];
      }
    };
    return () => pc.close();
  }, [turnConfig]);

  return <video ref={videoRef} autoPlay playsInline controls className="w-full rounded-xl bg-black" />;
}

Ready to test your live RTSP video stream?

Generate free authenticated RTSP links with unlimited bandwidth and inspect frame timestamps in seconds.

Generate Free RTSP Link

Related Tutorials & Setup Guides

View all 100+ guides