A videocall in 11 lines of code with OpenVidu

var OV = new OpenVidu(); // Imported from openvidu-browser.js
var session = OV.initSession();
session.on(‘streamCreated’, event => {
session.subscribe(event.stream, “subscribers”);
session.connect(TOKEN).then(() => {
var publisher = OV.initPublisher(“publisher”);
}).catch(error => {
console.log(“Error connecting to the session”, error.message);
11 lines of JavaScript code are enough
This could be the simplest HTML

Securing your OpenVidu sessions

REST API (we’ll use curl for the sample code)

  1. Initalize a Session in OpenVidu Server
curl -H “Accept: application/json” -H “Content-type: application/json” -X POST https://OPENVIDUAPP:OPENVIDU_SECRET@OPENVIDU_URL/api/sessions
curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"session":"SESSION_ID"}' https://OPENVIDUAPP:OPENVIDU_SECRET@OPENVIDU_URL/api/tokens


  1. Initalize a Session in OpenVidu Server
OpenVidu openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
SessionProperties properties = new SessionProperties.Builder().build();
Session session = openVidu.createSession(properties);
TokenOptions tokenOptions = new TokenOptions.Builder()
String token = session.generateToken(tokenOptions);


  1. Initalize a Session in OpenVidu Server
var openvidu = new OpenVidu(OPENVIDU_URL, OPENVIDU_SECRET);
var properties = {};
openVidu.createSession(properties).then(session => { ... });
var tokenOptions = {
role: "PUBLISHER",
data: "user_data"
session.generateToken(tokenOptions).then(token => { ... });

Stay tuned for next iterations! You can follow us on Twitter and a Star in GitHub is always welcome :)



Easy videoconference in your web or mobile app

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store