Skip to main content

Stream Recording JS

The streamrecorder package provides an easy to use interface to connect to an agent session, start and stop recordings, as well as to switch streams during an active recording.

Additionally it provides an interface to connect a supervisor that can watch an agents stream.

info

The client application requires to have an auth token, received from the streamrecorder service /auth_v2/ endpoints and a unique client identifier.
Read more in the authentication documentation.

Setup

Add the local package and in the project e.g. as streamrecorder-package and locally configure the package in packages.json file.

{
"name": "streamrecorder-ui",
"dependencies": {
"eyeson-streamrec": "./streamrecorder-package"
},
}

Usage

An agent requires to have a proper client identifer and a authentication token in order to connect to the Eyeson service.

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 (webhookUrl is optional)
await eyeson.connect(clientId, clientAuthToken, stream, webhookUrl);
// start a recording for the connected session (webhookUrl is optional)
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);
}
})();

The termination_cause property is one of the following codes:

  • CONN_ERROR ... generic connection error
  • CONN_TIMEOUT ... connection timeout, client network problems
  • TERM_BY_CLIENT ... terminated by client
  • AGENT_SESSION_TERM ... the monitored agent session was stopped
  • PEERCONN_FAILED ... the peer-connection failed
  • SDP_ERROR ... the SDP could not be processed
  • SERVICE_SHUTDOWN ... streamrec service is shutting down
  • NO_ACTIVE_AGENT ... no active agent exists for the specifiec client-id
  • TWO_TIMER ... agent or supervisor already has an active session
  • MAX_SUPERVISORS_PER_AGENT ... limit of monitoring sessions reached
  • NO_PACKET_RECEIVED ... connection timeout due to missing media packets

Supervisor

A supervisor requires to have a proper client identifer and a authentication token in order to connect to the Eyeson service. Ensure the supervisor is allowed to watch the agent when fetching the authentication token at the /auth_v2/ endpoint.

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;
}
});
// (webhookUrl is optional)
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);
}
})();