-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
534f2f7
commit 57faf15
Showing
7 changed files
with
116 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ dev dependencies: { | |
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon | ||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 | ||
* @author Miroslav Pejic - [email protected] | ||
* @version 1.7.02 | ||
* @version 1.7.03 | ||
* | ||
*/ | ||
|
||
|
@@ -181,6 +181,12 @@ if (sentryEnabled) { | |
*/ | ||
} | ||
|
||
// Handle WebHook | ||
const webhook = { | ||
enabled: config?.webhook?.enabled || false, | ||
url: config?.webhook?.url || 'http://localhost:8888/webhook-endpoint', | ||
}; | ||
|
||
// Discord Bot | ||
const { enabled, commands, token } = config.discord || {}; | ||
|
||
|
@@ -1182,6 +1188,7 @@ function startServer() { | |
stats_enabled: config.stats?.enabled ? config.stats : false, | ||
ngrok_enabled: config.ngrok?.enabled ? config.ngrok : false, | ||
email_alerts: config.email?.alert ? config.email : false, | ||
webhook: webhook, | ||
|
||
// Version Information | ||
app_version: packageJson.version, | ||
|
@@ -1526,6 +1533,15 @@ function startServer() { | |
}); // config.email.alert: true | ||
} | ||
|
||
// handle WebHook | ||
if (webhook.enabled) { | ||
// Trigger a POST request when a user joins | ||
axios | ||
.post(webhook.url, { event: 'join', data }) | ||
.then((response) => log.debug('Join event tracked:', response.data)) | ||
.catch((error) => log.error('Error tracking join event:', error.message)); | ||
} | ||
|
||
cb(room.toJson()); | ||
}); | ||
|
||
|
@@ -2789,7 +2805,7 @@ function startServer() { | |
room.broadCast(socket.id, 'editorUpdate', data); | ||
}); | ||
|
||
socket.on('disconnect', () => { | ||
socket.on('disconnect', (reason) => { | ||
if (!roomExists(socket)) return; | ||
|
||
const { room, peer } = getRoomAndPeer(socket); | ||
|
@@ -2798,7 +2814,7 @@ function startServer() { | |
|
||
const isPresenter = isPeerPresenter(socket.room_id, socket.id, peer_name, peer_uuid); | ||
|
||
log.debug('[Disconnect] - peer name', peer_name); | ||
log.debug('[Disconnect] - peer name', { peer_name, reason }); | ||
|
||
room.removePeer(socket.id); | ||
|
||
|
@@ -2825,6 +2841,19 @@ function startServer() { | |
|
||
if (isPresenter) removeIP(socket); | ||
|
||
if (webhook.enabled) { | ||
const data = { | ||
peer_name: peer_name, | ||
presenter: isPresenter, | ||
reason: reason, | ||
}; | ||
// Trigger a POST request when a user disconnects | ||
axios | ||
.post(webhook.url, { event: 'disconnect', data }) | ||
.then((response) => log.debug('Disconnect event tracked:', response.data)) | ||
.catch((error) => log.error('Error tracking disconnect event:', error.message)); | ||
} | ||
|
||
socket.room_id = null; | ||
}); | ||
|
||
|
@@ -2870,6 +2899,18 @@ function startServer() { | |
|
||
if (isPresenter) removeIP(socket); | ||
|
||
if (webhook.enabled) { | ||
const data = { | ||
peer_name: peer_name, | ||
presenter: isPresenter, | ||
}; | ||
// Trigger a POST request when a user exits | ||
axios | ||
.post(webhook.url, { event: 'exit', data }) | ||
.then((response) => log.debug('ExitROom event tracked:', response.data)) | ||
.catch((error) => log.error('Error tracking exitRoom event:', error.message)); | ||
} | ||
|
||
callback('Successfully exited room'); | ||
}); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 [email protected] or purchase directly via CodeCanyon | ||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 | ||
* @author Miroslav Pejic - [email protected] | ||
* @version 1.7.02 | ||
* @version 1.7.03 | ||
* | ||
*/ | ||
|
||
|
@@ -4904,7 +4904,7 @@ function showAbout() { | |
imageUrl: image.about, | ||
customClass: { image: 'img-about' }, | ||
position: 'center', | ||
title: 'WebRTC SFU v1.7.02', | ||
title: 'WebRTC SFU v1.7.03', | ||
html: ` | ||
<br /> | ||
<div id="about"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon | ||
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970 | ||
* @author Miroslav Pejic - [email protected] | ||
* @version 1.7.02 | ||
* @version 1.7.03 | ||
* | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "mirotalk-webhook", | ||
"version": "1.0.0", | ||
"description": "MiroTalk WebHook endpoint example", | ||
"main": "server.js", | ||
"scripts": { | ||
"start": "node server.js" | ||
}, | ||
"keywords": [ | ||
"webhook", | ||
"server" | ||
], | ||
"author": "Miroslav Pejic", | ||
"license": "AGPLv3", | ||
"dependencies": { | ||
"express": "4.21.2", | ||
"body-parser": "1.20.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const bodyParser = require('body-parser'); | ||
|
||
const app = express(); | ||
const port = 8888; | ||
|
||
// Middleware to parse JSON bodies | ||
app.use(bodyParser.json()); | ||
|
||
// Endpoint to receive webhooks | ||
app.post('/webhook-endpoint', (req, res) => { | ||
const { event, data } = req.body; | ||
|
||
// Handle different events | ||
switch (event) { | ||
case 'disconnect': | ||
console.log('User disconnected:', data); | ||
// Add your custom logic here | ||
break; | ||
case 'join': | ||
console.log('User joined:', data); | ||
// Add your custom logic here | ||
break; | ||
case 'exit': | ||
console.log('User exited:', data); | ||
// Add your custom logic here | ||
break; | ||
default: | ||
console.error('Unknown event type'); | ||
break; | ||
} | ||
|
||
res.status(200).send('Webhook received'); | ||
}); | ||
|
||
// Start the server | ||
app.listen(port, () => { | ||
console.log(`Webhook server running on http://localhost:${port}`); | ||
}); |