1. Home
  2. SIP Over WebRTC
  3. WebRTC to SIP Proxy
  1. Home
  2. Under the Hood
  3. WebRTC to SIP Proxy

WebRTC to SIP Proxy

Web Real-Time Communication (WebRTC) is not inherently bound to the Session Initiation Protocol (SIP); it’s a versatile set of technologies designed for peer-to-peer media communications across web browsers. However, in many practical applications, particularly in business telephony, integrating WebRTC with SIP-based systems is essential. This integration is commonly facilitated through a WebRTC to SIP proxy, enabling WebRTC’s browser-based communications to interface seamlessly with traditional VoIP systems.

How WebRTC Communicates

WebRTC itself is a basket of protocols and APIs that enable real-time communication (RTC) capabilities in web browsers, including the transmission of audio, video, and arbitrary data. It does not specify signaling protocols or methods, leaving the choice of signaling mechanism (like SIP, XMPP, or proprietary protocols) up to the application developers.

Key Components of WebRTC:

  • MediaStream: Captures audio and video.
  • RTCPeerConnection: Handles stable, efficient communication of streaming data between peers.
  • RTCDataChannel: Enables peer-to-peer exchange of arbitrary data.

Integration with SIP: The Role of SIP.js

To bridge the gap between WebRTC and SIP-based PBX systems, a JavaScript library like SIP.js is often used. SIP.js implements a SIP stack on the client side, utilizing WebSockets for its transport layer. This setup allows SIP signaling to be carried out directly in the web browser, making it possible to initiate and control calls to and from a SIP-enabled PBX system.

SIP.js Code Sample:

Here’s a basic example of how to set up a WebRTC call using SIP.js:

// Configuration for the SIP.js User Agent
var configuration = {
    uri: 'sip:alice@example.com',
    transportOptions: {
        wsServers: ['wss://sip.example.com']
    },
    authorizationUser: 'alice',
    password: 'supersecret'
};

// Create a new SIP.js User Agent
var userAgent = new SIP.UA(configuration);

// Listen for incoming calls
userAgent.on('invite', function (session) {
    session.accept();  // Automatically accept the call
});

// To make a call
var session = userAgent.invite('sip:bob@example.com');

This example sets up a basic SIP user agent that can receive and make calls. It assumes that there’s a WebSocket server (wss://sip.example.com) that can relay SIP messages to and from the PBX.

The Role of a WebRTC to SIP Proxy

The proxy acts as an intermediary that translates signaling and sometimes media between WebRTC and traditional SIP devices. The proxy must handle several important tasks:

  • WebSocket Endpoint: The proxy serves as the endpoint for WebSocket connections from WebRTC clients. It receives SIP messages encapsulated within WebSocket frames from the client’s SIP.js stack.
  • SIP Signaling Relay: After extracting SIP messages, the proxy relays them to the SIP server (PBX). It also performs the reverse operation, receiving SIP messages from the PBX and forwarding them to the WebRTC client.
  • Media Handling: While WebRTC uses DTLS-SRTP for media encryption, traditional SIP environments might not. The proxy can also handle transcoding and re-encrypting media streams when necessary to ensure compatibility between WebRTC clients and SIP endpoints.

Proxy Operation Example:

Here’s how a basic call flow might look through a WebRTC to SIP proxy:

  1. Outgoing Call Setup:
    • The WebRTC client uses SIP.js to send an INVITE request through the WebSocket.
    • The proxy receives the WebSocket data, extracts the SIP INVITE, and forwards it to the PBX.
  2. Incoming Call Notification:
    • The PBX sends an INVITE to the proxy for an incoming call.
    • The proxy translates this to a WebSocket message and forwards it to the WebRTC client.
  3. Media Setup:
    • Upon call acceptance, WebRTC negotiates media directly with the PBX if possible, using ICE candidates. The proxy may assist in this negotiation or handle media relaying if direct media paths cannot be established.

Conclusion

A WebRTC to SIP proxy is crucial for integrating cutting-edge WebRTC applications with established SIP-based telephony systems. By handling the intricacies of SIP signaling and media translation, the proxy enables seamless communication across disparate technology stacks, ensuring broad compatibility and extending the reach of modern web communications into traditional telephony environments.

Related Articles