openvidu-java-client API


This is a Java library wrapping OpenVidu Server REST API

Check JavaDoc documentation


Code samples 🔗

Create a Session 🔗

OpenVidu openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
SessionProperties properties = new SessionProperties.Builder().build();
Session session = openVidu.createSession(properties);

Create a Connection 🔗

ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
    .type(ConnectionType.WEBRTC)
    .role(OpenViduRole.PUBLISHER)
    .data("user_data")
    .build();
Connection connection = session.createConnection(connectionProperties);
String token = connection.getToken(); // Send this string to the client side

Update a Connection 🔗

This feature is part of OpenViduPRO tier.
ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
    .role(OpenViduRole.MODERATOR)
    .record(false)
    .build();
String connectionId = connection.getConnectionId();
session.updateConnection(connectionId, connectionProperties);

Publish an IP camera 🔗

ConnectionProperties connectionProperties = new ConnectionProperties.Builder()
    .type(ConnectionType.IPCAM)
    .rtspUri("rtsp://your.camera.ip:7777/path")
    .adaptativeBitrate(true)
    .onlyPlayWithSubscribers(true)
    .networkCache(2000)
    .build();
// "session" being a Session object
Connection ipcamConnection = session.createConnection(connectionProperties);

Fetch Session status 🔗

// Fetch all session info from OpenVidu Server
openvidu.fetch():
List<Session> activeSessions = openvidu.getActiveSessions();

// Fetch one session info from OpenVidu Server
session.fetch();
List<Connection> activeConnections = session.getActiveConnections();

Close a Session 🔗

session.close();

Destroy a Connection 🔗

// Find the desired Connection object in the list returned by Session.getActiveConnections()
session.forceDisconnect(connection);

Unpublish a stream 🔗

// Find the desired Publisher object in the list returned by Connection.getPublishers()
session.forceUnpublish(publisher);

Manage recordings 🔗

// Start recording
String sessionId = session.getSessionId();
RecordingProperties properties = new RecordingProperties.Builder().build();
Recording recordingStarted = openVidu.startRecording(sessionId, properties);

// Stop recording
String recordingId = recordingStarted.getId();
Recording recordingStopped = openvidu.stopRecording(recordingId);

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

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

// Delete recording
openVidu.deleteRecording(recordingId);