Skip to content

Commit

Permalink
[mirotalksfu] - add roomsAllowed, fix, update dep
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Oct 18, 2024
1 parent d177bbb commit c29e777
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 35 deletions.
57 changes: 51 additions & 6 deletions app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.88
* @version 1.5.89
*
*/

Expand Down Expand Up @@ -141,6 +141,7 @@ const hostCfg = {
user_auth: config.host.user_auth,
users_from_db: config.host.users_from_db,
users_api_room_allowed: config.host.users_api_room_allowed,
users_api_rooms_allowed: config.host.users_api_rooms_allowed,
users_api_endpoint: config.host.users_api_endpoint,
users_api_secret_key: config.host.users_api_secret_key,
users: config.host.users,
Expand Down Expand Up @@ -647,15 +648,18 @@ function startServer() {
config.presenters.list.includes(username).toString();

const token = encodeToken({ username: username, password: password, presenter: isPresenter });
return res.status(200).json({ message: token });
const allowedRooms = await getUserAllowedRooms(username, password);

return res.status(200).json({ message: token, allowedRooms: allowedRooms });
}

if (isPeerValid) {
log.debug('PEER LOGIN OK', { ip: ip, authorized: true });
const isPresenter =
config.presenters && config.presenters.list && config.presenters.list.includes(username).toString();
const token = encodeToken({ username: username, password: password, presenter: isPresenter });
return res.status(200).json({ message: token });
const allowedRooms = await getUserAllowedRooms(username, password);
return res.status(200).json({ message: token, allowedRooms: allowedRooms });
} else {
return res.status(401).json({ message: 'unauthorized' });
}
Expand Down Expand Up @@ -1254,10 +1258,9 @@ function startServer() {
});
return cb('unauthorized');
}
} else {
if (!hostCfg.users_from_db) return cb('unauthorized');
}
// else {
// return cb('unauthorized');
// }

