A modern React JS application for real-time WebRTC webcam video streaming: Broadcast camera live to multiple viewers. Public source code & build included.
- Real-time WebRTC video streaming with peer-to-peer connections
- Broadcast Mode: Stream video from your camera to multiple viewers
- Play Mode: Watch streams from broadcasters
- Camera Selection: Switch between available camera devices
- Audio Controls: Mute/unmute microphone in broadcast mode or audio in playback mode
- Connection Status Indicators: Monitor connection state and viewer count
- Responsive UI: Built with Tailwind CSS
- Stream URL Sharing: Easily share links to your streams
- Reconnection: Handles on demand disconnect/reconnect
You can test the application without installation by visiting the official demo:
Visit https://demo.videowhisper.com/Webcam-Streaming-WebRTC/ to try out the application.
- Access the demo link above
- Allow camera and microphone permissions when prompted
- The app should start broadcasting automatically
- Test camera switching if you have multiple cameras
- Click the TV button in the bottom right to open playback in a new tab
- Use the URL copy buttons in the bottom right to share your stream
- Note the viewer count on the connection button once connected (green)
- Test the disconnect/reconnect functionality by clicking the connection button
- From a broadcaster session, open the URL in a new tab
- Optionally copy the URL and open in another browser or device or share with a friend
- Playback should start automatically
- Test the disconnect/reconnect functionality by clicking the connection (WiFi) button
To install and run the application on your own server:
- Download or build the distribution files (the
dist
folder) - Upload the files from
dist
to a folder on your web server (Apache, Nginx, etc.) - Create a
config.json
file in the root folder (or duplicateunconfigured.json
) and update it with your streaming server details:
{
"channel": "YourChannelName",
"username": "{generate}",
"view": "Broadcast",
"enableGET": true,
"showURL": true,
"vwsSocket": "wss://your-webrtc-server:3000",
"vwsToken": "your-token-here",
"stream": {
"width": 640,
"height": 360,
"framerate": 15,
"videoBitrate": 500,
"audioBitrate": 32
},
"development": false
}
- Replace
wss://your-webrtc-server:3000
andyour-token-here
with your VideoWhisper Server details (get a free account if you don't have own streaming server or account) - Access the application through your web server
- A web server with HTTPS (required for WebRTC in production)
- Access to a VideoWhisper Server that handles signaling, STUN/TURN (self-hosted VideoWhisper Server or a free plan from WebRTCHost )
- Modern browser with WebRTC support (Chrome, Firefox, Safari, Edge, Brave)
When enableGET: true
is set in the config, you can use URL parameters to quickly access broadcast/playback for specific channels:
- Broadcasting:
/?view=Broadcast&channel=MyChannel
- Viewing:
/?view=Play&channel=MyChannel
This project implements WebRTC-based video streaming using a client-server architecture with peer-to-peer connections:
The application connects to the VideoWhisper WebRTC Server which acts as a signaling server to:
- Establish connections between peers
- Manage channel/room subscriptions
- Handle WebRTC session negotiation
- Provide ICE server configuration for NAT traversal (STUN/TURN configuration)
- Handle access and limitations for streaming
The broadcaster component captures local media and establishes peer connections with viewers:
- Media Capture: Accesses the user's camera and microphone
- Multiple Connections: Maintains separate WebRTC peer connections for each viewer
- Connection Management:
- Creates and sends offers to new viewers
- Processes ICE candidates
- Monitors connection states
- Tracks connected peer count
- Camera Controls: Provides UI to switch between available camera devices
The viewer component receives and displays the broadcaster's stream:
- Session Management: Subscribes to channels using the signaling server
- WebRTC Handling:
- Processes incoming offers from broadcasters
- Generates and sends answers
- Sets up media reception
- Monitors connection quality
- Stream Statistics: Collects and displays info about video resolution, bitrate, and FPS
- Auto-reconnection: Attempts to reconnect when connections fail
-
The server connection is established using Socket.IO
-
Broadcast flow:
- Publisher connects to the server and publishes to a channel
- WebRTC peer connections are created for each viewer that joins
- Media tracks are added to each peer connection
- ICE candidates are exchanged via the signaling server
-
Play flow:
- Viewer connects to the server and subscribes to a channel
- Receives offer from the broadcaster
- Generates an answer and sends it back
- Processes incoming media tracks and renders the video
To keep your development configuration private and separate from the public repository:
- Edit
public/config.json
with your development server details - This file is automatically added to
.gitignore
to prevent it from being published
The application will:
- First try to load
config.json
(your private config) - Fall back to
unconfigured.json
if not found
- A template configuration file is provided at
public/unconfigured.json
- Register for a free developer account at WebRTCHost
- Edit the file with your own server details and remove the
deny
property:
{
"channel": "{generate}", // Will auto-generate a channel name
"username": "{generate}", // Will auto-generate a username
"view": "Broadcast", // Initial view mode: "Broadcast" or "Play"
"enableGET": true, // Allow URL parameters to override config
"showURL": true, // Show URL sharing button
"vwsSocket": "wss://your-webrtc-server:3000", // Your WebRTC server address
"vwsToken": "your-token-here" // Your authentication token,
"deny": "Deny access to app" // for integrations deny message will prevent access when not logged in or configured
"development": false, // Set to true for development mode and troubleshooting, logging
}
You can embed the application in your website and provide custom configuration through the window.videowhisperConfig
object:
<script>
window.videowhisperConfig = {
configURL: "app-login.php"
}
You can use an integration script that only provides access to authenticated site users.
- Node.js 18.x or higher
- npm or pnpm package manager
-
Clone the repository:
git clone https://github.com/videowhisper/Webcam-Streaming-WebRTC.git cd Webcam-Streaming-WebRTC
-
Install dependencies:
npm install # or using pnpm pnpm install
-
Create a development configuration:
- Copy
public/unconfigured.json
topublic/config.json
- Edit
public/config.json
with your WebRTC server details - Remove the
deny
property to enable access
- Copy
-
Start the development server:
npm run dev # or using pnpm pnpm dev
-
Access the application at
http://localhost:5173
-
Make sure your
vite.config.js
is set up correctly (theconfig.json
will be excluded from the build) -
Run the build command:
npm run build # or using pnpm pnpm build
-
The build will be created in the
dist
directory -
Deploy the contents of the
dist
directory to your web server- Note: You'll need to create a
config.json
file on your server as described in the installation instructions
- Note: You'll need to create a
When deploying, remember that the application requires a WebRTC signaling server to function properly.
When developing or contributing to this project:
- Private Configuration: Always use
config.json
for development and testing, not the publicunconfigured.json
- This file should contain your streaming server/account details and should not be shared publicly
- The
unconfigured.json
file is a public template with out of the box values
- Environment Variables: Consider using environment variables for sensitive data in production builds
- Configuration Template: Update
unconfigured.json
if you add new configuration options - Never Commit Credentials: Ensure your private WebRTC server details are never committed to the repository
To prepare for publishing:
- Ensure your private configuration (
config.json
) is added to.gitignore
- Update
unconfigured.json
with placeholder values and thedeny
property - Update documentation as needed with any new configuration options
Event | Parameters | Description |
---|---|---|
publish |
(username, channel, params) |
Starts broadcasting to the specified channel |
messagePeer |
{from, target, type, content, ...} |
Sends WebRTC signaling data to viewers |
Event | Parameters | Description |
---|---|---|
subscribe |
(username, channel) |
Subscribes to a broadcast channel |
messagePeer |
{from, target, type, content, ...} |
Sends WebRTC signaling data to broadcaster |
Event | Description |
---|---|
message |
General WebRTC signaling data (offers, answers, candidates) |
peers |
List of connected peers and ICE server configuration, for Broadcaster |
peer |
Notification when a new peer joins, for Broadcaster |
publishError |
Error notification for broadcasting issues, for Broadcaster |
subscribeError |
Error notification for viewing issues, for Viewer |
Type | Purpose |
---|---|
offer |
Initial connection offer from broadcaster to viewer |
answer |
Viewer's response to an offer |
candidate |
ICE candidate for connection establishment |
Project uses Tailwind CSS for styling and Vite. The UI is responsive and designed to work well on various screen sizes. For documentation on how to customize the styles, refer to the Tailwind CSS + Vite documentation.
- React: JavaScript library for building user interfaces
- Vite: Build tool for fast development and production builds
- Tailwind CSS: Utility-first CSS framework for styling
- Socket.IO: Library for real-time communication between client and server
- WebRTC: Technology for real-time peer-to-peer communication
- VideoWhisper WebRTC Server: Signaling server for WebRTC connections