[mirotalksfu] - lock the room by the password
هذا الالتزام موجود في:
@@ -11,6 +11,7 @@ module.exports = class Room {
|
|||||||
this.router = null;
|
this.router = null;
|
||||||
this.io = io;
|
this.io = io;
|
||||||
this._isLocked = false;
|
this._isLocked = false;
|
||||||
|
this._roomPassword = null;
|
||||||
this.peers = new Map();
|
this.peers = new Map();
|
||||||
this.createTheRouter();
|
this.createTheRouter();
|
||||||
}
|
}
|
||||||
@@ -193,11 +194,15 @@ module.exports = class Room {
|
|||||||
// ROOM STATUS
|
// ROOM STATUS
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
|
getPassword() {
|
||||||
|
return this._roomPassword;
|
||||||
|
}
|
||||||
isLocked() {
|
isLocked() {
|
||||||
return this._isLocked;
|
return this._isLocked;
|
||||||
}
|
}
|
||||||
setLocked(status) {
|
setLocked(status, password) {
|
||||||
this._isLocked = status;
|
this._isLocked = status;
|
||||||
|
this._roomPassword = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|||||||
@@ -241,17 +241,32 @@ io.on('connection', (socket) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('roomAction', (action) => {
|
socket.on('roomAction', (data) => {
|
||||||
switch (action) {
|
log.debug('Room action:', data);
|
||||||
|
switch (data.action) {
|
||||||
case 'lock':
|
case 'lock':
|
||||||
roomList.get(socket.room_id).setLocked(true);
|
roomList.get(socket.room_id).setLocked(true, data.password);
|
||||||
|
roomList.get(socket.room_id).broadCast(socket.id, 'roomAction', data.action);
|
||||||
|
break;
|
||||||
|
case 'checkPassword':
|
||||||
|
let roomData = {
|
||||||
|
room: null,
|
||||||
|
password: 'KO',
|
||||||
|
};
|
||||||
|
if (data.password == roomList.get(socket.room_id).getPassword()) {
|
||||||
|
roomData.room = roomList.get(socket.room_id).toJson();
|
||||||
|
roomData.password = 'OK'
|
||||||
|
roomList.get(socket.room_id).sendTo(socket.id, 'roomPassword', roomData);
|
||||||
|
} else {
|
||||||
|
roomList.get(socket.room_id).sendTo(socket.id, 'roomPassword', roomData);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'unlock':
|
case 'unlock':
|
||||||
roomList.get(socket.room_id).setLocked(false);
|
roomList.get(socket.room_id).setLocked(false);
|
||||||
|
roomList.get(socket.room_id).broadCast(socket.id, 'roomAction', data.action);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
log.debug('Room locked:', roomList.get(socket.room_id).isLocked());
|
log.debug('Room locked:', roomList.get(socket.room_id).isLocked());
|
||||||
roomList.get(socket.room_id).broadCast(socket.id, 'roomAction', action);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('peerAction', (data) => {
|
socket.on('peerAction', (data) => {
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ class RoomClient {
|
|||||||
this.recScreenStream = null;
|
this.recScreenStream = null;
|
||||||
this._isRecording = false;
|
this._isRecording = false;
|
||||||
|
|
||||||
|
this.RoomPassword = null;
|
||||||
|
|
||||||
// file transfer settings
|
// file transfer settings
|
||||||
this.fileToSend = null;
|
this.fileToSend = null;
|
||||||
this.fileReader = null;
|
this.fileReader = null;
|
||||||
@@ -186,16 +188,12 @@ class RoomClient {
|
|||||||
.then(
|
.then(
|
||||||
async function (room) {
|
async function (room) {
|
||||||
if (room === 'isLocked') {
|
if (room === 'isLocked') {
|
||||||
this.roomIsLocked();
|
this.event(_EVENTS.roomLock);
|
||||||
|
console.log('00-WARNING ----> Room is Locked, Try to unlock by the password');
|
||||||
|
this.unlockTheRoom();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await this.handleRoomInfo(room);
|
await this.joinAllowed(room);
|
||||||
const data = await this.socket.request('getRouterRtpCapabilities');
|
|
||||||
this.device = await this.loadDevice(data);
|
|
||||||
console.log('07 ----> Get Router Rtp Capabilities codecs: ', this.device.rtpCapabilities.codecs);
|
|
||||||
await this.initTransports(this.device);
|
|
||||||
this.startLocalMedia();
|
|
||||||
this.socket.emit('getProducers');
|
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
)
|
)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -203,6 +201,16 @@ class RoomClient {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async joinAllowed(room) {
|
||||||
|
await this.handleRoomInfo(room);
|
||||||
|
const data = await this.socket.request('getRouterRtpCapabilities');
|
||||||
|
this.device = await this.loadDevice(data);
|
||||||
|
console.log('07 ----> Get Router Rtp Capabilities codecs: ', this.device.rtpCapabilities.codecs);
|
||||||
|
await this.initTransports(this.device);
|
||||||
|
this.startLocalMedia();
|
||||||
|
this.socket.emit('getProducers');
|
||||||
|
}
|
||||||
|
|
||||||
async handleRoomInfo(room) {
|
async handleRoomInfo(room) {
|
||||||
let peers = new Map(JSON.parse(room.peers));
|
let peers = new Map(JSON.parse(room.peers));
|
||||||
participantsCount = peers.size;
|
participantsCount = peers.size;
|
||||||
@@ -427,6 +435,14 @@ class RoomClient {
|
|||||||
}.bind(this),
|
}.bind(this),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.socket.on(
|
||||||
|
'roomPassword',
|
||||||
|
function (data) {
|
||||||
|
console.log('Room password:', data.password);
|
||||||
|
this.roomPassword(data);
|
||||||
|
}.bind(this),
|
||||||
|
);
|
||||||
|
|
||||||
this.socket.on(
|
this.socket.on(
|
||||||
'peerAction',
|
'peerAction',
|
||||||
function (data) {
|
function (data) {
|
||||||
@@ -2037,12 +2053,53 @@ class RoomClient {
|
|||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
roomAction(action, emit = true) {
|
roomAction(action, emit = true) {
|
||||||
if (emit) this.socket.emit('roomAction', action);
|
let data = {
|
||||||
|
action: action,
|
||||||
|
password: null,
|
||||||
|
};
|
||||||
|
if (emit) {
|
||||||
|
switch (action) {
|
||||||
|
case 'lock':
|
||||||
|
Swal.fire({
|
||||||
|
allowOutsideClick: false,
|
||||||
|
allowEscapeKey: false,
|
||||||
|
background: swalBackground,
|
||||||
|
imageUrl: image.locked,
|
||||||
|
input: 'text',
|
||||||
|
inputPlaceholder: 'Set Room password',
|
||||||
|
confirmButtonText: `OK`,
|
||||||
|
showClass: {
|
||||||
|
popup: 'animate__animated animate__fadeInDown',
|
||||||
|
},
|
||||||
|
hideClass: {
|
||||||
|
popup: 'animate__animated animate__fadeOutUp',
|
||||||
|
},
|
||||||
|
inputValidator: (pwd) => {
|
||||||
|
if (!pwd) return 'Please enter the Room password';
|
||||||
|
this.RoomPassword = pwd;
|
||||||
|
},
|
||||||
|
}).then(() => {
|
||||||
|
data.password = this.RoomPassword;
|
||||||
|
this.socket.emit('roomAction', data);
|
||||||
|
this.roomStatus(action);
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'unlock':
|
||||||
|
this.socket.emit('roomAction', data);
|
||||||
|
this.roomStatus(action);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.roomStatus(action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
roomStatus(action) {
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'lock':
|
case 'lock':
|
||||||
this.sound('locked');
|
this.sound('locked');
|
||||||
this.event(_EVENTS.roomLock);
|
this.event(_EVENTS.roomLock);
|
||||||
this.userLog('info', '🔒 LOCKED the room, no one can access!', 'top-end');
|
this.userLog('info', '🔒 LOCKED the room with the password: ' + this.RoomPassword, 'top-end');
|
||||||
break;
|
break;
|
||||||
case 'unlock':
|
case 'unlock':
|
||||||
this.event(_EVENTS.roomUnlock);
|
this.event(_EVENTS.roomUnlock);
|
||||||
@@ -2051,12 +2108,53 @@ class RoomClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
roomPassword(data) {
|
||||||
|
switch (data.password) {
|
||||||
|
case 'OK':
|
||||||
|
this.joinAllowed(data.room);
|
||||||
|
break;
|
||||||
|
case 'KO':
|
||||||
|
this.roomIsLocked();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ####################################################
|
// ####################################################
|
||||||
// HANDLE ROOM ACTION
|
// HANDLE ROOM ACTION
|
||||||
// ####################################################
|
// ####################################################
|
||||||
|
|
||||||
|
unlockTheRoom() {
|
||||||
|
Swal.fire({
|
||||||
|
allowOutsideClick: false,
|
||||||
|
allowEscapeKey: false,
|
||||||
|
background: swalBackground,
|
||||||
|
imageUrl: image.locked,
|
||||||
|
title: 'Oops, Room Locked',
|
||||||
|
text: 'The room is locked, Enter the Room password',
|
||||||
|
input: 'text',
|
||||||
|
inputPlaceholder: 'Enter the Room password',
|
||||||
|
confirmButtonText: `OK`,
|
||||||
|
showClass: {
|
||||||
|
popup: 'animate__animated animate__fadeInDown',
|
||||||
|
},
|
||||||
|
hideClass: {
|
||||||
|
popup: 'animate__animated animate__fadeOutUp',
|
||||||
|
},
|
||||||
|
inputValidator: (pwd) => {
|
||||||
|
if (!pwd) return 'Please enter the Room password';
|
||||||
|
this.RoomPassword = pwd;
|
||||||
|
},
|
||||||
|
}).then(() => {
|
||||||
|
let data = {
|
||||||
|
action: 'checkPassword',
|
||||||
|
password: this.RoomPassword,
|
||||||
|
}
|
||||||
|
this.socket.emit('roomAction', data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
roomIsLocked() {
|
roomIsLocked() {
|
||||||
this.sound('locked');
|
this.sound('eject');
|
||||||
this.event(_EVENTS.roomLock);
|
this.event(_EVENTS.roomLock);
|
||||||
console.log('Room is Locked, try with another one');
|
console.log('Room is Locked, try with another one');
|
||||||
Swal.fire({
|
Swal.fire({
|
||||||
@@ -2064,7 +2162,7 @@ class RoomClient {
|
|||||||
background: swalBackground,
|
background: swalBackground,
|
||||||
position: 'center',
|
position: 'center',
|
||||||
imageUrl: image.locked,
|
imageUrl: image.locked,
|
||||||
title: 'Oops, Room Locked',
|
title: 'Oops, Wrong Room Password',
|
||||||
text: 'The room is locked, try with another one.',
|
text: 'The room is locked, try with another one.',
|
||||||
showDenyButton: false,
|
showDenyButton: false,
|
||||||
confirmButtonText: `Ok`,
|
confirmButtonText: `Ok`,
|
||||||
|
|||||||
المرجع في مشكلة جديدة
حظر مستخدم