Skip to main content

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) => void
function
required
Callback invoked when a signaling message needs to be sent to the peer.Signature: (peerJid: string, message: { iq: string }) => void
function
Callback invoked when the proxy connection is closedSignature: () => void
Example:

Methods

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)
This method:
  1. Creates a new ProxyConnectionPC instance as initiator
  2. Sets source names for all local tracks
  3. Initiates the WebRTC negotiation
  4. Sends tracks through the peer connection
Example:

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
Jingle Actions Handled:
  • session-initiate - Creates a new peer connection (as answerer)
  • session-accept - Accepts the connection offer
  • transport-info - Exchanges ICE candidates
  • session-terminate - Terminates the connection
  • connection-error - Handles connection errors
  • unavailable - Peer unavailable
Example:
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.
Example:

Complete Examples

Screen Share Proxy (Sender)

Screen Share Proxy (Receiver)

Bidirectional Audio/Video Proxy

Important Notes

ProxyConnectionService manages only one active peer connection at a time. If a connection exists and a message arrives from a different peer, it will be automatically rejected.
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

  1. Initiator calls start(peerJid, tracks) → Sends session-initiate
  2. Receiver processes message → Creates connection → Sends session-accept
  3. Both peers exchange ICE candidates via transport-info
  4. Connection established → Media flows
  5. Either peer can send session-terminate to close
  6. onConnectionClosed callback 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+