
Secure Stream Recording: A Guide for Developers
Record & store
any stream
Key components
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.
Establish a client session by providing the clientId, authToken,
and an optional session webhook
.
Set up a supervisor session by providing the supervisorId, clientId, authToken
, and an optional session webhook
. Supervision sessions are only possible for active streams.
uploadURL
and an optional recording webhook
.
Need to know
Webhooks
Stream Recording supports the following webhooks:
upload_ready
: Triggered when the recorded file is ready for uploadupload_failed
: Triggered if the file upload failssession_finished
: Triggered when the client session endssupervisor_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.
TABLE OF CONTENTS
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 theeyeson-streamrec
library. -
Initialize variables: Four variables are initialized:
clientId
,clientAuthToken
,stream
, andwebhookUrl
. 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 specifieduploadUrl
, and webhook events will be sent to the givenwebhookUrl
. -
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 theSupervisor
class from theeyeson-streamrec
library. -
Initialize variables: Five variables are initialized:
supervisorId
,clientId
,supervisorAuthToken
,webhookUrl
, andvideo
. 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, thesrcObject
of thevideo
element is set tonull
. -
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;
andvideo.play();
set thesrcObject
of thevideo
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 and documentation
Of course: There is always coffee and code. But nothing explains code like good documentation and example code.

Advantages of stream recording
- 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.