openvidu-recording-node 🔗

Check it on GitHub

An OpenVidu application with a Node.js backend and a plain JS/HTML/CSS frontend. It makes use of openvidu-node-client SDK to communicate with the OpenVidu deployment. This application demonstrates OpenVidu recording capabilities. It is highly recommended to have read Recording documentation before diving into the tutorial.

Running this tutorial 🔗

To run the tutorial you need the three components stated in OpenVidu application architecture: an OpenVidu deployment, your server application and your client application. In this order:

1. Run OpenVidu deployment 🔗

Using Docker Engine:

# WARNING: this container is not suitable for production deployments of OpenVidu
# Visit https://docs.openvidu.io/en/stable/deployment

docker run -p 4443:4443 --rm \
    -e OPENVIDU_SECRET=MY_SECRET \
    -e OPENVIDU_RECORDING=true \
    -e OPENVIDU_RECORDING_PATH=/opt/openvidu/recordings \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /opt/openvidu/recordings:/opt/openvidu/recordings \
openvidu/openvidu-dev:2.29.0

Check out the additional configuration properties and volumes you must set in the docker run command for the recording to work. If you let the default value /opt/openvidu/recordings/ as OPENVIDU_RECORDING_PATH, make sure the docker container has write permissions on it.

2. Run the server application and the client application 🔗

You need Node and NPM. Check them with:

node --version
npm --version

Clone the repo:

git clone https://github.com/OpenVidu/openvidu-tutorials.git -b v2.29.0

Run the application:

cd openvidu-tutorials/openvidu-recording-node
npm install
node server.js http://localhost:4443 MY_SECRET

Go to https://localhost:5000 to test the app once the server is running. To test two different users in the same computer, use a standard window and an incognito window.

To test the application with other devices in your network, visit this FAQ. On step 1 add the additional flags to activate the recording module as explained above. And ignore step 2 and step 3, as the application already includes a backend and the frontend doesn't need to communicate with a different application server.

Understanding the code 🔗

This is an application with a JS/HTML/CSS frontend and a straightforward Node.js backend that serves HTML files.

This application provides the:

  • Backend: Node.js app with the following classes

    • server.js : entrypoint for the app and controller for managing the token to enter the OpenVidu Session

  • Frontend templates: Plain JS/HTML/CSS files served by the backend (public/)

    • index.html : template with the recording features
    • app.js: javascript file which hosted OpenVidu methods and front-backend communication

  • Frontend static files (public/)

    • openvidu-browser-VERSION.js : openvidu-browser library. You don't have to manipulate this file
    • style.css : some CSS classes to style the templates

Although this tutorial includes several methods to make the backend-frontend communication effective, we will focus on the recording features. The application shows how to manage the recordings using the OpenVidu Recording API provided by openvidu-node-client.

1) Start the recording: 🔗

app.post('/recording-node/api/recording/start', function (req, res) {
    // Retrieve params from POST body
    var recordingProperties = {
        outputMode: req.body.outputMode,
        hasAudio: req.body.hasAudio,
        hasVideo: req.body.hasVideo,
    }
    var sessionId = req.body.session;

    OV.startRecording(sessionId, recordingProperties)
        .then(recording => res.status(200).send(recording))
        .catch(error => res.status(400).send(error.message));
});

2) Stop the recording: 🔗

app.post('/recording-node/api/recording/stop', function (req, res) {
    // Retrieve params from POST body
    var recordingId = req.body.recording;

    OV.stopRecording(recordingId)
        .then(recording => res.status(200).send(recording))
        .catch(error => res.status(400).send(error.message));
});

3) Get a recording: 🔗

app.get('/recording-node/api/recording/get/:recordingId', function (req, res) {
    // Retrieve params from GET url
    var recordingId = req.params.recordingId;

    OV.getRecording(recordingId)
        .then(recording => res.status(200).send(recording))
        .catch(error => res.status(400).send(error.message));
});

4) List the recording: 🔗

app.get('/recording-node/api/recording/list', function (req, res) {
    OV.listRecordings()
        .then(recordings => res.status(200).send(recordings))
        .catch(error => res.status(400).send(error.message));
});

5) Delete the recording: 🔗

app.delete('/recording-node/api/recording/delete', function (req, res) {
    // Retrieve params from DELETE body
    var recordingId = req.body.recording;

    OV.deleteRecording(recordingId)
        .then(() => res.status(200).send())
        .catch(error => res.status(400).send(error.message));
});

Deploying openvidu-recording-node 🔗

1) Build the docker image 🔗

Under the root project folder, you can see the openvidu-recording-node/docker/ directory. Here it is included all the required files yo make it possible the deployment with OpenVidu.

First of all, you will need to create the openvidu-recording-node docker image. Under openvidu-recording-node/docker/ directory you will find the create_image.sh script. This script will create the docker image with the openvidu-recording-node server and the static files.

./create_image.sh openvidu/my-openvidu-recording-node-demo:X.Y.Z

This script will create an image named openvidu/my-openvidu-recording-node-demo:X.Y.Z. This name will be used in the next step.

2) Deploy the docker image 🔗

Time to deploy the docker image. You can follow the Deploy OpenVidu based application with Docker guide for doing this.