Overview
ProxyConnectionService manages peer-to-peer WebRTC connections for proxying media streams between participants. It’s designed primarily for screen sharing scenarios where one participant forwards their screen to another peer through a direct P2P connection, bypassing the main conference infrastructure.Key Features
- Direct P2P connections using WebRTC
- Jingle-based signaling via XMPP IQ stanzas
- Automatic TURN credentials fetching
- Converts remote streams to JitsiLocalTrack for local usage
- Single active connection management (only one peer at a time)
Constructor
object
required
Configuration options for the proxy connection service
JitsiConnection
JitsiConnection instance used to fetch TURN credentials for the P2P connection
RTCConfiguration
RTCConfiguration for the WebRTC peer connection. If not provided and jitsiConnection is available, P2P ICE config will be used automatically.
boolean
default:"false"
Whether to convert received video to a desktop (screen share) stream type
function
required
Callback invoked when a remote stream is received. The stream is converted to a JitsiLocalTrack and passed to this callback.Signature:
(jitsiLocalTrack: JitsiLocalTrack) => voidfunction
required
Callback invoked when a signaling message needs to be sent to the peer.Signature:
(peerJid: string, message: { iq: string }) => voidfunction
Callback invoked when the proxy connection is closedSignature:
() => voidMethods
start
Initiates a new proxy peer connection as the initiator and sends local tracks to the peer.string
required
The full JID of the remote peer to connect to
JitsiLocalTrack[]
default:"[]"
Array of local media tracks to send to the peer (typically screen share tracks)
- Creates a new ProxyConnectionPC instance as initiator
- Sets source names for all local tracks
- Initiates the WebRTC negotiation
- Sends tracks through the peer connection
processMessage
Processes incoming signaling messages from the peer to establish or update the proxy connection.object
required
Signaling message received from the peer
string
required
The sender’s full JID
object
required
Message data containing the IQ
string
required
Stringified Jingle IQ stanza for connection negotiation
session-initiate- Creates a new peer connection (as answerer)session-accept- Accepts the connection offertransport-info- Exchanges ICE candidatessession-terminate- Terminates the connectionconnection-error- Handles connection errorsunavailable- Peer unavailable
If a proxy connection is already active with a different peer, incoming messages from other peers are automatically rejected with a
connection-error action.stop
Terminates the active proxy peer connection and cleans up resources.Complete Examples
Screen Share Proxy (Sender)
Screen Share Proxy (Receiver)
Bidirectional Audio/Video Proxy
Important Notes
The service uses Jingle protocol over XMPP IQ stanzas for signaling. Ensure your XMPP server and message handlers support custom IQ namespaces.
Remote streams are converted to JitsiLocalTrack instances with a special
deviceId format: proxy:{peerJid} and sourceType: 'proxy'Connection Lifecycle
- Initiator calls
start(peerJid, tracks)→ Sendssession-initiate - Receiver processes message → Creates connection → Sends
session-accept - Both peers exchange ICE candidates via
transport-info - Connection established → Media flows
- Either peer can send
session-terminateto close onConnectionClosedcallback triggered on both sides
Error Handling
The service handles several error scenarios:- Rejected connections - Messages from unexpected peers are rejected with
connection-error - Missing peer JID - Throws error if
start()called without peer JID - Connection errors - Automatically closes and cleans up
- Malformed XML - Logs error and returns null for invalid IQ messages
Performance Considerations
- Uses P2P connection, bypassing media server (lower latency, reduced server load)
- Requires TURN servers for connections behind restrictive NATs
- ICE configuration automatically fetched from JitsiConnection
- Single connection limit prevents resource exhaustion
Browser Support
Requires WebRTC support:- Chrome/Edge 56+
- Firefox 44+
- Safari 11+
- Opera 43+