Merge pull request #66 from loranger/name_per_room

[mirotalksfu] - allow name storage per room
هذا الالتزام موجود في:
Miroslav Pejic
2022-08-31 08:45:15 +02:00
ملتزم من قبل GitHub
الأصل f436bbe182 b2e9e4c3c4
التزام 2d729f83eb

عرض الملف

@@ -393,6 +393,11 @@ function whoAreYou() {
return; return;
} }
let default_name = window.localStorage.peer_name ? window.localStorage.peer_name : '';
if (getCookie(room_id + '_name')) {
default_name = getCookie(room_id + '_name');
}
Swal.fire({ Swal.fire({
allowOutsideClick: false, allowOutsideClick: false,
allowEscapeKey: false, allowEscapeKey: false,
@@ -401,7 +406,7 @@ function whoAreYou() {
imageUrl: image.username, imageUrl: image.username,
input: 'text', input: 'text',
inputPlaceholder: 'Enter your name', inputPlaceholder: 'Enter your name',
inputValue: window.localStorage.peer_name ? window.localStorage.peer_name : '', inputValue: default_name,
html: `<br /> html: `<br />
<div style="overflow: hidden;"> <div style="overflow: hidden;">
<button id="initAudioButton" class="fas fa-microphone" onclick="handleAudio(event)"></button> <button id="initAudioButton" class="fas fa-microphone" onclick="handleAudio(event)"></button>
@@ -417,12 +422,15 @@ function whoAreYou() {
}, },
inputValidator: (name) => { inputValidator: (name) => {
if (!name) return 'Please enter your name'; if (!name) return 'Please enter your name';
if (!getCookie(room_id + '_name')) {
window.localStorage.peer_name = name;
}
setCookie(room_id + '_name', name, 30);
peer_name = name; peer_name = name;
}, },
}).then(() => { }).then(() => {
getPeerInfo(); getPeerInfo();
joinRoom(peer_name, room_id); joinRoom(peer_name, room_id);
window.localStorage.peer_name = peer_name;
}); });
if (!DetectRTC.isMobileDevice) { if (!DetectRTC.isMobileDevice) {
@@ -1256,6 +1264,24 @@ function openURL(url, blank = false) {
blank ? window.open(url, '_blank') : (window.location.href = url); blank ? window.open(url, '_blank') : (window.location.href = url);
} }
function setCookie(name, value, expDays) {
let date = new Date();
date.setTime(date.getTime() + expDays * 24 * 60 * 60 * 1000);
const expires = 'expires=' + date.toUTCString();
document.cookie = name + '=' + value + '; ' + expires + '; path=/';
}
function getCookie(cName) {
const name = cName + '=';
const cDecoded = decodeURIComponent(document.cookie);
const cArr = cDecoded.split('; ');
let res;
cArr.forEach((val) => {
if (val.indexOf(name) === 0) res = val.substring(name.length);
});
return res;
}
// #################################################### // ####################################################
// HANDLE WHITEBOARD // HANDLE WHITEBOARD
// #################################################### // ####################################################