[mirotalksfu] - improve webhook, add readme
هذا الالتزام موجود في:
@@ -63,10 +63,12 @@ module.exports = class Logger {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
getDateTime() {
|
getDateTime(color = true) {
|
||||||
const currentTime = new Date().toLocaleString('en-US', this.tzOptions);
|
const now = new Date();
|
||||||
const milliseconds = String(new Date().getMilliseconds()).padStart(3, '0');
|
const currentTime = now.toLocaleString('en-US', this.tzOptions);
|
||||||
return colors.cyan(`${currentTime}:${milliseconds}`);
|
const milliseconds = String(now.getMilliseconds()).padStart(3, '0');
|
||||||
|
const timestamp = `${currentTime}:${milliseconds}`;
|
||||||
|
return color ? colors.cyan(timestamp) : timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormatTime(ms) {
|
getFormatTime(ms) {
|
||||||
|
|||||||
@@ -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 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
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.04
|
* @version 1.7.05
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -2843,6 +2843,8 @@ function startServer() {
|
|||||||
|
|
||||||
if (webhook.enabled) {
|
if (webhook.enabled) {
|
||||||
const data = {
|
const data = {
|
||||||
|
timestamp: log.getDateTime(false),
|
||||||
|
room_id: socket.room_id,
|
||||||
peer_name: peer_name,
|
peer_name: peer_name,
|
||||||
presenter: isPresenter,
|
presenter: isPresenter,
|
||||||
reason: reason,
|
reason: reason,
|
||||||
@@ -2895,12 +2897,12 @@ function startServer() {
|
|||||||
log.info('[REMOVE ME] - Last peer - current active RTMP streams', activeStreams);
|
log.info('[REMOVE ME] - Last peer - current active RTMP streams', activeStreams);
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.room_id = null;
|
|
||||||
|
|
||||||
if (isPresenter) removeIP(socket);
|
if (isPresenter) removeIP(socket);
|
||||||
|
|
||||||
if (webhook.enabled) {
|
if (webhook.enabled) {
|
||||||
const data = {
|
const data = {
|
||||||
|
timestamp: log.getDateTime(false),
|
||||||
|
room_id: socket.room_id,
|
||||||
peer_name: peer_name,
|
peer_name: peer_name,
|
||||||
presenter: isPresenter,
|
presenter: isPresenter,
|
||||||
};
|
};
|
||||||
@@ -2911,6 +2913,8 @@ function startServer() {
|
|||||||
.catch((error) => log.error('Error tracking exitRoom event:', error.message));
|
.catch((error) => log.error('Error tracking exitRoom event:', error.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
socket.room_id = null;
|
||||||
|
|
||||||
callback('Successfully exited room');
|
callback('Successfully exited room');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mirotalksfu",
|
"name": "mirotalksfu",
|
||||||
"version": "1.7.04",
|
"version": "1.7.05",
|
||||||
"description": "WebRTC SFU browser-based video calls",
|
"description": "WebRTC SFU browser-based video calls",
|
||||||
"main": "Server.js",
|
"main": "Server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -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 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
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.04
|
* @version 1.7.05
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -4904,7 +4904,7 @@ function showAbout() {
|
|||||||
imageUrl: image.about,
|
imageUrl: image.about,
|
||||||
customClass: { image: 'img-about' },
|
customClass: { image: 'img-about' },
|
||||||
position: 'center',
|
position: 'center',
|
||||||
title: 'WebRTC SFU v1.7.04',
|
title: 'WebRTC SFU v1.7.05',
|
||||||
html: `
|
html: `
|
||||||
<br />
|
<br />
|
||||||
<div id="about">
|
<div id="about">
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* @license For commercial or closed source, contact us at license.mirotalk@gmail.com or purchase directly via CodeCanyon
|
* @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
|
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
|
||||||
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
|
||||||
* @version 1.7.04
|
* @version 1.7.05
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
50
webhook/README.md
Normal file
50
webhook/README.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# Webhooks Example
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
This example shows how to set up a server to listen for MiroTalk SFU webhook events (join, exitRoom, disconnect).
|
||||||
|
|
||||||
|
### Step 1: Enable Webhooks
|
||||||
|
|
||||||
|
Edit `app/src/config.js` to enable webhooks:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
webhook: {
|
||||||
|
enabled: true, // Enable webhook functionality
|
||||||
|
url: 'http://localhost:8888/webhook-endpoint', // Webhook server URL
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Step 2: Run the Webhook Server
|
||||||
|
|
||||||
|
1. **Install dependencies**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Start the server**:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm start
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### Step 3: Webhook Events
|
||||||
|
|
||||||
|
MiroTalk SFU sends HTTP `POST` requests to the specified URL with event data:
|
||||||
|
|
||||||
|
**Example Payload**:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"event": "join",
|
||||||
|
"data": {}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Events**: `join`, `exit`, `disconnect`.
|
||||||
|
- **Data**: Includes `event` and custom `data`.
|
||||||
@@ -15,10 +15,6 @@ app.post('/webhook-endpoint', (req, res) => {
|
|||||||
|
|
||||||
// Handle different events
|
// Handle different events
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case 'disconnect':
|
|
||||||
console.log('User disconnected:', data);
|
|
||||||
// Add your custom logic here
|
|
||||||
break;
|
|
||||||
case 'join':
|
case 'join':
|
||||||
console.log('User joined:', data);
|
console.log('User joined:', data);
|
||||||
// Add your custom logic here
|
// Add your custom logic here
|
||||||
@@ -27,6 +23,10 @@ app.post('/webhook-endpoint', (req, res) => {
|
|||||||
console.log('User exited:', data);
|
console.log('User exited:', data);
|
||||||
// Add your custom logic here
|
// Add your custom logic here
|
||||||
break;
|
break;
|
||||||
|
case 'disconnect':
|
||||||
|
console.log('User disconnected:', data);
|
||||||
|
// Add your custom logic here
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
console.error('Unknown event type');
|
console.error('Unknown event type');
|
||||||
break;
|
break;
|
||||||
|
|||||||
ثنائية
webhook/webhooks.png
Normal file
ثنائية
webhook/webhooks.png
Normal file
ملف ثنائي غير معروض.
|
بعد العرض: | الارتفاع: | الحجم: 5.4 KiB |
المرجع في مشكلة جديدة
حظر مستخدم