Skip to content
Signaling Drivers

Signaling Drivers

Signaling is a crucial part of any WebRTC application, as it enables peers to discover each other and exchange the necessary information to establish a peer-to-peer connection. Peerix provides a flexible signaling mechanism that allows you to choose from several built-in drivers or implement your own custom driver.

Peerix’s transport-agnostic design means that you can use any signaling method that suits your application’s needs, whether it’s a simple in-memory driver for testing, a browser-based communication channel, or a more robust messaging system for production use. This flexibility allows you to build applications that can scale and adapt to different environments and requirements without being tied to a specific signaling implementation.

Peerix uses several techniques to reduce the number of signaling messages required to establish and maintain peer connections, such as negotiating multiple media streams and data channels. Each peer connection begins with a negotiated data channel for signaling after the initial connection is established, eliminating the need for a signaling server during the lifetime of the peer connection. Additionally, Peerix uses compression to minimize the size of signaling messages, further reducing the overhead and load on the signaling server. Finally, Peerix offers built-in namespace hashing and encryption for signaling messages to ensure that sensitive information remains protected during transmission. As a result, Peerix efficiently manages peer connections and media streams with minimal signaling overhead. This keeps private data secure, making Peerix an ideal choice for real-time applications that require low latency and high performance.

    sequenceDiagram
    Peer1->>Peer2: join
    Peer2->>Peer1: offer
    Peer1->>Peer2: answer
    Peer2<<->>Peer1: candidate
    Peer1->>Peer2: leave
  

This diagram above illustrates the typical signaling flow between two peers in a Peerix application. It’s an internal process that happens automatically during negotiation and connection management. The driver you choose will handle the signaling messages and ensure that peers can discover each other and establish connections without requiring you to manage the signaling logic directly.

Built-in Signaling Drivers

Peerix supports multiple signaling drivers for peer discovery and connection management. You can choose the driver that best fits your application’s needs:

To use a built-in signaling driver, simply import the desired driver and create an instance of the Peer class with it:

import { Peer, BroadcastChannelDriver } from 'peerix';

// create the specific driver instance
const driver = new BroadcastChannelDriver();

// use the driver
const peer = new Peer({ driver });

Custom Signaling Drivers

You can also implement your own custom signaling driver by adhering to the following interface:

import { Driver } from 'peerix';

class MyDriver extends Driver {
  async subscribe(namespace, handler) {
    // implement subscription logic for the given namespace and handler
  }

  async unsubscribe(namespace, handler) {
    // implement unsubscription logic for the given namespace and handler
  }

  async dispatch(namespace, message) {
    // implement dispatch logic for the given namespace and message
  }
}

This driver interface allows you to integrate Peerix with any signaling mechanism you prefer, such as WebSocket transport.