[mirotalk] - extend Rest API, update dep

This commit is contained in:
Miroslav Pejic
2024-01-19 14:59:54 +01:00
parent b5954a1927
commit 26b67b48ea
12 changed files with 306 additions and 39 deletions
+5 -1
View File
@@ -230,10 +230,14 @@ $ 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 a entrypoint / Room URL for your meeting, where authorization: API_KEY_SECRET.
# The response will give you a entrypoint / Room URL for your meeting.
$ curl -X POST "http://localhost:3000/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
$ curl -X POST "https://p2p.mirotalk.com/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
$ curl -X POST "https://mirotalk.up.railway.app/api/v1/meeting" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json"
# The response will give you a entrypoint / URL for the direct join to the meeting.
$ curl -X POST "http://localhost:3000/api/v1/join" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalk","audio":"true","video":"true","screen":"false","hide":"false","notify":"true"}'
$ curl -X POST "https://p2p.mirotalk.com/api/v1/join" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalk","audio":"true","video":"true","screen":"false","hide":"false","notify":"true"}'
$ curl -X POST "https://mirotalk.up.railway.app/api/v1/join" -H "authorization: mirotalk_default_secret" -H "Content-Type: application/json" --data '{"room":"test","name":"mirotalk","audio":"true","video":"true","screen":"false","hide":"false","notify":"true"}'
```
</details>
+34 -16
View File
@@ -1,36 +1,54 @@
[![restAPI](restAPI.png)](https://p2p.mirotalk.com/api/v1/docs)
![restAPI](restAPI.png)
## Create a meeting
## Create a Meeting
Create a meeting with a `HTTP request` containing the `API_KEY` sent to MiroTalks server. The response contains a `meeting` URL that can be `embedded` in your client within an `iframe`.
To initiate a meeting, send an HTTP request to MiroTalks server with your API key. Replace the default secret key in `.env` with your own.
```bash
cd meeting
# js
node meeting.js
# php
php meeting.php
# python
python meeting.py
# bash
./meeting.sh
API_KEY_SECRET=mirotalk_default_secret
```
## Embed a meeting
Use the following examples to make API calls:
Embedding a meeting into a `service` or `app` requires using an `iframe` with the `src` attribute specified as the `meeting` from `HTTP response`. Change the iframe `src` with your own instance of MiroTalk.
```bash
# Node.js
node meeting.js
node join.js
# PHP
php meeting.php
php join.php
# Python
python3 meeting.py
python3 join.py
# Bash
./meeting.sh
./join.sh
```
The server response will contain a meeting URL that can be embedded in your client using an iframe.
---
## Embed a Meeting
To embed a meeting in your service or app, use an iframe with the source attribute set to the meeting URL obtained from the HTTP response.
```html
<iframe
allow="camera; microphone; display-capture; fullscreen; clipboard-read; clipboard-write; autoplay"
src="https://p2p.mirotalk.com/join/room_name"
src="https://p2p.mirotalk.com/join/test"
style="height: 100vh; width: 100vw; border: 0px;"
></iframe>
```
---
## Fast Integration
Develop your `website` or `application`, and bring `video meetings` in with a simple `iframe`.
Integrate video meetings into your website or application quickly by incorporating the following iframe code:
```html
<iframe
+42
View File
@@ -0,0 +1,42 @@
'use strict';
// npm i node-fetch
async function getJoin() {
try {
// Use dynamic import with await
const { default: fetch } = await import('node-fetch');
const API_KEY_SECRET = 'mirotalk_default_secret';
const MIROTALK_URL = 'https://p2p.mirotalk.com/api/v1/join';
// const MIROTALK_URL = 'http://localhost:3000/api/v1/join';
// const MIROTALK_URL = "https://mirotalk.up.railway.app/api/v1/join";
const response = await fetch(MIROTALK_URL, {
method: 'POST',
headers: {
authorization: API_KEY_SECRET,
'Content-Type': 'application/json',
},
body: JSON.stringify({
room: 'test',
name: 'mirotalk',
audio: true,
video: true,
screen: false,
hide: false,
notify: true,
}),
});
const data = await response.json();
if (data.error) {
console.log('Error:', data.error);
} else {
console.log('join:', data.join);
}
} catch (error) {
console.error('Error fetching data:', error);
}
}
getJoin();
+39
View File
@@ -0,0 +1,39 @@
<?php
$API_KEY_SECRET = "mirotalk_default_secret";
$MIROTALK_URL = "https://p2p.mirotalk.com/api/v1/join";
// $MIROTALK_URL = "http://localhost:3000/api/v1/join";
// $MIROTALK_URL = "https://mirotalk.up.railway.app/api/v1/join";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $MIROTALK_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$headers = [
'authorization:' . $API_KEY_SECRET,
'Content-Type: application/json'
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = array(
"room" => "test",
"name" => "mirotalk",
"audio" => true,
"video" => true,
"screen" => false,
"hide" => false,
"notify" => true,
);
$data_string = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "Status code: $httpcode \n";
$data = json_decode($response);
echo "join: ", $data->{'join'}, "\n";
+33
View File
@@ -0,0 +1,33 @@
# pip3 install requests
import requests
import json
API_KEY_SECRET = "mirotalk_default_secret"
MIROTALK_URL = "https://p2p.mirotalk.com/api/v1/join"
# MIROTALK_URL = "http://localhost:3000/api/v1/join"
# MIROTALK_URL = "https://mirotalk.up.railway.app/api/v1/join"
headers = {
"authorization": API_KEY_SECRET,
"Content-Type": "application/json",
}
data = {
"room": "test",
"name": "mirotalk",
"audio": "true",
"video": "true",
"screen": "false",
"hide": "false",
"notify": "true",
}
response = requests.post(
MIROTALK_URL,
headers=headers,
json=data,
)
print("Status code:", response.status_code)
data = json.loads(response.text)
print("join:", data["join"])
+12
View File
@@ -0,0 +1,12 @@
#!/bin/bash
API_KEY_SECRET="mirotalk_default_secret"
MIROTALK_URL="https://p2p.mirotalk.com/api/v1/join"
# MIROTALK_URL="http://localhost:3000/api/v1/join"
# MIROTALK_URL = "https://mirotalk.up.railway.app/api/v1/join"
curl $MIROTALK_URL \
--header "authorization: $API_KEY_SECRET" \
--header "Content-Type: application/json" \
--data '{"room":"test","name":"mirotalk","audio":"true","video":"true","screen":"false","hide":"false","notify":"true"}' \
--request POST
+2
View File
@@ -1,5 +1,7 @@
'use strict';
// npm i node-fetch
async function getMeeting() {
try {
// Use dynamic import with await
+55 -2
View File
@@ -1,8 +1,8 @@
swagger: '2.0'
info:
title: MiroTalk API
description: API description for external applications that integrates with MiroTalk.
title: MiroTalk P2P API
description: API description for external applications that integrates with MiroTalk P2P.
version: 1.0.0
basePath: /api/v1
@@ -31,6 +31,54 @@ paths:
$ref: '#/definitions/MeetingResponse'
'403':
description: 'Unauthorized!'
/join:
post:
tags:
- 'join'
summary: 'Create direct join'
description: 'Create join'
parameters:
- in: body
name: Join
description: Custom Join URL.
schema:
type: object
required:
- room
- name
- audio
- video
- screen
- hide
- notify
properties:
room:
type: string
name:
type: string
audio:
type: boolean
video:
type: boolean
screen:
type: boolean
hide:
type: boolean
notify:
type: boolean
consumes:
- 'application/json'
produces:
- 'application/json'
security:
- secretApiKey: []
responses:
'200':
description: 'Direct join created'
schema:
$ref: '#/definitions/JoinResponse'
'403':
description: 'Unauthorized!'
securityDefinitions:
secretApiKey:
@@ -45,3 +93,8 @@ definitions:
properties:
meeting:
type: 'string'
JoinResponse:
type: 'object'
properties:
join:
type: 'string'
+45
View File
@@ -0,0 +1,45 @@
'use strict';
const { v4: uuidV4 } = require('uuid');
module.exports = class ServerApi {
constructor(host = null, authorization = null, api_key_secret = null) {
this._host = host;
this._authorization = authorization;
this._api_key_secret = api_key_secret;
}
isAuthorized() {
if (this._authorization != this._api_key_secret) return false;
return true;
}
getMeetingURL() {
return this.getProtocol() + this._host + '/join/' + uuidV4();
}
getJoinURL(data) {
return (
this.getProtocol() +
this._host +
'/join?room=' +
data.room +
'&name=' +
data.name +
'&audio=' +
data.audio +
'&video=' +
data.video +
'&screen=' +
data.screen +
'&hide=' +
data.hide +
'&notify=' +
data.notify
);
}
getProtocol() {
return 'http' + (this._host.includes('localhost') ? '' : 's') + '://';
}
};
+35 -16
View File
@@ -38,7 +38,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.2.72
* @version 1.2.75
*
*/
@@ -56,6 +56,7 @@ const path = require('path');
const axios = require('axios');
const app = express();
const checkXSS = require('./xss.js');
const ServerApi = require('./api');
const Host = require('./host');
const Logs = require('./logs');
const log = new Logs('server');
@@ -426,32 +427,50 @@ app.post(['/login'], (req, res) => {
For api docs we use: https://swagger.io/
*/
// request meeting room endpoint
app.post([apiBasePath + '/meeting'], (req, res) => {
// check if user was authorized for the api call
const { headers, body } = req;
const authorization = headers.authorization;
if (authorization != api_key_secret) {
// API request meeting room endpoint
app.post([`${apiBasePath}/meeting`], (req, res) => {
const host = req.headers.host;
const authorization = req.headers.authorization;
const api = new ServerApi(host, authorization, api_key_secret);
if (!api.isAuthorized()) {
log.debug('MiroTalk get meeting - Unauthorized', {
headers: headers,
body: body,
header: req.headers,
body: req.body,
});
return res.status(403).json({ error: 'Unauthorized!' });
}
// setup meeting URL
const host = req.headers.host;
const meetingURL = getMeetingURL(host);
const meetingURL = api.getMeetingURL();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ meeting: meetingURL }));
// log.debug the output if all done
log.debug('MiroTalk get meeting - Authorized', {
headers: headers,
body: body,
header: req.headers,
body: req.body,
meeting: meetingURL,
});
});
// API request join room endpoint
app.post([`${apiBasePath}/join`], (req, res) => {
const host = req.headers.host;
const authorization = req.headers.authorization;
const api = new ServerApi(host, authorization, api_key_secret);
if (!api.isAuthorized()) {
log.debug('MiroTalk get join - Unauthorized', {
header: req.headers,
body: req.body,
});
return res.status(403).json({ error: 'Unauthorized!' });
}
const joinURL = api.getJoinURL(req.body);
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify({ join: joinURL }));
log.debug('MiroTalk get join - Authorized', {
header: req.headers,
body: req.body,
join: joinURL,
});
});
/*
MiroTalk Slack app v1
https://api.slack.com/authentication/verifying-requests-from-slack
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.2.72",
"version": "1.2.75",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
@@ -37,8 +37,8 @@
"license": "AGPL-3.0",
"homepage": "https://github.com/miroslavpejic85/mirotalk",
"dependencies": {
"@sentry/integrations": "^7.93.0",
"@sentry/node": "^7.93.0",
"@sentry/integrations": "^7.94.1",
"@sentry/node": "^7.94.1",
"axios": "^1.6.5",
"body-parser": "^1.20.2",
"colors": "^1.4.0",
+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.2.72
* @version 1.2.75
*
*/