-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mirotalk] - improve whiteboard, update dep
- Loading branch information
1 parent
f586db3
commit d558ee0
Showing
4 changed files
with
126 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* | ||
*/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* | ||
*/ | ||
|
||
|
@@ -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'); | ||
|
@@ -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', { | ||
|
@@ -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 | ||
|
@@ -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' }, | ||
|