Skip to content

Commit

Permalink
[mirotalk] - improve whiteboard, update dep
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Jul 4, 2024
1 parent f586db3 commit d558ee0
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 77 deletions.
2 changes: 1 addition & 1 deletion app/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies: {
* @license For commercial use or closed source, contact us at [email protected] or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - [email protected]
* @version 1.3.39
* @version 1.3.40
*
*/

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.3.39",
"version": "1.3.40",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
Expand Down Expand Up @@ -41,7 +41,7 @@
"homepage": "https://github.com/miroslavpejic85/mirotalk",
"dependencies": {
"@sentry/integrations": "^7.114.0",
"@sentry/node": "^7.114.0",
"@sentry/node": "^8.13.0",
"axios": "^1.7.2",
"body-parser": "^1.20.2",
"colors": "^1.4.0",
Expand All @@ -55,7 +55,7 @@
"js-yaml": "^4.1.0",
"ngrok": "^5.0.0-beta.2",
"nodemailer": "^6.9.14",
"openai": "^4.52.2",
"openai": "^4.52.3",
"qs": "^6.12.2",
"socket.io": "^4.7.5",
"swagger-ui-express": "^5.0.1",
Expand Down
4 changes: 2 additions & 2 deletions public/css/whiteboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
position: fixed;
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 Down
191 changes: 120 additions & 71 deletions public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @license For commercial use or closed source, contact us at [email protected] or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - [email protected]
* @version 1.3.39
* @version 1.3.40
*
*/

Expand Down Expand Up @@ -106,8 +106,8 @@ const fileSharingInput = '*'; // allow all file extensions
const Base64Prefix = 'data:application/pdf;base64,';
const wbPdfInput = 'application/pdf';
const wbImageInput = 'image/*';
const wbWidth = 1200;
const wbHeight = 600;
const wbWidth = 1280;
const wbHeight = 768;

// Peer infos
const extraInfo = getId('extraInfo');
Expand Down Expand Up @@ -8735,75 +8735,10 @@ function whiteboardAddObj(type) {
});
break;
case 'imgFile':
Swal.fire({
allowOutsideClick: false,
background: swBg,
position: 'center',
title: 'Select image',
input: 'file',
inputAttributes: {
accept: wbImageInput,
'aria-label': 'Select 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');
}
}
});
setupFileSelection('Select the image', wbImageInput, renderImageToCanvas);
break;
case 'pdfFile':
Swal.fire({
allowOutsideClick: false,
background: swBg,
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 @@ -8864,6 +8799,120 @@ function whiteboardAddObj(type) {
}
}

/**
* Setup Canvas file selections
* @param {string} title
* @param {string} accept
* @param {object} renderToCanvas
*/
function setupFileSelection(title, accept, renderToCanvas) {
Swal.fire({
allowOutsideClick: false,
background: swBg,
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);
}
}
}

/**
* Render Image file to Canvas
* @param {object} wbCanvasImg
*/
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);
}
}

/**
* Render PDF file to Canvas
* @param {object} wbCanvasPdf
*/
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);
}
}

/**
* Promisify the FileReader
* @param {object} blob
Expand Down Expand Up @@ -9956,7 +10005,7 @@ function showAbout() {
Swal.fire({
background: swBg,
position: 'center',
title: '<strong>WebRTC P2P v1.3.39</strong>',
title: '<strong>WebRTC P2P v1.3.40</strong>',
imageAlt: 'mirotalk-about',
imageUrl: images.about,
customClass: { image: 'img-about' },
Expand Down

0 comments on commit d558ee0

Please sign in to comment.