if (!hostCfg.users_from_db) {
const roomAllowedForUser = isRoomAllowedForUser('[Join]', peer_name, room.id);
Expand Down Expand Up @@ -2949,6 +2952,48 @@ function startServer() {
return allowRoomAccess;
}

async function getUserAllowedRooms(username, password) {
// Gel user allowed rooms from db...
if (hostCfg.protected && hostCfg.users_from_db && hostCfg.users_api_rooms_allowed) {
try {
// Using either email or username, as the username can also be an email here.
const response = await axios.post(
hostCfg.users_api_rooms_allowed,
{
email: username,
username: username,
password: password,
api_secret_key: hostCfg.users_api_secret_key,
},
{
timeout: 5000, // Timeout set to 5 seconds (5000 milliseconds)
},
);
const allowedRooms = response.data ? response.data.message : {};
log.debug('AXIOS getUserAllowedRooms', allowedRooms);
return allowedRooms;
} catch (error) {
log.error('AXIOS getUserAllowedRooms error', error.message);
return {};
}
}

// Get allowed rooms for user from config.js file
if (hostCfg.protected && !hostCfg.users_from_db) {
const isOIDCEnabled = config.oidc && config.oidc.enabled;

const user = hostCfg.users.find((user) => user.displayname === username || user.username === username);

if (!isOIDCEnabled && !user) {
log.debug('getUserAllowedRooms - user not found', username);
return false;
}
return user.allowed_rooms;
}

return ['*'];
}

async function isRoomAllowedForUser(message, username, room) {
const logData = { message, username, room };

Expand Down
2 changes: 2 additions & 0 deletions app/src/config.template.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,10 @@ module.exports = {
users_from_db: false, // if true ensure that api.token is also set to true.
users_api_endpoint: 'http://localhost:9000/api/v1/user/isAuth',
users_api_room_allowed: 'http://localhost:9000/api/v1/user/isRoomAllowed',
users_api_rooms_allowed: 'http://localhost:9000/api/v1/user/roomsAllowed',
//users_api_endpoint: 'https://webrtc.mirotalk.com/api/v1/user/isAuth',
//users_api_room_allowed: 'https://webrtc.mirotalk.com/api/v1/user/isRoomAllowed',
//users_api_rooms_allowed: 'https://webrtc.mirotalk.com/api/v1/user/roomsAllowed',
users_api_secret_key: 'mirotalkweb_default_secret',
users: [
{
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalksfu",
"version": "1.5.88",
"version": "1.5.89",
"description": "WebRTC SFU browser-based video calls",
"main": "Server.js",
"scripts": {
Expand Down Expand Up @@ -73,11 +73,11 @@
"js-yaml": "^4.1.0",
"jsdom": "^25.0.1",
"jsonwebtoken": "^9.0.2",
"mediasoup": "3.14.15",
"mediasoup": "3.14.16",
"mediasoup-client": "3.7.17",
"ngrok": "^5.0.0-beta.2",
"nodemailer": "^6.9.15",
"openai": "^4.67.3",
"openai": "^4.68.1",
"qs": "6.13.0",
"socket.io": "4.8.0",
"swagger-ui-express": "5.0.1",
Expand Down
8 changes: 8 additions & 0 deletions public/css/landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -2106,3 +2106,11 @@ main {
/* #roomName {
text-align: left;
} */

/*--------------------------------------------------------------
# Login and Join ROOM
--------------------------------------------------------------*/

#joinRoomForm {
display: none;
}
31 changes: 31 additions & 0 deletions public/js/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ console.log(window.location);

const usernameInput = document.getElementById('username');
const passwordInput = document.getElementById('password');
const loginForm = document.getElementById('loginForm');
const loginBtn = document.getElementById('loginButton');

const joinRoomForm = document.getElementById('joinRoomForm');
const selectRoom = document.getElementById('selectRoom');
const joinSelectRoomBtn = document.getElementById('joinSelectRoomButton');

usernameInput.onkeyup = (e) => {
if (e.keyCode === 13) {
e.preventDefault();
Expand All @@ -23,6 +28,10 @@ loginBtn.onclick = (e) => {
login();
};

joinSelectRoomBtn.onclick = (e) => {
join();
};

function login() {
const username = filterXSS(document.getElementById('username').value);
const password = filterXSS(document.getElementById('password').value);
Expand Down Expand Up @@ -50,6 +59,21 @@ function login() {
const token = response.data.message;
window.sessionStorage.peer_token = token;

// Allowed rooms
const allowedRooms = response.data.allowedRooms;
if (allowedRooms && !allowedRooms.includes('*')) {
console.log('User detected with limited join room access!', allowedRooms);
loginForm.style.display = 'none';
joinRoomForm.style.display = 'block';
allowedRooms.forEach((room) => {
const option = document.createElement('option');
option.value = room;
option.text = room;
selectRoom.appendChild(option);
});
return;
}

if (room) {
return (window.location.href = '/join/' + window.location.search);
// return (window.location.href = '/join/?room=' + room + '&token=' + token);
Expand Down Expand Up @@ -80,3 +104,10 @@ function login() {
return;
}
}

function join() {
//window.location.href = '/join/' + selectRoom.value;
const username = filterXSS(document.getElementById('username').value);
const roomId = filterXSS(document.getElementById('selectRoom').value);
window.location.href = '/join/?room=' + roomId + '&name=' + username + '&token=' + window.sessionStorage.peer_token;
}
4 changes: 2 additions & 2 deletions public/js/Room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.88
* @version 1.5.89
*
*/

Expand Down Expand Up @@ -4500,7 +4500,7 @@ function showAbout() {
imageUrl: image.about,
customClass: { image: 'img-about' },
position: 'center',
title: 'WebRTC SFU v1.5.88',
title: 'WebRTC SFU v1.5.89',
html: `
<br />
<div id="about">
Expand Down
2 changes: 1 addition & 1 deletion public/js/RoomClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @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
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.88
* @version 1.5.89
*
*/

Expand Down
58 changes: 35 additions & 23 deletions public/views/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=IBM+Plex+Sans:400,600" />
<link rel="stylesheet" type="text/css" href="../css/landing.css" />

<!-- Bootstrap 5 -->

<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC"
crossorigin="anonymous"
/>
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"
></script>

<!-- Js scripts -->

<script defer src="../js/Brand.js"></script>
Expand All @@ -63,24 +77,7 @@
<header class="site-header">
<div class="container">
<div class="site-header-inner">
<div class="brand header-brand">
<h1 class="m-0">
<a href="/">
<img
class="header-logo-image"
src="../images/logo.svg"
alt="mirotalksfu-webrtc-logo"
/>
<!-- <img
class="header-logo-image reveal-from-left"
src="../images/mirotalk-mc.png"
alt="mirotalksfu-webrtc-logo"
width="96"
height="auto"
/> -->
</a>
</h1>
</div>
<div class="brand header-brand"></div>
</div>
</div>
</header>
Expand Down Expand Up @@ -119,6 +116,25 @@ <h1 class="m-0">
</button>
</div>
</div>
<!-- Join Room Section hidden -->
<div id="joinRoomForm" class="mb-12">
<div class="hero-copy reveal-from-bottom">
<h1 class="hero-title mt-0">
Pick name. <br />
Share URL. <br />
Start conference.
</h1>
</div>
<br />
<div class="mb-12">
<select id="selectRoom" class="form-select text-light bg-dark"></select>
</div>
<div class="mt-24 mb-32">
<button id="joinSelectRoomButton" class="button button-primary button-block">
JOIN ROOM
</button>
</div>
</div>
</div>
<div class="hero-figure anime-element">
<svg class="placeholder" width="528" height="396" viewBox="0 0 528 396">
Expand All @@ -143,11 +159,7 @@ <h1 class="m-0">
<footer id="footer" class="site-footer">
<div class="container">
<div class="site-footer-inner">
<div class="brand footer-brand">
<a href="/">
<img class="header-logo-image" src="../images/logo.svg" alt="Logo" />
</a>
</div>
<div class="brand footer-brand"></div>
<ul class="footer-links list-reset">
<li>
<a href="/about">About</a>
Expand Down

0 comments on commit c29e777

Please sign in to comment.