Commit f86b8529 by ramdayalmunda

restart recording feature added

parent 6a3f96aa
...@@ -92,6 +92,17 @@ var getUserDetails = null ...@@ -92,6 +92,17 @@ var getUserDetails = null
sendMessageToActiveTab("recordingStopped") sendMessageToActiveTab("recordingStopped")
return return
} }
if (loggedIn && request.action === 'restartRecording') {
imageNumber = 0;
sendResponse({
userDetails,
loggedIn,
recording,
status: tutorShotId?(recording?"recording":"paused"):"stopped"
});
sendMessageToActiveTab("recordingRestarted")
return
}
if (request.action === 'captureSS') { if (request.action === 'captureSS') {
if (!loggedIn) { if (!loggedIn) {
......
...@@ -10,11 +10,7 @@ var userDetails = {}; ...@@ -10,11 +10,7 @@ var userDetails = {};
var btn = {} var btn = {}
!(async function () { !(async function () {
// this is load custom font loadFont('tutor-shot-calibri', `${origin}/assets/fonts/calibri-regular.ttf`, 'truetype')
let customFont = new FontFace('tutor-shot-calibri', `url(${origin}/assets/fonts/calibri-regular.ttf) format("truetype")`)
customFont.load().then(function (font) {
document.fonts.add(font);
})
if (window.origin == origin) login() if (window.origin == origin) login()
...@@ -50,7 +46,8 @@ var btn = {} ...@@ -50,7 +46,8 @@ var btn = {}
box-shadow: 0px 0px 20px #cccccc; box-shadow: 0px 0px 20px #cccccc;
display: flex; display: flex;
align-items: center; align-items: center;
font-family: 'tutor-shot-calibri'; /* font-family: 'tutor-shot-calibri'; */
font-family: 'sans serif';
transition: 0.3s; transition: 0.3s;
} }
...@@ -200,42 +197,42 @@ async function getCaptureData() { ...@@ -200,42 +197,42 @@ async function getCaptureData() {
function reRenderFloatingBar(data) { function reRenderFloatingBar(data) {
console.log('reRenderFloatingBar', data) console.log('reRenderFloatingBar', data)
if (data){ if (data) {
if (data.status=='stopped'){ if (data.status == 'stopped') {
floatingBar.remove() floatingBar.remove()
return return
}else if (!document.body.contains(floatingBar)){ } else if (!document.body.contains(floatingBar)) {
document.body.append(floatingBar) document.body.append(floatingBar)
} }
} }
if (!btn.play){ if (!btn.play) {
btn.play = document.querySelector('[tutor-shot="play-btn"]') btn.play = document.querySelector('[tutor-shot="play-btn"]')
btn.play.addEventListener('click', resumeRecording) btn.play.addEventListener('click', resumeRecording)
} }
if (!btn.capture){ if (!btn.capture) {
btn.capture = document.querySelector('[tutor-shot="capture-btn"]') btn.capture = document.querySelector('[tutor-shot="capture-btn"]')
console.log('take screen shot') console.log('take screen shot')
} }
if (!btn.playText) btn.playText = document.querySelector('[tutor-shot="play-text"]') if (!btn.playText) btn.playText = document.querySelector('[tutor-shot="play-text"]')
if (!btn.pause){ if (!btn.pause) {
btn.pause = document.querySelector('[tutor-shot="pause-btn"]') btn.pause = document.querySelector('[tutor-shot="pause-btn"]')
btn.pause.addEventListener('click', pauseRecording) btn.pause.addEventListener('click', pauseRecording)
} }
if (!btn.stop){ if (!btn.stop) {
btn.stop = document.querySelector('[tutor-shot="stop-btn"]') btn.stop = document.querySelector('[tutor-shot="stop-btn"]')
btn.stop.addEventListener('click', stopRecording) btn.stop.addEventListener('click', stopRecording)
} }
if (!btn.restart){ if (!btn.restart) {
btn.restart = document.querySelector('[tutor-shot="restart-btn"]') btn.restart = document.querySelector('[tutor-shot="restart-btn"]')
btn.restart.addEventListener('click', restartRecording) btn.restart.addEventListener('click', restartRecording)
} }
if (!btn.counter) btn.counter = document.querySelector('[tutor-shot="counter"]') if (!btn.counter) btn.counter = document.querySelector('[tutor-shot="counter"]')
if (data?.hasOwnProperty('imageNumber')){ if (data?.hasOwnProperty('imageNumber')) {
console.log('set', data.imageNumber, btn.counter.innerHTML) console.log('set', data.imageNumber, btn.counter.innerHTML)
btn.counter.innerHTML = `${data.imageNumber}` btn.counter.innerHTML = `${data.imageNumber}`
if (data.imageNumber<=0) btn.counter.style.display='none' if (data.imageNumber <= 0) btn.counter.style.display = 'none'
else btn.counter.style.display='flex' else btn.counter.style.display = 'flex'
} }
if (data?.state == 'paused') { if (data?.state == 'paused') {
btn.play.style.display = 'flex' btn.play.style.display = 'flex'
...@@ -273,7 +270,7 @@ const api = axios.create({ ...@@ -273,7 +270,7 @@ const api = axios.create({
window.addEventListener('mousedown', async function (e) { window.addEventListener('mousedown', async function (e) {
// to prevent the event when clicking inside the floating bar // to prevent the event when clicking inside the floating bar
if (floatingBar?.contains(e.target) || startingOverlay?.contains(e.target)){ if (floatingBar?.contains(e.target) || startingOverlay?.contains(e.target)) {
return return
} }
if (e.button === 0) { // only left click allowed if (e.button === 0) { // only left click allowed
...@@ -303,21 +300,21 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -303,21 +300,21 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
if (message.action == 'tabChanged') { if (message.action == 'tabChanged') {
// console.log('tabChanged', message) // console.log('tabChanged', message)
} }
if (message.status){ if (message.status) {
console.log('got message status', message) console.log('got message status', message)
} }
let data = await getCaptureData() let data = await getCaptureData()
reRenderFloatingBar(data) reRenderFloatingBar(data)
if (message.message == 'recordingStarted'){ if (message.message == 'recordingStarted') {
if (floatingBar){ if (floatingBar) {
if(!startingOverlay){ if (!startingOverlay) {
clearInterval(overlayInterval) clearInterval(overlayInterval)
let counter = 5 let counter = 5
startingOverlay = document.createElement('div') startingOverlay = document.createElement('div')
startingOverlay.setAttribute('class', 'tutor-shot-overlay') startingOverlay.setAttribute('class', 'tutor-shot-overlay')
document.body.append(startingOverlay) document.body.append(startingOverlay)
function changeText(){ function changeText() {
if (counter<=0){ if (counter <= 0) {
clearInterval(overlayInterval) clearInterval(overlayInterval)
startingOverlay.remove() startingOverlay.remove()
return return
...@@ -332,12 +329,15 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -332,12 +329,15 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
` `
} }
changeText() changeText()
overlayInterval = setInterval(changeText, 1000 ) overlayInterval = setInterval(changeText, 1000)
} }
} }
} }
if (message.message == 'recordingStopped') {
window.open(`${origin}/tutor-shot-list`)
}
}); });
...@@ -356,19 +356,44 @@ async function startRecording() { ...@@ -356,19 +356,44 @@ async function startRecording() {
} }
} }
async function pauseRecording(){ async function pauseRecording() {
console.log('to pause recording') await chrome.runtime.sendMessage({ action: "pauseRecording" })
await chrome.runtime.sendMessage({action: "pauseRecording"})
} }
async function resumeRecording(){ async function resumeRecording() {
await chrome.runtime.sendMessage({action: "resumeRecording"}) await chrome.runtime.sendMessage({ action: "resumeRecording" })
} }
async function stopRecording(){ async function stopRecording() {
console.log('stop recording') await chrome.runtime.sendMessage({ action: "stopRecording" })
await chrome.runtime.sendMessage({action: "stopRecording"})
} }
async function restartRecording(){ async function restartRecording() {
console.log('remove all the screenshot in current recording') await chrome.runtime.sendMessage({ action: "restartRecording" })
try{
let captureData = await getCaptureData()
await api.delete('/tutor-shot/segments', { params: {tutorShotOid: captureData.tutorShotOid} })
}catch(err){
console.log(err)
}
}
async function checkFont(fontName) { // Use FontFace API to check if the font is available
try {
await document.fonts.load('1em ' + fontName); // Attempt to load the font
return true; // Font successfully loaded
} catch (error) {
return false; // Font couldn't be loaded
}
}
async function loadFont(name, url, type='true'){
return new Promise( (res, rej)=>{
// this is load custom font
let customFont = new FontFace(name, `url(${url}) format("${type}")`)
customFont.load().then(function (font) {
document.fonts.add(font);
res(true)
})
} )
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment