Skip to content

Commit

Permalink
[call-me] - #3 change room with host...
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Dec 28, 2024
1 parent 9cbb9c1 commit 89b8b81
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ SSL=false # true or false
DOMAIN=localhost
PORT=8000

# Host

HOST_PASSWORD_ENABLED=false # true or false
HOST_PASSWORD='123456789'

# Stun

STUN_SERVER_ENABLED=true # true or false
Expand All @@ -17,11 +22,6 @@ TURN_SERVER_URL=turn:a.relay.metered.ca:443
TURN_SERVER_USERNAME=e8dd65b92c62d3e36cafb807
TURN_SERVER_CREDENTIAL=uWdWNmkhvyqTEswO

# Room

ROOM_PASSWORD_ENABLED=false # true or false
ROOM_PASSWORD='123456789'

# API

API_KEY_SECRET=call_me_api_key_secret # change me
Expand Down
22 changes: 11 additions & 11 deletions app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ const config = {
turnServerUrl: process.env.TURN_SERVER_URL,
turnServerUsername: process.env.TURN_SERVER_USERNAME,
turnServerCredential: process.env.TURN_SERVER_CREDENTIAL,
roomPasswordEnabled: process.env.ROOM_PASSWORD_ENABLED === 'true',
roomPassword: process.env.ROOM_PASSWORD || '',
hostPasswordEnabled: process.env.HOST_PASSWORD_ENABLED === 'true',
hostPassword: process.env.HOST_PASSWORD || '',
apiKeySecret: process.env.API_KEY_SECRET,
randomImageUrl: process.env.RANDOM_IMAGE_URL || '',
apiBasePath: '/api/v1',
swaggerDocument: yaml.load(fs.readFileSync(path.join(__dirname, '/api/swagger.yaml'), 'utf8')),
};

// If no room password is specified, a random one is generated (if room password is enabled)
config.roomPassword = process.env.ROOM_PASSWORD || (config.roomPasswordEnabled ? generatePassword() : '');
config.hostPassword = process.env.HOST_PASSWORD || (config.hostPasswordEnabled ? generatePassword() : '');

// Add STUN server if enabled and URL is provided
if (config.stunServerEnabled && config.stunServerUrl) {
Expand Down Expand Up @@ -95,9 +95,9 @@ server.listen(port, () => {
console.log('Server', {
running_at: host,
ice: config.iceServers,
room: {
password_enabled: config.roomPasswordEnabled,
password: config.roomPassword,
host: {
password_enabled: config.hostPasswordEnabled,
password: config.hostPassword,
},
api_key_secret: config.apiKeySecret,
api_docs: apiDocs,
Expand Down Expand Up @@ -152,7 +152,7 @@ app.get('/join/', (req, res) => {
// http://localhost:8000/join?user=user1&password=123456789
// http://localhost:8000/join?user=user2&call=user1&password=123456789

if (config.roomPasswordEnabled && password !== config.roomPassword) {
if (config.hostPasswordEnabled && password !== config.hostPassword) {
return unauthorized(res);
}

Expand Down Expand Up @@ -217,15 +217,15 @@ app.get(`${config.apiBasePath}/users`, (req, res) => {
});

// Check if Room password required
app.get('/api/roomPassword', (req, res) => {
const isPasswordRequired = config.roomPasswordEnabled;
app.get('/api/hostPassword', (req, res) => {
const isPasswordRequired = config.hostPasswordEnabled;
res.json({ isPasswordRequired });
});

// Check if Room password valid
app.post('/api/roomPasswordValidate', (req, res) => {
app.post('/api/hostPasswordValidate', (req, res) => {
const { password } = req.body;
const success = password === config.roomPassword;
const success = password === config.hostPassword;
res.json({ success: success });
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "call-me",
"version": "1.0.36",
"version": "1.0.37",
"description": "Your Go-To for Instant Video Calls",
"author": "Miroslav Pejic - miroslav.pejic.85@gmail.com",
"license": "AGPLv3",
Expand Down
Binary file added public/assets/locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 12 additions & 9 deletions public/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,25 @@ document.addEventListener('DOMContentLoaded', function () {

// githubDiv.style.display = 'none';

async function checkRoomPassword(maxRetries = 3, attempts = 0) {
async function checkHostPassword(maxRetries = 3, attempts = 0) {
try {
// Fetch room configuration
const { data: config } = await axios.get('/api/roomPassword');
// Fetch host configuration
const { data: config } = await axios.get('/api/hostPassword');

if (config.isPasswordRequired) {
// Show prompt for the password
const { value: password } = await Swal.fire({
title: 'Room Protected',
text: 'Please enter the room password:',
title: 'Host Protected',
text: 'Please enter the host password:',
input: 'password',
inputPlaceholder: 'Enter your password',
inputAttributes: {
autocapitalize: 'off',
autocorrect: 'off',
},
imageUrl: 'assets/locked.png',
imageWidth: 150,
imageHeight: 150,
allowOutsideClick: false,
allowEscapeKey: false,
showDenyButton: true,
Expand All @@ -79,7 +82,7 @@ async function checkRoomPassword(maxRetries = 3, attempts = 0) {
}

// Validate the password
const { data: validationResult } = await axios.post('/api/roomPasswordValidate', { password });
const { data: validationResult } = await axios.post('/api/hostPasswordValidate', { password });

if (validationResult.success) {
await Swal.fire({
Expand All @@ -99,7 +102,7 @@ async function checkRoomPassword(maxRetries = 3, attempts = 0) {
text: `Please try again. (${attempts}/${maxRetries} attempts)`,
});
// Retry the process
checkRoomPassword(maxRetries, attempts);
checkHostPassword(maxRetries, attempts);
} else {
await Swal.fire({
icon: 'warning',
Expand All @@ -117,7 +120,7 @@ async function checkRoomPassword(maxRetries = 3, attempts = 0) {
Swal.fire({
icon: 'error',
title: 'Error',
text: 'An error occurred while joining the room.',
text: 'An error occurred while joining the host.',
});
}
}
Expand Down Expand Up @@ -187,7 +190,7 @@ function handleDirectJoin() {
}
}

if (!password) checkRoomPassword();
if (!password) checkHostPassword();
}

// Session Time
Expand Down

0 comments on commit 89b8b81

Please sign in to comment.