From 0f451901c424aedd5e67fc1fb907154be77f6a75 Mon Sep 17 00:00:00 2001 From: Miroslav Pejic Date: Sat, 21 Dec 2024 11:23:21 +0100 Subject: [PATCH] [mirotalksfu] - add timestamp to stats, fix api doc --- app/api/swagger.yaml | 23 ++++++++++------------- app/src/Server.js | 6 ++++-- app/src/ServerApi.js | 4 ++-- package.json | 2 +- public/js/Room.js | 4 ++-- public/js/RoomClient.js | 2 +- tests/test-ServerAPI.js | 10 +++++++--- 7 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/api/swagger.yaml b/app/api/swagger.yaml index 41e7835f..84038a14 100644 --- a/app/api/swagger.yaml +++ b/app/api/swagger.yaml @@ -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: @@ -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: diff --git a/app/src/Server.js b/app/src/Server.js index 6f3902cb..3ca369f5 100644 --- a/app/src/Server.js +++ b/app/src/Server.js @@ -55,7 +55,7 @@ dev dependencies: { * @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon * @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 * @author Miroslav Pejic - miroslav.pejic.85@gmail.com - * @version 1.6.54 + * @version 1.6.55 * */ @@ -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, }); @@ -957,6 +958,7 @@ function startServer() { log.debug('MiroTalk get stats - Authorized', { header: req.headers, body: req.body, + timestamp, totalRooms, totalUsers, }); diff --git a/app/src/ServerApi.js b/app/src/ServerApi.js index 9ab43d2b..693d7922 100644 --- a/app/src/ServerApi.js +++ b/app/src/ServerApi.js @@ -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) { diff --git a/package.json b/package.json index 49ced38d..0a8614d0 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/public/js/Room.js b/public/js/Room.js index 0c882477..80cc2f26 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -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 license.mirotalk@gmail.com or purchase directly via CodeCanyon * @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 * @author Miroslav Pejic - miroslav.pejic.85@gmail.com - * @version 1.6.54 + * @version 1.6.55 * */ @@ -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: `
diff --git a/public/js/RoomClient.js b/public/js/RoomClient.js index e7c79f08..df157b2c 100644 --- a/public/js/RoomClient.js +++ b/public/js/RoomClient.js @@ -9,7 +9,7 @@ * @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon * @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 * @author Miroslav Pejic - miroslav.pejic.85@gmail.com - * @version 1.6.54 + * @version 1.6.55 * */ diff --git a/tests/test-ServerAPI.js b/tests/test-ServerAPI.js index e79c76c2..a97bd95a 100644 --- a/tests/test-ServerAPI.js +++ b/tests/test-ServerAPI.js @@ -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 @@ -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, }); @@ -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, }); @@ -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, });