openvidu-node-client API


This is a Node library wrapping OpenVidu REST API


Installation 🔗

npm i -S openvidu-node-client



Documentation 🔗

TypeDoc documentation



Code samples 🔗

Create a Session 🔗

var openVidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
var properties = {};
openVidu.createSession(properties).then(session => { ... });

Create a Connection 🔗

var connectionProperties = {
    role: "PUBLISHER",
    data: "user_data"
};
session.createConnection(connectionProperties).then(connection => {
    var token = connection.token; // Send this string to the client side
});

Update a Connection 🔗

This feature is part of OpenVidu PRO and ENTERPRISE editions.
var connectionProperties = {
    type: "WEBRTC",
    role: "MODERATOR",
    record: false
};
var connectionId = connection.connectionId;
session.updateConnection(connectionId, connectionProperties).then(connection => { ... });

Publish an IP camera 🔗

var connectionProperties = {
    type: "IPCAM",
    rtspUri: "rtsp://your.camera.ip:7777/path",
    adaptativeBitrate: true,
    onlyPlayWithSubscribers: true,
    networkCache: 2000
};
// "session" being a Session object
session.createConnection(connectionProperties)
    .then(ipcamConnection => { ... })
    .catch(error => console.error(error));

Fetch Session status 🔗

// Fetch all session info from OpenVidu Server
openvidu.fetch()
  .then(anyChange => {
      var activeSessions = openvidu.activeSessions;
  });

// Fetch one session info from OpenVidu Server
session.fetch()
  .then(anyChange => {
      var activeConnections = session.activeSessions;
  });

Close a Session 🔗

session.close().then(() => console.log('Session closed'));

Destroy a Connection 🔗

// Find the desired Connection object in the array Session.activeConnections
session.forceDisconnect(connection);

Unpublish a stream 🔗

// Find the desired Publisher object in the array Connection.publishers
session.forceUnpublish(publisher);

Manage recordings 🔗

// Start recording
var sessionId = session.getSessionId();
openVidu.startRecording(sessionId).then(recordingStarted => ... );

// Stop recording
var recordingId = recordingStarted.id;
openvidu.stopRecording(recordingId).then(recordingStopped => ... );

// Get recording
openvidu.getRecording(recordingId).then(recordingRetrieved => ... );

// List recordings
openVidu.listRecordings().then(recordingList => ... );

// Delete recording
openVidu.deleteRecording(recordingId);