Skip to content

Commit

Permalink
[mirotalksfu] - improve collaborative whiteboard
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Jul 4, 2024
1 parent 06e62d4 commit d876180
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 85 deletions.
2 changes: 1 addition & 1 deletion app/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies: {
* @license For commercial or closed source, contact us at [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.4.81
* @version 1.4.82
*
*/

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": "mirotalksfu",
"version": "1.4.81",
"version": "1.4.82",
"description": "WebRTC SFU browser-based video calls",
"main": "Server.js",
"scripts": {
Expand Down
32 changes: 22 additions & 10 deletions public/css/Room.css
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,8 @@ progress {
position: absolute;
margin: auto;
padding: 10px;
width: var(--wb-width);
height: var(--wb-height);
width: calc(var(--wb-width) * 1px);
height: calc(var(--wb-height) * 1px);
background: var(--wb-bg);
border: var(--border);
box-shadow: var(--box-shadow);
Expand All @@ -1160,6 +1160,11 @@ progress {
margin-left: 8px;
}

.whiteboard-header-title button {
font-size: 1.5em;
margin-right: 5px;
}

.whiteboard-header button {
/* padding: 10px; */
border-radius: 5px;
Expand All @@ -1180,25 +1185,32 @@ progress {
.whiteboard-header-options .dropdown-menu {
background: var(--body-bg);
border: none;
max-height: calc(var(--wb-height) * 1px); /* Set a maximum height */
overflow-y: auto; /* Enable vertical scrolling */
max-height: calc(var(--wb-height) * 1px);
overflow-y: auto;
}

.whiteboard-header-options .dropdown-menu button {
background: none;
border: none;
color: #ffffff;
width: 100%;
text-align: left;
padding: 10px;
display: flex;
align-items: center;
justify-content: flex-start;
width: 160px;
font-size: 0.8em;
text-align: left;
padding: 8px 16px;
border: none;
background: none;
cursor: pointer;
}

.whiteboard-header-options .dropdown-menu button:hover {
background: var(--select-bg);
}

.whiteboard-header-options .dropdown-menu button i,
.whiteboard-header-options .dropdown-menu button svg {
margin-right: 8px;
}

.whiteboardColorPicker {
-webkit-appearance: none;
-moz-appearance: none;
Expand Down
177 changes: 106 additions & 71 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 [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.4.81
* @version 1.4.82
*
*/

Expand Down Expand Up @@ -69,8 +69,8 @@ const Base64Prefix = 'data:application/pdf;base64,';

const wbImageInput = 'image/*';
const wbPdfInput = 'application/pdf';
const wbWidth = 1200;
const wbHeight = 600;
const wbWidth = 1280;
const wbHeight = 768;

const swalImageUrl = '../images/pricing-illustration.svg';

Expand Down Expand Up @@ -3165,75 +3165,10 @@ function whiteboardAddObj(type) {
});
break;
case 'imgFile':
Swal.fire({
allowOutsideClick: false,
background: swalBackground,
position: 'center',
title: 'Select the image',
input: 'file',
inputAttributes: {
accept: wbImageInput,
'aria-label': 'Select the image',
},
showDenyButton: true,
confirmButtonText: `OK`,
denyButtonText: `Cancel`,
showClass: { popup: 'animate__animated animate__fadeInDown' },
hideClass: { popup: 'animate__animated animate__fadeOutUp' },
}).then((result) => {
if (result.isConfirmed) {
let wbCanvasImg = result.value;
if (wbCanvasImg && wbCanvasImg.size > 0) {
let reader = new FileReader();
reader.onload = function (event) {
let imgObj = new Image();
imgObj.src = event.target.result;
imgObj.onload = function () {
let image = new fabric.Image(imgObj);
image.set({ top: 0, left: 0 }).scale(0.3);
addWbCanvasObj(image);
};
};
reader.readAsDataURL(wbCanvasImg);
} else {
userLog('error', 'File not selected or empty', 'top-end');
}
}
});
setupFileSelection('Select the image', wbImageInput, renderImageToCanvas);
break;
case 'pdfFile':
Swal.fire({
allowOutsideClick: false,
background: swalBackground,
position: 'center',
title: 'Select the PDF',
input: 'file',
inputAttributes: {
accept: wbPdfInput,
'aria-label': 'Select the PDF',
},
showDenyButton: true,
confirmButtonText: `OK`,
denyButtonText: `Cancel`,
showClass: { popup: 'animate__animated animate__fadeInDown' },
hideClass: { popup: 'animate__animated animate__fadeOutUp' },
}).then((result) => {
if (result.isConfirmed) {
let wbCanvasPdf = result.value;
if (wbCanvasPdf && wbCanvasPdf.size > 0) {
let reader = new FileReader();
reader.onload = async function (event) {
wbCanvas.requestRenderAll();
await pdfToImage(event.target.result, wbCanvas);
whiteboardIsDrawingMode(false);
wbCanvasToJson();
};
reader.readAsDataURL(wbCanvasPdf);
} else {
userLog('error', 'File not selected or empty', 'top-end');
}
}
});
setupFileSelection('Select the PDF', wbPdfInput, renderPdfToCanvas);
break;
case 'text':
const text = new fabric.IText('Lorem Ipsum', {
Expand Down Expand Up @@ -3294,6 +3229,106 @@ function whiteboardAddObj(type) {
}
}

function setupFileSelection(title, accept, renderToCanvas) {
Swal.fire({
allowOutsideClick: false,
background: swalBackground,
position: 'center',
title: title,
input: 'file',
html: `
<div id="dropArea">
<p>Drag and drop your file here</p>
</div>
`,
inputAttributes: {
accept: accept,
'aria-label': title,
},
didOpen: () => {
const dropArea = document.getElementById('dropArea');
dropArea.addEventListener('dragenter', handleDragEnter);
dropArea.addEventListener('dragover', handleDragOver);
dropArea.addEventListener('dragleave', handleDragLeave);
dropArea.addEventListener('drop', handleDrop);
},
showDenyButton: true,
confirmButtonText: `OK`,
denyButtonText: `Cancel`,
showClass: { popup: 'animate__animated animate__fadeInDown' },
hideClass: { popup: 'animate__animated animate__fadeOutUp' },
}).then((result) => {
if (result.isConfirmed) {
renderToCanvas(result.value);
}
});

function handleDragEnter(e) {
e.preventDefault();
e.stopPropagation();
e.target.style.background = 'var(--body-bg)';
}

function handleDragOver(e) {
e.preventDefault();
e.stopPropagation();
e.dataTransfer.dropEffect = 'copy';
}

function handleDragLeave(e) {
e.preventDefault();
e.stopPropagation();
e.target.style.background = '';
}

function handleDrop(e) {
e.preventDefault();
e.stopPropagation();
const dt = e.dataTransfer;
const files = dt.files;
handleFiles(files);
e.target.style.background = '';
}

function handleFiles(files) {
if (files.length > 0) {
const file = files[0];
console.log('Selected file:', file);
Swal.close();
renderToCanvas(file);
}
}
}

function renderImageToCanvas(wbCanvasImg) {
if (wbCanvasImg && wbCanvasImg.size > 0) {
let reader = new FileReader();
reader.onload = function (event) {
let imgObj = new Image();
imgObj.src = event.target.result;
imgObj.onload = function () {
let image = new fabric.Image(imgObj);
image.set({ top: 0, left: 0 }).scale(0.3);
addWbCanvasObj(image);
};
};
reader.readAsDataURL(wbCanvasImg);
}
}

async function renderPdfToCanvas(wbCanvasPdf) {
if (wbCanvasPdf && wbCanvasPdf.size > 0) {
let reader = new FileReader();
reader.onload = async function (event) {
wbCanvas.requestRenderAll();
await pdfToImage(event.target.result, wbCanvas);
whiteboardIsDrawingMode(false);
wbCanvasToJson();
};
reader.readAsDataURL(wbCanvasPdf);
}
}

function readBlob(blob) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
Expand Down Expand Up @@ -4065,7 +4100,7 @@ function showAbout() {
imageUrl: image.about,
customClass: { image: 'img-about' },
position: 'center',
title: 'WebRTC SFU v1.4.81',
title: 'WebRTC SFU v1.4.82',
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 [email protected] or purchase directly via CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-sfu-webrtc-realtime-video-conferences/40769970
* @author Miroslav Pejic - [email protected]
* @version 1.4.81
* @version 1.4.82
*
*/

Expand Down
2 changes: 1 addition & 1 deletion public/views/Room.html
Original file line number Diff line number Diff line change
Expand Up @@ -1211,8 +1211,8 @@ <h1>Loading</h1>
</button>
<div class="dropdown-menu text-start" aria-labelledby="whiteboardDropDownMenu">
<button id="whiteboardImgFileBtn"><i class="far fa-image"></i> Add image file</button>
<button id="whiteboardPdfFileBtn"><i class="far fa-file-pdf"></i> Add pdf file</button>
<button id="whiteboardImgUrlBtn"><i class="fas fa-link"></i> Add image URL</button>
<button id="whiteboardPdfFileBtn"><i class="far fa-file-pdf"></i> Add pdf file</button>
<button id="whiteboardTextBtn"><i class="fas fa-spell-check"></i> Add text</button>
<button id="whiteboardLineBtn"><i class="fas fa-slash"></i> Add line</button>
<button id="whiteboardRectBtn"><i class="far fa-square"></i> Add rectangle</button>
Expand Down

0 comments on commit d876180

Please sign in to comment.