Skip to content

Commit

Permalink
[mirotalksfu] - add timestamp to stats, fix api doc
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Dec 21, 2024
1 parent 3e2708c commit 0f45190
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
23 changes: 10 additions & 13 deletions app/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,16 @@ definitions:
StatsResponse:
type: object
properties:
meetings:
type: array
items:
$ref: '#/definitions/Stats'
success:
type: boolean
timestamp:
type: string
format: date-time
example: "2024-12-21T12:00:00Z"
totalRooms:
type: integer
totalPeers:
type: integer
MeetingsResponse:
type: object
properties:
Expand Down Expand Up @@ -218,15 +224,6 @@ definitions:
browser:
type: string

Stats:
type: object
properties:
success:
type: boolean
totalRooms:
type: integer
totalUser:
type: integer
Meeting:
type: object
properties:
Expand Down
6 changes: 4 additions & 2 deletions app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dev dependencies: {
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.6.54
* @version 1.6.55
*
*/

Expand Down Expand Up @@ -945,10 +945,11 @@ function startServer() {
return res.status(403).json({ error: 'Unauthorized!' });
}

const { totalRooms, totalUsers } = api.getStats(roomList);
const { timestamp, totalRooms, totalUsers } = api.getStats(roomList);

res.json({
success: true,
timestamp,
totalRooms,
totalUsers,
});
Expand All @@ -957,6 +958,7 @@ function startServer() {
log.debug('MiroTalk get stats - Authorized', {
header: req.headers,
body: req.body,
timestamp,
totalRooms,
totalUsers,
});
Expand Down
4 changes: 2 additions & 2 deletions app/src/ServerApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ module.exports = class ServerApi {
return true;
}

getStats(roomList) {
getStats(roomList, timestamp = new Date().toISOString()) {
const totalUsers = Array.from(roomList.values()).reduce((total, room) => total + room.peers.size, 0);
const totalRooms = roomList.size;
return { totalRooms, totalUsers };
return { timestamp, totalRooms, totalUsers };
}

getMeetings(roomList) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalksfu",
"version": "1.6.54",
"version": "1.6.55",
"description": "WebRTC SFU browser-based video calls",
"main": "Server.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions public/js/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (location.href.substr(0, 5) !== 'https') location.href = 'https' + location.h
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.6.54
* @version 1.6.55
*
*/

Expand Down Expand Up @@ -4619,7 +4619,7 @@ function showAbout() {
imageUrl: image.about,
customClass: { image: 'img-about' },
position: 'center',
title: 'WebRTC SFU v1.6.54',
title: 'WebRTC SFU v1.6.55',
html: `
<br />
<div id="about">
Expand Down
2 changes: 1 addition & 1 deletion public/js/RoomClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.6.54
* @version 1.6.55
*
*/

Expand Down
10 changes: 7 additions & 3 deletions tests/test-ServerAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('test-ServerAPI', () => {
const host = 'example.com';
const authorization = 'secret-key';
const apiKeySecret = 'secret-key';
const timestamp = new Date().toISOString();

beforeEach(() => {
// Mocking config values
Expand Down Expand Up @@ -58,9 +59,10 @@ describe('test-ServerAPI', () => {
],
]);

const result = serverApi.getStats(roomList);
const result = serverApi.getStats(roomList, timestamp);

result.should.deepEqual({
timestamp: timestamp,
totalRooms: 2,
totalUsers: 3,
});
Expand All @@ -72,9 +74,10 @@ describe('test-ServerAPI', () => {
['room2', { peers: new Map() }],
]);

const result = serverApi.getStats(roomList);
const result = serverApi.getStats(roomList, timestamp);

result.should.deepEqual({
timestamp: timestamp,
totalRooms: 2,
totalUsers: 0,
});
Expand All @@ -83,9 +86,10 @@ describe('test-ServerAPI', () => {
it('should return 0 rooms when roomList is empty', () => {
const roomList = new Map();

const result = serverApi.getStats(roomList);
const result = serverApi.getStats(roomList, timestamp);

result.should.deepEqual({
timestamp: timestamp,
totalRooms: 0,
totalUsers: 0,
});
Expand Down

0 comments on commit 0f45190

Please sign in to comment.