Vidyo.io is a platform as a service (PaaS) that enables developers to provide high-quality, real-time video communication capabilities. The service includes the VidyoClient SDK, which provides the APIs for integrating such communication capabilities into a variety of applications and workflows.
To start using Vidyo.io services load the Javascript Vidyo Library into your web application as shown below.
Static or Dynamic loading require a global callback function. When the library loads the callback will be invoked.
Static loading
<script src="https://static.vidyo.io/latest/javascript/VidyoClient/VidyoClient.js?onload=onVidyoClientLoaded"></script>
Dynamic loading via jQuery
The loadVidyo function returns a promise that notifies the correct loading of the library.
function loadVidyo() { console.log("[CTLIVE WIDGET] Start Video Escalation..."); return new Promise( function(resolve, reject) { if (typeof window.VC === "undefined") { // Vidyo Global Callback window.onVidyoClientLoaded = function (status) { console.log("[VIDYO] SDK EVENT"); if (typeof status !== "undefined") { switch (status.state) { case "READY": console.log("[VIDYO] READY"); // The library is operating normally // After the VidyoClient/VidyoConnector is successfully initialized, // A global VC object will become available. resolve(); break; case "RETRYING": console.log("[VIDYO] RETRYING"); break; case "FAILED": console.log("[VIDYO] FAILED"); break; case "FAILEDVERSION": console.log("[VIDYO] FAILEDVERSION"); break; case "NOTAVAILABLE": console.log("[VIDYO] NOTAVAILABLE"); break; } } }; $.getScript("https://static.vidyo.io/latest/javascript/VidyoClient/VidyoClient.js?onload=CTLIVE_VIDYO_LOADED&webrtc=true&plugin=false", function () { console.log("[VIDYO] SDK Library loaded"); } ); } else { // Library already loaded resolve(); } } ); };
After the VidyoClient/VidyoConnector is successfully initialized, global VC object will become available.
Connect to a Video Room or create a new one
In order to join a video room each participant must provide a new token. Tokens are used to authenticate each endpoint (mobile, web, or native desktop app) to the vidyo.io service and enable video chat sessions.
A token is generated by combining a user name, the application ID and an expiration time, then signing these with the developer key. The resulting string is the token.
Application ID, expiration time and developer key are stored in CTLive MongoDB configuration.
To generate a new token you can use the new API getToken available in CTLive SDK.
LIVECHATSDK.LIVECHAT.getVideoToken(<chat_id>, <nickname>).then( function(data) { console.log("[VIDYO] Token", data.token); } );
Start a Video Session
Once the token is generated you have to create a new Vidyo Connector Object and use the Connect method to join an existing video room or create a new one.
A DOM element ID must be reserved as display area where the video streaming will be render.
// Generate new Token LIVECHATSDK.LIVECHAT.getVideoToken(AD_VIDEO_Obj.chat_id, "AGENT").then( function (data) { var TokenID = data.token; console.log("[VIDYO] Token [" + TokenID + "]" ); // Create a Video Connector VC.CreateVidyoConnector( { viewId: "divPanelVideo", // DOM element reserved to video render viewStyle: "VIDYO_CONNECTORVIEWSTYLE_Default", remoteParticipants: 2, // Max number of participants logFileFilter: "info", // Log levels logFileName: "", userData: "" } ).then( function(vidyoConnector) { // Connect to Video Room vidyoConnector.Connect( { host: "prod.vidyo.io", token: TokenID, //Generated Token displayName: "CUSTOMER", resourceId: "CHAT_DEFAULT_e9f75bfb-b8cc-4141-8c74-646d45636a14", // Video Conference Name, use the CTLive CHAT ID onSuccess: function () { console.log("[VIDYO] CONNECTED"); vidyoConnector.RegisterParticipantEventListener( { onJoined: VIDYO_onJoined, onLeft: VIDYO_onLeft, onDynamicChanged: VIDYO_onDynamicChanged, onLoudestChanged: VIDYO_onLoudestChanged } ); }, onFailure: function (reason) { console.log("[VIDYO] CONNECT ERROR [" + reason + "]"); }, onDisconnected: function (reason) { console.log("[VIDYO] DISCONNECTED [" + reason + "]"); console.log("[VIDYO] Call Disconnect() API on Video Connector"); vidyoConnector.Disconnect().then( function (result) { console.log("[VIDYO] Call Disable() API on Video Connector"); vidyoConnector.Disable(); } ); } } ).catch( function (err) {console.err(err); } ); } ); } ).catch( function(err) { console.err(err); } );