[mirotalk] - add stats endpoint
This commit is contained in:
@@ -230,6 +230,10 @@ $ docker-compose down
|
||||
- `Rest API:` The [API documentation](https://docs.mirotalk.com/mirotalk-p2p/api/) uses [swagger](https://swagger.io/) at http://localhost:3000/api/v1/docs. Or check it out on [live](https://p2p.mirotalk.com/api/v1/docs).
|
||||
|
||||
```bash
|
||||
# The response will give you the total of rooms and peers.
|
||||
$ curl -X GET "http://localhost:3000/api/v1/stats" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
|
||||
$ curl -X GET "https://p2p.mirotalk.com/api/v1/stats" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
|
||||
$ curl -X GET "https://mirotalk.up.railway.app/api/v1/stats" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
|
||||
# The response will give you the active meetings (default disabled).
|
||||
$ curl -X GET "http://localhost:3000/api/v1/meetings" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json"
|
||||
$ curl -X GET "https://p2p.mirotalk.com/api/v1/meetings" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json"
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
async function getStats() {
|
||||
try {
|
||||
// Use dynamic import with await
|
||||
const { default: fetch } = await import('node-fetch');
|
||||
|
||||
const API_KEY_SECRET = 'mirotalkp2p_default_secret';
|
||||
const MIROTALK_URL = 'https://p2p.mirotalk.com/api/v1/stats';
|
||||
//const MIROTALK_URL = 'http://localhost:3000/api/v1/stats';
|
||||
|
||||
const response = await fetch(MIROTALK_URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
authorization: API_KEY_SECRET,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data.error) {
|
||||
console.log('Error:', data.error);
|
||||
} else {
|
||||
if (data) {
|
||||
const formattedData = JSON.stringify(data, null, 2);
|
||||
console.log(formattedData);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
}
|
||||
}
|
||||
|
||||
getStats();
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
$API_KEY_SECRET = "mirotalkp2p_default_secret";
|
||||
$MIROTALK_URL = "https://p2p.mirotalk.com/api/v1/stats";
|
||||
//$MIROTALK_URL = "http://localhost:3000/api/v1/stats";
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $MIROTALK_URL);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_HTTPGET, true);
|
||||
|
||||
$headers = [
|
||||
'authorization:' . $API_KEY_SECRET,
|
||||
'Content-Type: application/json'
|
||||
];
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
$response = curl_exec($ch);
|
||||
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
echo "Status code: $httpcode \n";
|
||||
|
||||
if ($response) {
|
||||
echo json_encode(json_decode($response), JSON_PRETTY_PRINT);
|
||||
} else {
|
||||
echo "Failed to retrieve data.\n";
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
# pip3 install requests
|
||||
import requests
|
||||
import json
|
||||
|
||||
API_KEY_SECRET = "mirotalkp2p_default_secret"
|
||||
MIROTALK_URL = "https://p2p.mirotalk.com/api/v1/stats"
|
||||
#MIROTALK_URL = "http://localhost:3000/api/v1/stats"
|
||||
|
||||
headers = {
|
||||
"authorization": API_KEY_SECRET,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
response = requests.get(
|
||||
MIROTALK_URL,
|
||||
headers=headers
|
||||
)
|
||||
|
||||
print("Status code:", response.status_code)
|
||||
|
||||
if response.status_code == 200:
|
||||
data = response.json()
|
||||
pretty_printed_data = json.dumps(data, indent=4)
|
||||
print(data)
|
||||
else:
|
||||
print("Failed to retrieve data. Error:", response.text)
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
API_KEY_SECRET="mirotalkp2p_default_secret"
|
||||
MIROTALK_URL="https://p2p.mirotalk.com/api/v1/stats"
|
||||
#MIROTALK_URL="http://localhost:3000/api/v1/stats"
|
||||
|
||||
curl $MIROTALK_URL \
|
||||
--header "authorization: $API_KEY_SECRET" \
|
||||
--header "Content-Type: application/json" \
|
||||
--request GET
|
||||
@@ -12,6 +12,23 @@ schemes:
|
||||
- http
|
||||
|
||||
paths:
|
||||
/stats:
|
||||
get:
|
||||
tags:
|
||||
- 'stats'
|
||||
summary: 'Get stats'
|
||||
description: 'Get stats'
|
||||
produces:
|
||||
- 'application/json'
|
||||
security:
|
||||
- secretApiKey: []
|
||||
responses:
|
||||
'200':
|
||||
description: 'Get Stats done'
|
||||
schema:
|
||||
$ref: '#/definitions/StatsResponse'
|
||||
'403':
|
||||
description: 'Unauthorized!'
|
||||
/meetings:
|
||||
get:
|
||||
tags:
|
||||
@@ -149,6 +166,13 @@ securityDefinitions:
|
||||
description: 'Format like this: authorization: {API_KEY_SECRET}'
|
||||
|
||||
definitions:
|
||||
StatsResponse:
|
||||
type: object
|
||||
properties:
|
||||
meetings:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/definitions/Stats'
|
||||
MeetingsResponse:
|
||||
type: object
|
||||
properties:
|
||||
@@ -211,6 +235,15 @@ definitions:
|
||||
type: string
|
||||
browser:
|
||||
type: string
|
||||
Stats:
|
||||
type: object
|
||||
properties:
|
||||
success:
|
||||
type: boolean
|
||||
totalRooms:
|
||||
type: integer
|
||||
totalUser:
|
||||
type: integer
|
||||
|
||||
Meeting:
|
||||
type: object
|
||||
|
||||
@@ -19,6 +19,21 @@ module.exports = class ServerApi {
|
||||
return true;
|
||||
}
|
||||
|
||||
getStats(peers) {
|
||||
let totalRooms = 0;
|
||||
let totalPeers = 0;
|
||||
|
||||
for (const room_id in peers) {
|
||||
totalRooms++; // Increment room count
|
||||
totalPeers += Object.keys(peers[room_id]).length; // Count the number of peers in the room
|
||||
}
|
||||
|
||||
return {
|
||||
totalRooms,
|
||||
totalPeers,
|
||||
};
|
||||
}
|
||||
|
||||
getMeetings(peers) {
|
||||
const meetings = {};
|
||||
for (const room_id in peers) {
|
||||
|
||||
+35
-1
@@ -39,7 +39,7 @@ dependencies: {
|
||||
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.4.12
|
||||
* @version 1.4.13
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -712,6 +712,40 @@ app.get('/:roomId', (req, res) => {
|
||||
For api docs we use: https://swagger.io/
|
||||
*/
|
||||
|
||||
// request stats list
|
||||
app.get([`${apiBasePath}/stats`], (req, res) => {
|
||||
// Check if endpoint allowed
|
||||
if (api_disabled.includes('stats')) {
|
||||
return res.status(403).json({
|
||||
error: 'This endpoint has been disabled. Please contact the administrator for further information.',
|
||||
});
|
||||
}
|
||||
// check if user was authorized for the api call
|
||||
const { host, authorization } = req.headers;
|
||||
const api = new ServerApi(host, authorization, api_key_secret);
|
||||
if (!api.isAuthorized()) {
|
||||
log.debug('MiroTalk get stats - Unauthorized', {
|
||||
header: req.headers,
|
||||
body: req.body,
|
||||
});
|
||||
return res.status(403).json({ error: 'Unauthorized!' });
|
||||
}
|
||||
// Get stats
|
||||
const { totalRooms, totalPeers } = api.getStats(peers);
|
||||
res.json({
|
||||
success: true,
|
||||
totalRooms,
|
||||
totalPeers,
|
||||
});
|
||||
// log.debug the output if all done
|
||||
log.debug('MiroTalk get stats - Authorized', {
|
||||
header: req.headers,
|
||||
body: req.body,
|
||||
totalRooms,
|
||||
totalPeers,
|
||||
});
|
||||
});
|
||||
|
||||
// request token endpoint
|
||||
app.post([`${apiBasePath}/token`], (req, res) => {
|
||||
// Check if endpoint allowed
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mirotalk",
|
||||
"version": "1.4.12",
|
||||
"version": "1.4.13",
|
||||
"description": "A free WebRTC browser-based video call",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
|
||||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
|
||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||
* @version 1.4.12
|
||||
* @version 1.4.13
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -10695,7 +10695,7 @@ function showAbout() {
|
||||
Swal.fire({
|
||||
background: swBg,
|
||||
position: 'center',
|
||||
title: '<strong>WebRTC P2P v1.4.12</strong>',
|
||||
title: '<strong>WebRTC P2P v1.4.13</strong>',
|
||||
imageAlt: 'mirotalk-about',
|
||||
imageUrl: images.about,
|
||||
customClass: { image: 'img-about' },
|
||||
|
||||
Reference in New Issue
Block a user