Skip to content

Secure Stream Recording: A Guide for Developers

From developer for developers

Record & store
any stream

Stream Recording is a powerful feature that enables contact centers and support organisations to record and store video and/or audio streams from client sessions. It uses a highly optimised and low-bandwidth solution that ensures minimal impact on client machines' performance. In this guide, we will discuss the key components, webhooks, and the advantages of using Stream Recording in contact centers and help desks.
Building Blocks

Key components

1
Authentication

Authenticate with the StreamRec Service using the provided Authentication key. This is a different key than the one you use with the Eyeson API. Contact us to receive a key to develop.

2
Client session

Establish a client session by providing the clientId, authToken, and an optional session webhook.

3
Supervisor session

Set up a supervisor session by providing the supervisorId, clientId, authToken, and an optional session webhook. Supervision sessions are only possible for active streams.

4
Start/Stop recording
Control the recording by providing an uploadURL and an optional recording webhook.
Building blocks

Need to know

Webhooks

Stream Recording supports the following webhooks:

  • upload_ready: Triggered when the recorded file is ready for upload
  • upload_failed: Triggered if the file upload fails
  • session_finished: Triggered when the client session ends
  • supervisor_session_finished: Triggered when the supervisor session ends

WebRTC for video streams

Stream Recording utilizes WebRTC for video streams, enabling:

  • One client per client session & up to three supervisor sessions per client

Both client and supervisor sessions use WebRTC peer connections for video streams, ensuring low bandwidth usage and optimum real-time performance.

Examples

 

Client side

This code demonstrates the usage of the eyeson-streamrec library. It imports the library, sets up necessary variables, and demonstrates how to connect, record, switch media streams, stop recording, and disconnect from a session. Here's a step-by-step explanation:

  • Import the library: import eyeson from 'eyeson-streamrec'; imports the eyeson-streamrec library.

  • Initialize variables: Four variables are initialized: clientId, clientAuthToken, stream, and webhookUrl. These are required for authentication and working with the media streams and webhooks.

  • Define an event listener: eyeson.addEventListener() adds an event listener that listens for events from the Eyeson API. This example listens for 'connected' and 'disconnected' events and logs them to the console along with their termination cause, if available.

  • Connect to a session: await eyeson.connect(clientId, clientAuthToken, stream, webhookUrl); connects the client to an Eyeson session using their client ID, authentication token, media stream, and a webhook URL.

  • Start recording: await eyeson.startRecording(uploadUrl, webhookUrl); starts recording the connected session. The recording will be uploaded to the specified uploadUrl, and webhook events will be sent to the given webhookUrl.

  • Switch media streams: await eyeson.switchStream(newStream); allows switching to a different media stream (newStream) if needed.

  • Stop recording: await eyeson.stopRecording(); stops the recording of the current session.

  • Disconnect from the session: await eyeson.disconnect(); disconnects the client from the session.

The entire process is wrapped in an asynchronous immediately-invoked function expression (IIFE) and uses a try-catch block for error handling.

 

import eyeson from 'eyeson-streamrec';

const clientId; // client identifier
const clientAuthToken; // client auth token gathered by the streamrec service
const stream; // media stream
const webhookUrl; // target URL for webhooks

(async () => {
  try {
    eyeson.addEventListener(({ type, termination_cause }) => {
        if (type === 'connected') {
            console.log('connected');
        }
        if (type === 'disconnected') {
            console.log('disconnected', termination_cause);
        }
    });

    // connect the client to a session
    await eyeson.connect(clientId, clientAuthToken, stream, webhookUrl);
    // start a recording for the connected session
    await eyeson.startRecording(uploadUrl, webhookUrl);
    
    // switch to another media stream if needed
    await eyeson.switchStream(newStream);

    // ensure Recording is started and has not yet been stopped before stopping
    // the recording or switching the stream
    await eyeson.stopRecording();

    // disconnect the client session
    await eyeson.disconnect();
  } catch(err) {
    console.error(err);
  }
})();

 

Supervisor session

This code demonstrates the usage of the eyeson-streamrec library to connect a supervisor to a video session. It imports the library, sets up necessary variables, and demonstrates how to connect the supervisor, display the remote video stream, and disconnect from the session. Here's a step-by-step explanation:

  • Import the library: import { Supervisor } from 'eyeson-streamrec'; imports the Supervisor class from the eyeson-streamrec library.

  • Initialize variables: Five variables are initialized: supervisorId, clientId, supervisorAuthToken, webhookUrl, and video. These are required for authentication, working with the media streams, and webhooks.

  • Define an event listener: Supervisor.addEventListener() adds an event listener that listens for events from the Eyeson API. This example listens for the 'disconnected' event and logs it to the console. When the disconnection occurs, the srcObject of the video element is set to null.

  • Connect the supervisor: const remoteStream = await Supervisor.connect(supervisorId, supervisorAuthToken, clientId, webhookUrl); connects the supervisor to an Eyeson session using their supervisor ID, authentication token, client ID, and a webhook URL. It returns the remote media stream.

  • Display the remote stream: video.srcObject = remoteStream; and video.play(); set the srcObject of the video element to the remote media stream and start playing the video.

  • Disconnect from the session: await Supervisor.disconnect(); disconnects the supervisor from the session.

The entire process is wrapped in an asynchronous immediately-invoked function expression (IIFE) and uses a try-catch block for error handling.

 

import { Supervisor } from 'eyeson-streamrec';

const supervisorId; // supervisor identifier
const clientId; // client identifier
const supervisorAuthToken; // supervisor auth token gathered by the streamrec service
const webhookUrl; // target URL for webhooks
const video; // video element

(async () => {
  try {
    Supervisor.addEventListener(({ type }) => {
        if (type === 'disconnected') {
          console.log('disconnected');
          video.srcObject = null;
        }
    });
    const remoteStream = await Supervisor.connect(supervisorId, supervisorAuthToken, clientId, webhookUrl);
    console.log('connected');
    video.srcObject = remoteStream;
    video.play();

    await Supervisor.disconnect();
  } catch(err) {
    console.error(err);
  }
})();

Nothing is better than some code & documentation

Of course: There is always coffee and code. But nothing explains code like good documentation and example code.
Benefits

Advantages of stream recording

Stream Recording offers several benefits for contact centers and support organisations:

  • WebRTC Video Streams: Stream Recording uses WebRTC for video streams, providing real-time communication and low-latency performance.
  • Secure Recording: Recorded files are never stored or touched in any way by the system, ensuring data security and privacy.
  • Instant File Transfer: As soon as the recording is finished, files are immediately moved or sent to the user's storage, allowing for quick access and review.
  • Low Bandwidth: Optimized for low bandwidth usage, Stream Recording ensures a smooth experience even on weaker internet connections.
  • Minimal Impact on Client Performance: The system operates with very low performance impact on the client machine, ensuring a seamless experience for users.

In summary, Secure Stream Recording is an excellent solution for contact centers and support help desks looking to enhance their services with secure and efficient video stream recording. By leveraging the power of WebRTC and providing a seamless, low-bandwidth experience, Stream Recording allows developers to create a powerful and user-friendly solution for customer centric communication and monitoring.
Need more Info or an Authentication key?

Contact us

If you need an Authentication key to build your own proof of concept please send us a message and give us some key facts of your project: Estimated traffic, kind of stream you want to record and tech stack this is intended to be used with.