Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 870e7eb

Browse files
committed
Add analytics REST API sample
1 parent df73775 commit 870e7eb

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

src/sdk/rest/API.js

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,113 @@ OWT_REST.API = (function(OWT_REST) {
13111311
}, callbackError);
13121312
};
13131313

1314+
/*
1315+
* * @callback onAnalyticsList
1316+
* * @param {Array.<{id: string, analytics: Object, media: Object}>} analyticsList -The analytics list.
1317+
* * @param {Object} analyticsList[x].analytics -The information of the analytics.
1318+
* * @param {string} analyticsList[x].analytics.algorithm -The algorithm of the analytics.
1319+
* * @param {Object} analyticsList[x].media -The media description of the analytics, which must follow the definition of object "MediaSubOptions" in section "3.3.11 Participant Starts a Subscription" in "Client-Portal Protocol.md" doc.
1320+
*/
1321+
/**
1322+
* @function getAnalytics
1323+
* @desc This function gets the all the ongoing analytics in the specified room.
1324+
* @memberOf OWT_REST.API
1325+
* @param {string} room -Room ID.
1326+
* @param {function} callback -Callback function on success
1327+
* @param {function} callbackError -Callback function on error
1328+
* @example
1329+
var roomId = '51c10d86909ad1f939000001';
1330+
OWT_REST.API.getAnalytics(roomId, function(analyticsList) {
1331+
console.log('Analytics:', analyticsList);
1332+
}, function(status, error) {
1333+
// HTTP status and error
1334+
console.log(status, error);
1335+
});
1336+
*/
1337+
var getAnalytics = function(room, callback, callbackError) {
1338+
send('GET', 'rooms/' + room + '/analytics/', undefined, function(analyticsList) {
1339+
var result = JSON.parse(analyticsList);
1340+
callback(result);
1341+
}, callbackError);
1342+
};
1343+
1344+
/*
1345+
* * @callback onStartingAnalyticsOK
1346+
* * @param {Object} analyticsInfo -The object containing the information of the server-side analytics.
1347+
* * @param {string} analyticsInfo.id -The analytics ID.
1348+
* * @param {Object} analyticsInfo.analytics -The information of the analytics.
1349+
* * @param {string} analyticsInfo.analytics.algorithm -The algorithm of the analytics.
1350+
* * @param {Object} analyticsInfo.media -The media description of the analytics, which must follow the definition of object "MediaSubOptions" in section "3.3.11 Participant Starts a Subscription" in "Client-Portal Protocol.md" doc.
1351+
*/
1352+
/**
1353+
* @function startAnalytics
1354+
* @desc This function starts a analytics in the specified room.
1355+
* @memberOf OWT_REST.API
1356+
* @param {string} room -Room ID.
1357+
* @param {string} algorithm -The algorithm ID.
1358+
* @param {Object} media -The media description of the analytics, which must follow the definition of object "MediaSubOptions" in section "3.3.11 Participant Starts a Subscription" in "Client-Portal Protocol.md" doc.
1359+
* @param {onStartingAnalyticsOK} callback -Callback function on success
1360+
* @param {function} callbackError -Callback function on error
1361+
* @example
1362+
var roomId = '51c10d86909ad1f939000001';
1363+
var algorithm = 'testalgo123';
1364+
var media = {
1365+
audio: {
1366+
from: '7652773772543651'
1367+
},
1368+
video: {
1369+
from: '7652773772543651',
1370+
parameters: {
1371+
keyFrameInterval: 2
1372+
}
1373+
}
1374+
};
1375+
OWT_REST.API.startAnalytics(roomId, algorithm, media, function(analytics) {
1376+
console.log('analytics:', analytics);
1377+
}, function(status, error) {
1378+
// HTTP status and error
1379+
console.log(status, error);
1380+
});
1381+
*/
1382+
var startAnalytics = function(room, algorithm, media, callback, callbackError) {
1383+
var options = {
1384+
algorithm: algorithm,
1385+
media: media
1386+
};
1387+
1388+
send('POST', 'rooms/' + room + '/analytics/', options, function(analyticsRtn) {
1389+
var result = JSON.parse(analyticsRtn);
1390+
callback(result);
1391+
}, callbackError);
1392+
};
1393+
1394+
/**
1395+
* @function stopAnalytics
1396+
* @desc This function stops the specified analytics in the specified room.
1397+
* @memberOf OWT_REST.API
1398+
* @param {string} room -Room ID
1399+
* @param {string} id -Analytics ID
1400+
* @param {function} callback -Callback function on success
1401+
* @param {function} callbackError -Callback function on error
1402+
* @example
1403+
var roomId = '51c10d86909ad1f939000001';
1404+
var id = '878889273471677';
1405+
OWT_REST.API.stopAnalytics(roomId, id, function(result) {
1406+
console.log('Analytics:', id, 'in room:', roomId, 'stopped');
1407+
}, function(status, error) {
1408+
// HTTP status and error
1409+
console.log(status, error);
1410+
});
1411+
*/
1412+
var stopAnalytics = function(room, id, callback, callbackError) {
1413+
if (typeof id !== 'string' || id.trim().length === 0) {
1414+
return callbackError('Invalid analytics ID');
1415+
}
1416+
send('DELETE', 'rooms/' + room + '/analytics/' + id, undefined, function(result) {
1417+
callback(result);
1418+
}, callbackError);
1419+
};
1420+
13141421
/**
13151422
* @function createToken
13161423
* @desc This function creates a new token when a new participant to a room needs to be added.

0 commit comments

Comments
 (0)