[mirotalksfu] - add Room Lock/Unlock

main
Miroslav Pejic 5 years ago
parent 2efec309e8
commit dced5c66c6

@ -147,6 +147,12 @@
<button id="stopScreenButton" class="hidden">
<i class="fas fa-stop-circle"></i>
</button>
<button id="lockRoomButton" class="hidden">
<i class="fas fa-lock-open"></i>
</button>
<button id="unlockRoomButton" class="hidden">
<i class="fas fa-lock"></i>
</button>
<button id="aboutButton" class="hidden">
<i class="fas fa-question"></i>
</button>

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

@ -67,6 +67,8 @@ function initClient() {
setTippy('stopVideoButton', 'Stop Video', 'bottom');
setTippy('startScreenButton', 'Start Screen', 'bottom');
setTippy('stopScreenButton', 'Stop Screen', 'bottom');
setTippy('lockRoomButton', 'Room Lock', 'bottom');
setTippy('unlockRoomButton', 'Room Unlock', 'bottom');
setTippy('aboutButton', 'About', 'bottom');
}
initEnumerateDevices();
@ -273,7 +275,7 @@ async function shareRoom(useNavigator = false) {
background: swalBackground,
imageUrl: swalImageUrl,
imageWidth: 300,
imageHeight: 200,
imageHeight: 150,
position: 'center',
title: '<strong>Hello ' + peer_name + '</strong>',
html:
@ -400,6 +402,7 @@ function roomIsReady() {
if (isAudioAllowed) show(startAudioButton);
if (isVideoAllowed) show(startVideoButton);
show(videoMedia);
show(lockRoomButton);
show(aboutButton);
handleButtons();
handleSelects();
@ -553,6 +556,12 @@ function handleButtons() {
stopScreenButton.onclick = () => {
rc.closeProducer(RoomClient.mediaType.screen);
};
lockRoomButton.onclick = () => {
rc.roomAction('lock');
};
unlockRoomButton.onclick = () => {
rc.roomAction('unlock');
};
aboutButton.onclick = () => {
showAbout();
};
@ -667,6 +676,14 @@ function handleRoomClientEvents() {
hide(stopScreenButton);
show(startScreenButton);
});
rc.on(RoomClient.EVENTS.roomLock, () => {
hide(lockRoomButton);
show(unlockRoomButton);
});
rc.on(RoomClient.EVENTS.roomUnlock, () => {
hide(unlockRoomButton);
show(lockRoomButton);
});
rc.on(RoomClient.EVENTS.exitRoom, () => {
window.location.href = '/newroom';
});
@ -715,7 +732,7 @@ function showAbout() {
background: swalBackground,
imageUrl: swalImageUrl,
imageWidth: 300,
imageHeight: 200,
imageHeight: 150,
position: 'center',
html: `
<br/>

@ -11,6 +11,7 @@ const html = {
const image = {
poster: '../images/loader.gif',
delete: '../images/delete.png',
locked: '../images/locked.png',
};
const mediaType = {
@ -39,6 +40,8 @@ const _EVENTS = {
pauseScreen: 'pauseScreen',
resumeScreen: 'resumeScreen',
stopScreen: 'stopScreen',
roomLock: 'roomLock',
roomUnlock: 'roomUnlock',
};
let recordedBlobs;
@ -171,6 +174,10 @@ class RoomClient {
.request('join', data)
.then(
async function (room) {
if (room === 'isLocked') {
this.roomIsLocked();
return;
}
this.connectedRoom = room;
console.log('07 ----> Joined to room', this.connectedRoom);
const data = await this.socket.request('getRouterRtpCapabilities');
@ -359,11 +366,19 @@ class RoomClient {
this.socket.on(
'message',
function (data) {
console.log('message', data);
console.log('Message', data);
this.showMessage(data);
}.bind(this),
);
this.socket.on(
'roomAction',
function (data) {
console.log('Room action:', data);
this.roomAction(data, false);
}.bind(this),
);
this.socket.on(
'disconnect',
function () {
@ -1365,4 +1380,51 @@ class RoomClient {
this.event(_EVENTS.stopRec);
this.sound('recStop');
}
// ####################################################
// ROOM ACTION
// ####################################################
roomAction(action, emit = true) {
if (emit) this.socket.emit('roomAction', action);
switch (action) {
case 'lock':
this.sound('locked');
this.event(_EVENTS.roomLock);
this.userLog('info', '🔒 LOCKED the room, no one can access!', 'top-end');
break;
case 'unlock':
this.event(_EVENTS.roomUnlock);
this.userLog('info', '🔓 UNLOCKED the room', 'top-end');
break;
}
}
// ####################################################
// HANDLE ROOM ACTION
// ####################################################
roomIsLocked() {
this.sound('locked');
this.event(_EVENTS.roomLock);
console.log('Room is Locked, try with another one');
Swal.fire({
allowOutsideClick: false,
background: swalBackground,
position: 'center',
imageUrl: image.locked,
title: 'Oops, Room Locked',
text: 'The room is locked, try with another one.',
showDenyButton: false,
confirmButtonText: `Ok`,
showClass: {
popup: 'animate__animated animate__fadeInDown',
},
hideClass: {
popup: 'animate__animated animate__fadeOutUp',
},
}).then((result) => {
if (result.isConfirmed) this.exit();
});
}
}

Binary file not shown.

@ -10,6 +10,7 @@ module.exports = class Room {
this.worker = worker;
this.router = null;
this.io = io;
this._isLocked = false;
this.peers = new Map();
this.createTheRouter();
}
@ -187,6 +188,17 @@ module.exports = class Room {
this.peers.get(socket_id).closeProducer(producer_id);
}
// ####################################################
// ROOM STATUS
// ####################################################
isLocked() {
return this._isLocked;
}
setLocked(status) {
this._isLocked = status;
}
// ####################################################
// SENDER
// ####################################################

@ -203,16 +203,36 @@ io.on('connection', (socket) => {
}
});
socket.on('join', (data, cb) => {
log.debug('User joined', data);
socket.on('roomAction', (action) => {
switch (action) {
case 'lock':
roomList.get(socket.room_id).setLocked(true);
break;
case 'unlock':
roomList.get(socket.room_id).setLocked(false);
break;
}
log.debug('Room locked:', roomList.get(socket.room_id).isLocked());
// send to all participants
roomList.get(socket.room_id).broadCast(socket.id, 'roomAction', action);
});
socket.on('join', (data, cb) => {
if (!roomList.has(socket.room_id)) {
return cb({
error: 'Room does not exist',
});
}
log.debug('User joined', data);
roomList.get(socket.room_id).addPeer(new Peer(socket.id, data));
if (roomList.get(socket.room_id).isLocked()) {
log.debug('User rejected because room is locked');
cb('isLocked');
return;
}
cb(roomList.get(socket.room_id).toJson());
});
@ -327,6 +347,10 @@ io.on('connection', (socket) => {
log.debug('Disconnect', getPeerName());
roomList.get(socket.room_id).removePeer(socket.id);
if (roomList.get(socket.room_id).getPeers().size === 0 && roomList.get(socket.room_id).isLocked()) {
roomList.get(socket.room_id).setLocked(false);
}
});
socket.on('exitRoom', async (_, callback) => {

Loading…
Cancel
Save