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.
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 errorCONN_TIMEOUT
... connection timeout, client network problemsTERM_BY_CLIENT
... terminated by clientAGENT_SESSION_TERM
... the monitored agent session was stoppedPEERCONN_FAILED
... the peer-connection failedSDP_ERROR
... the SDP could not be processedSERVICE_SHUTDOWN
... streamrec service is shutting downNO_ACTIVE_AGENT
... no active agent exists for the specifiec client-idTWO_TIMER
... agent or supervisor already has an active sessionMAX_SUPERVISORS_PER_AGENT
... limit of monitoring sessions reachedNO_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);
}
})();