Skip to main content

Adding custom events in watchRTC

Your application has its own set internal logic that is outside the scope and context of WebRTC itself. As such, the watchRTC SDK cannot be aware of these events and track them on its own. In order to be able to enrich watchRTC with such events, making it more powerful and useful when you need to analyze certain sessions, you can use the custom events mechanism.

By using the watchRTC.addEvent() API available in the watchRTC SDK, you can instruct watchRTC to add such events to its tracking of the session.

Custom Event Parameters

A custom event in watchRTC has 4 parameters to it: name, type, optional parameters and pc:

  1. Name: The name is an arbitrary string describing the event. This will display when the event occurs
  2. Type: The type indicates how watchRTC should treat this event. There are 3 types of events:
    • log | This event will appear only on the event log in the testRTC Internals for the peer and nowhere else. You’ll be able to track and correlate it along with all other API calls and callbacks that watchRTC tracks
    • local | This event will appear in the event log in the testRTC Internals as well as on the peer level charts. When you will drill down to look at the peer information, the event will show as a vertical line on the charts
    • global | This event will appear in the event log in the testRTC Internals, the peer level charts and the room level charts
  3. Parameters:The optional parameters are additional custom data you wish to store for the event. This data will appear in the events log
  4. pc: An optional parameter indicating the WebRTC RTCPeerConnection object this event is associated with. If this parameter is provided, the event will appear only on the event log of the specific peer connection in the 'Advanced' WebRTC Analytics view. This ensures that you can identify the relevant connection when multiple connections are in use

Script Example

const audioPc = new RTCPeerConnection();

// At any time during the call
  name: "muted",
  type: "local",
  parameters: { value: true },
  pc: audioPc

The code example above demonstrates how the application’s peer connection called ‘audioPc’ is added to the specific custom event using the ‘watchRTC.addEvent’ method.

This event is named 'muted,' has a type of 'local,' includes a parameter with the value 'true', and is associated with the RTCPeerConnection object ‘audioPc’.

Example Event Log

Here is how custom events appear in the events log:

Example Event Chart

Here is how you’ll see custom events on charts:

Was this article helpful?

0 out of 0 found this helpful