Skip to main content

Overview

Publishing a WebRTC stream to Ant Media Server involves capturing media from the user’s camera/microphone and sending it to the server. The server handles the stream ingestion and makes it available for playback or recording.

Quick Start

Basic Publishing Example

Configuration Options

WebSocket URL

The WebSocket URL format:
  • wss:// - Secure WebSocket protocol (required for HTTPS)
  • domain - Your Ant Media Server domain or IP
  • port - WebSocket port (default: 5443 for HTTPS, 5080 for HTTP)
  • application - Application name (e.g., WebRTCAppEE, LiveApp)

Media Constraints

Control which media devices to use and their properties:

Audio-Only Publishing

Screen Sharing

ICE Server Configuration

Callbacks

Main Callback Events

The callback function receives various events during the publishing lifecycle:

Error Callback

Advanced Publishing

Publishing with Token

For secure streams requiring authentication:

Publishing with Metadata

Multi-Track Publishing

Publish multiple video/audio tracks:

Server-Side API

IWebRTCAdaptor Interface

The server-side adaptor manages stream registration:

IWebRTCMuxer Interface

The muxer handles stream multiplexing to multiple clients:

Best Practices

1. Handle User Permissions

2. Stop Publishing Properly

3. Monitor Connection State

4. Use Unique Stream IDs

Troubleshooting

Common Issues

Issue: getUserMedia fails
  • Ensure page is served over HTTPS (or localhost)
  • Check browser permissions
  • Verify camera/microphone is not in use by another application
Issue: Publishing timeout
  • Check WebSocket connectivity
  • Verify server is running and accessible
  • Check firewall rules for WebRTC ports
Issue: No video/audio
  • Verify media constraints are correct
  • Check browser console for errors
  • Ensure localVideoId element exists in DOM

Next Steps

Playing Streams

Learn how to play published WebRTC streams

Peer-to-Peer

Build P2P applications with WebRTC