[mirotalk] - add getMeetings endpoint

This commit is contained in:
Miroslav Pejic
2024-03-24 14:03:56 +01:00
parent 559a1c52a5
commit 602b69e263
11 changed files with 214 additions and 5 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ IP_LOOKUP_ENABLED=false # true or false
# curl -X POST "http://localhost:3000/api/v1/meeting" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
API_KEY_SECRET=mirotalkp2p_default_secret
API_DISABLED='["token"]'
API_DISABLED='["token", "meetings"]'
# Survey URL
# Using to redirect the client after close the call (feedbacks, website...)
+4
View File
@@ -212,6 +212,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 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"
$ curl -X GET "mirotalk.up.railway.app/api/v1/meetings" -H "authorization: mirotalksfu_default_secret" -H "Content-Type: application/json"
# The response will give you a entrypoint / Room URL for your meeting.
$ curl -X POST "http://localhost:3000/api/v1/meeting" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
$ curl -X POST "https://p2p.mirotalk.com/api/v1/meeting" -H "authorization: mirotalkp2p_default_secret" -H "Content-Type: application/json"
+34
View File
@@ -0,0 +1,34 @@
'use strict';
async function getMeetings() {
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/meetings';
//const MIROTALK_URL = 'http://localhost:3000/api/v1/meetings';
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 && data.meetings) {
const meetings = data.meetings;
const formattedData = JSON.stringify({ meetings }, null, 2);
console.log(formattedData);
}
}
} catch (error) {
console.error('Error fetching data:', error);
}
}
getMeetings();
+29
View File
@@ -0,0 +1,29 @@
<?php
$API_KEY_SECRET = "mirotalkp2p_default_secret";
$MIROTALK_URL = "https://p2p.mirotalk.com/api/v1/meetings";
//$MIROTALK_URL = "http://localhost:3000/api/v1/meetings";
$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";
}
+26
View File
@@ -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/meetings"
#MIROTALK_URL = "http://localhost:3000/api/v1/meetings"
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)
+10
View File
@@ -0,0 +1,10 @@
#!/bin/bash
API_KEY_SECRET="mirotalkp2p_default_secret"
MIROTALK_URL="https://p2p.mirotalk.com/api/v1/meetings"
#MIROTALK_URL="http://localhost:3000/api/v1/meetings"
curl $MIROTALK_URL \
--header "authorization: $API_KEY_SECRET" \
--header "Content-Type: application/json" \
--request GET
+59
View File
@@ -12,6 +12,23 @@ schemes:
- http
paths:
/meetings:
get:
tags:
- 'meetings'
summary: 'Get meetings'
description: 'Get meetings'
produces:
- 'application/json'
security:
- secretApiKey: []
responses:
'200':
description: 'Get Meetings done'
schema:
$ref: '#/definitions/MeetingsResponse'
'403':
description: 'Unauthorized!'
/meeting:
post:
tags:
@@ -132,6 +149,13 @@ securityDefinitions:
description: 'Format like this: authorization: {API_KEY_SECRET}'
definitions:
MeetingsResponse:
type: object
properties:
meetings:
type: array
items:
$ref: '#/definitions/Meeting'
MeetingResponse:
type: 'object'
properties:
@@ -162,3 +186,38 @@ definitions:
properties:
token:
type: string
Peer:
type: object
properties:
peer_name:
type: string
peer_presenter:
type: boolean
peer_video:
type: boolean
peer_audio:
type: boolean
peer_video_status:
type: boolean
peer_audio_status:
type: boolean
peer_screen_status:
type: boolean
peer_hand_status:
type: boolean
peer_privacy_status:
type: boolean
os:
type: string
browser:
type: string
Meeting:
type: object
properties:
roomId:
type: string
peers:
type: array
items:
$ref: '#/definitions/Peer'
+12
View File
@@ -19,6 +19,18 @@ module.exports = class ServerApi {
return true;
}
getMeetings(peers) {
const meetings = {};
for (const room_id in peers) {
const meeting = peers[room_id];
if (!meetings) {
meetings = {};
}
meetings[room_id] = meeting;
}
return meetings;
}
getMeetingURL() {
return this.getProtocol() + this._host + '/join/' + uuidV4();
}
+37 -2
View File
@@ -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.3.08
* @version 1.3.09
*
*/
@@ -156,7 +156,7 @@ const { v4: uuidV4 } = require('uuid');
const apiBasePath = '/api/v1'; // api endpoint path
const api_docs = host + apiBasePath + '/docs'; // api docs
const api_key_secret = process.env.API_KEY_SECRET || 'mirotalkp2p_default_secret';
const apiDisabledString = process.env.API_DISABLED || '[]';
const apiDisabledString = process.env.API_DISABLED || '["token", "meetings"]';
const api_disabled = JSON.parse(apiDisabledString);
// Ngrok config
@@ -561,6 +561,35 @@ app.post([`${apiBasePath}/token`], (req, res) => {
});
});
// request meetings list
app.get([`${apiBasePath}/meetings`], (req, res) => {
// Check if endpoint allowed
if (api_disabled.includes('meetings')) {
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 meetings - Unauthorized', {
header: req.headers,
body: req.body,
});
return res.status(403).json({ error: 'Unauthorized!' });
}
// Get meetings
const meetings = api.getMeetings(peers);
res.json({ meetings: meetings });
// log.debug the output if all done
log.debug('MiroTalk get meetings - Authorized', {
header: req.headers,
body: req.body,
meetings: meetings,
});
});
// API request meeting room endpoint
app.post([`${apiBasePath}/meeting`], (req, res) => {
// Check if endpoint allowed
@@ -900,6 +929,7 @@ io.sockets.on('connect', async (socket) => {
peer_hand_status,
peer_rec_status,
peer_privacy_status,
peer_info,
} = config;
if (channel in socket.channels) {
@@ -978,6 +1008,9 @@ io.sockets.on('connect', async (socket) => {
// Check if peer is presenter, if token check the presenter key
const isPresenter = peer_token ? is_presenter : await isPeerPresenter(channel, socket.id, peer_name, peer_uuid);
// Some peer info data
const { osName, osVersion, browserName, browserVersion } = peer_info;
// collect peers info grp by channels
peers[channel][socket.id] = {
peer_name: peer_name,
@@ -990,6 +1023,8 @@ io.sockets.on('connect', async (socket) => {
peer_hand_status: peer_hand_status,
peer_rec_status: peer_rec_status,
peer_privacy_status: peer_privacy_status,
os: osName ? `${osName} ${osVersion}` : '',
browser: browserName ? `${browserName} ${browserVersion}` : '',
};
const activeRooms = getActiveRooms();
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.3.08",
"version": "1.3.09",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
+1 -1
View File
@@ -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.3.08
* @version 1.3.09
*
*/