Commit e4f159e3 by ramdayalmunda

removing events for getting generated video response

parent fcff1848
...@@ -7,7 +7,6 @@ var getUserDetails = null ...@@ -7,7 +7,6 @@ var getUserDetails = null
var recording = false; var recording = false;
var loggedIn = false; var loggedIn = false;
var userDetails = {} var userDetails = {}
var generatingVideo = false;
function setData(key, value, callback) { function setData(key, value, callback) {
...@@ -53,7 +52,7 @@ var getUserDetails = null ...@@ -53,7 +52,7 @@ var getUserDetails = null
}) })
function getStatus(){ function getStatus(){
return tutorShotId ? (generatingVideo?'generatingVideo':recording ? "recording" : "paused"):"stopped" return tutorShotId ? (recording ? "recording" : "paused"):"stopped"
} }
...@@ -260,7 +259,7 @@ var getUserDetails = null ...@@ -260,7 +259,7 @@ var getUserDetails = null
return return
} }
if (loggedIn && request.action === 'stopRecording') { if (loggedIn && request.action === 'stopRecording') {
generatingVideo = true console.log('to stop recording')
recording = false; recording = false;
sendResponse({ sendResponse({
userDetails, userDetails,
...@@ -268,21 +267,20 @@ var getUserDetails = null ...@@ -268,21 +267,20 @@ var getUserDetails = null
recording, recording,
status: getStatus() status: getStatus()
}); });
console.log('sending generatingVideo message, ')
sendMessageToActiveTab("generatingVideo") sendMessageToActiveTab("generatingVideo")
console.log('sent generatingVideo message, ')
await api.post('/tutor-shot/finalize', { _id: tutorShotId }, { headers: { userid: userDetails.uid } }) await api.post('/tutor-shot/finalize', { _id: tutorShotId }, { headers: { userid: userDetails.uid } })
generatingVideo = false
tutorShotId = null tutorShotId = null
sendMessageToActiveTab("recordingStopped")
setData("recording", false) setData("recording", false)
setData("imageNumber", 0) setData("imageNumber", 0)
setData("tutorShotId", tutorShotId) setData("tutorShotId", null)
imageNumber = 0; imageNumber = 0;
return return
} }
if (request.action === 'logout') { if (request.action === 'logout') {
loggedIn = false; loggedIn = false;
recording = false; recording = false;
generatingVideo = false;
userDetails = {}; userDetails = {};
tutorShotId = null; tutorShotId = null;
imageNumber = 0; imageNumber = 0;
...@@ -373,7 +371,12 @@ var getUserDetails = null ...@@ -373,7 +371,12 @@ var getUserDetails = null
status: getStatus(), status: getStatus(),
message: messageObj message: messageObj
} }
chrome.tabs.sendMessage(activeTab?.id, message); try{
chrome.tabs.sendMessage(activeTab?.id, message);
}catch(err){
console.log('error while sending data', activeTab, message)
console.log(err)
}
} }
}) })
} catch (err) { } catch (err) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
var loggedIn = false; var loggedIn = false;
var floatingBar = null; var floatingBar = null;
var startingOverlay = null; var startingOverlay = null;
var finalizingOverlay = null;
var overlayInterval = null; var overlayInterval = null;
const origin = "http://localhost:3039" const origin = "http://localhost:3039"
var userDetails = {}; var userDetails = {};
...@@ -11,21 +12,21 @@ var btn = {}; ...@@ -11,21 +12,21 @@ var btn = {};
var tutorShotOid = null; var tutorShotOid = null;
var containerDiv; var containerDiv;
var sr; var sr;
var webpageObserver = { disconnect(){} } var webpageObserver = { disconnect() { } }
!(async function () { !(async function () {
if (window.origin == origin){ login() } if (window.origin == origin) { login() }
else{ else {
window.clearInterval( window.tutorShotInterval ) window.clearInterval(window.tutorShotInterval)
window.tutorShotInterval = setInterval( async ()=>{ window.tutorShotInterval = setInterval(async () => {
try{ try {
let data = await getCaptureData() let data = await getCaptureData()
reRenderFloatingBar(data) reRenderFloatingBar(data)
}catch(err){ } catch (err) {
console.log(err) console.log(err)
} }
}, 1000 ) }, 1000)
} }
containerDiv = document.createElement('div') containerDiv = document.createElement('div')
...@@ -165,7 +166,6 @@ var webpageObserver = { disconnect(){} } ...@@ -165,7 +166,6 @@ var webpageObserver = { disconnect(){} }
<div class="counter-count" tutor-shot="counter" style="display:none;"></div> <div class="counter-count" tutor-shot="counter" style="display:none;"></div>
<div class="logo"> <div class="logo">
<img tutor-shot="main-logo" class="logo-img" src="${origin}/assets/images/tutor-shot-48.png" width="40"> <img tutor-shot="main-logo" class="logo-img" src="${origin}/assets/images/tutor-shot-48.png" width="40">
<img tutor-shot="generating-video" class="logo-img" src="${origin}/assets/images/logo-loader.gif" width="40">
</div> </div>
<div class="content"> <div class="content">
<div class="item" tutor-shot="play-btn"> <div class="item" tutor-shot="play-btn">
...@@ -237,6 +237,7 @@ async function getCaptureData() { ...@@ -237,6 +237,7 @@ async function getCaptureData() {
} }
function reRenderFloatingBar(data) { function reRenderFloatingBar(data) {
console.log('reRenderFloatingBar', data)
if (data) { if (data) {
if (data.status == 'stopped') { if (data.status == 'stopped') {
containerDiv.remove() containerDiv.remove()
...@@ -253,9 +254,6 @@ function reRenderFloatingBar(data) { ...@@ -253,9 +254,6 @@ function reRenderFloatingBar(data) {
if (!btn.mainLogo) { if (!btn.mainLogo) {
btn.mainLogo = sr.querySelector('[tutor-shot="main-logo"]') btn.mainLogo = sr.querySelector('[tutor-shot="main-logo"]')
} }
if (!btn.generatingVideo) {
btn.generatingVideo = sr.querySelector('[tutor-shot="generating-video"]')
}
if (!btn.capture) { if (!btn.capture) {
btn.capture = sr.querySelector('[tutor-shot="capture-btn"]') btn.capture = sr.querySelector('[tutor-shot="capture-btn"]')
} }
...@@ -288,7 +286,6 @@ function reRenderFloatingBar(data) { ...@@ -288,7 +286,6 @@ function reRenderFloatingBar(data) {
btn.pause.style.display = 'none' btn.pause.style.display = 'none'
btn.stop.style.display = 'flex' btn.stop.style.display = 'flex'
btn.restart.style.display = 'flex' btn.restart.style.display = 'flex'
btn.generatingVideo.style.display = 'none'
btn.mainLogo.style.display = 'block' btn.mainLogo.style.display = 'block'
} }
else if (data?.status == 'recording') { else if (data?.status == 'recording') {
...@@ -296,24 +293,14 @@ function reRenderFloatingBar(data) { ...@@ -296,24 +293,14 @@ function reRenderFloatingBar(data) {
btn.pause.style.display = 'flex' btn.pause.style.display = 'flex'
btn.restart.style.display = 'flex' btn.restart.style.display = 'flex'
btn.stop.style.display = 'flex' btn.stop.style.display = 'flex'
btn.generatingVideo.style.display = 'none'
btn.mainLogo.style.display = 'block' btn.mainLogo.style.display = 'block'
// btn.capture.style.display = 'flex' // btn.capture.style.display = 'flex'
} }
else if (data?.status == 'generatingVideo') {
btn.play.style.display = 'none'
btn.pause.style.display = 'none'
btn.stop.style.display = 'none'
btn.restart.style.display = 'none'
btn.generatingVideo.style.display = 'block'
btn.mainLogo.style.display = 'none'
}
else { // stopped else { // stopped
btn.play.style.display = 'flex' btn.play.style.display = 'flex'
btn.pause.style.display = 'none' btn.pause.style.display = 'none'
btn.stop.style.display = 'none' btn.stop.style.display = 'none'
btn.restart.style.display = 'none' btn.restart.style.display = 'none'
btn.generatingVideo.style.display = 'none'
btn.mainLogo.style.display = 'block' btn.mainLogo.style.display = 'block'
} }
} }
...@@ -346,8 +333,8 @@ window.addEventListener('mousedown', async function (e) { ...@@ -346,8 +333,8 @@ window.addEventListener('mousedown', async function (e) {
url: location.href, url: location.href,
origin: location.origin, origin: location.origin,
} }
let newLineBreakIndex = captureInfo.text.search( '\n' ) let newLineBreakIndex = captureInfo.text.search('\n')
if (newLineBreakIndex!=-1) captureInfo.text = captureInfo.text.slice(0, newLineBreakIndex) if (newLineBreakIndex != -1) captureInfo.text = captureInfo.text.slice(0, newLineBreakIndex)
// console.log('sending capture info', captureInfo) // console.log('sending capture info', captureInfo)
chrome.runtime.sendMessage({ action: "captureSS", captureInfo }) chrome.runtime.sendMessage({ action: "captureSS", captureInfo })
let data = await getCaptureData() let data = await getCaptureData()
...@@ -357,6 +344,7 @@ window.addEventListener('mousedown', async function (e) { ...@@ -357,6 +344,7 @@ window.addEventListener('mousedown', async function (e) {
}) })
// content.js // content.js
chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) { chrome.runtime.onMessage.addListener(async function (message, sender, sendResponse) {
console.log('getting message')
if (message.action == 'tabChanged') { if (message.action == 'tabChanged') {
// console.log('tabChanged', message) // console.log('tabChanged', message)
} }
...@@ -396,14 +384,26 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -396,14 +384,26 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
} }
else if (message.message == 'generatingVideo') { else if (message.message == 'generatingVideo') {
console.log('generating Video')
finalizingOverlay = document.createElement('div')
finalizingOverlay.setAttribute('class', 'tutor-shot-overlay')
sr.append(finalizingOverlay)
finalizingOverlay.innerHTML = `
<div>
Your video is being saved.
</div>
`
setTimeout(() => {
finalizingOverlay.remove()
if (window.location.href == `${origin}/tutor-shot-list`) {
window.location.reload()
} else {
window.open(`${origin}/tutor-shot-list`)
}
reRenderFloatingBar(data)
}, 2000)
reRenderFloatingBar(data) reRenderFloatingBar(data)
}
else if (message.message == 'recordingStopped') {
if (window.location.href == `${origin}/tutor-shot-list`){
window.location.reload()
}else {
window.open(`${origin}/tutor-shot-list`)
}
} }
}); });
...@@ -412,7 +412,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon ...@@ -412,7 +412,7 @@ chrome.runtime.onMessage.addListener(async function (message, sender, sendRespon
async function startRecording() { async function startRecording() {
try { try {
await getCaptureData(); await getCaptureData();
let { data } = await api.post('/tutor-shot', { title: "Some random title" }, { headers: { userId: userDetails.uid } }) let { data } = await api.post('/tutor-shot', { title: "No Title" }, { headers: { userId: userDetails.uid } })
if (data.success) { if (data.success) {
await chrome.runtime.sendMessage({ action: "startRecording", tutorShotId: data.tutorShot._id }) await chrome.runtime.sendMessage({ action: "startRecording", tutorShotId: data.tutorShot._id })
} }
......
{ {
"manifest_version": 3, "manifest_version": 3,
"name": "Tutor Shot Local", "name": "Tutor Shot Local",
"version": "1.8", "version": "1.10",
"description": "Capture web-page screenshots instantly with a single click. They're saved to your account at http://localhost:3039.", "description": "Capture web-page screenshots instantly with a single click. They're saved to your account at http://localhost:3039.",
"permissions": [ "permissions": [
"activeTab", "activeTab",
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
} }
inProgress = true inProgress = true
try{ try{
let { data } = await api.post('/tutor-shot', { title: "Some random title" }, { headers: { userId: userDetails.uid } } ) let { data } = await api.post('/tutor-shot', { title: "No Title" }, { headers: { userId: userDetails.uid } } )
if (data.success){ if (data.success){
chrome.runtime.sendMessage({ action: "startRecording", tutorShotId:data.tutorShot._id }, async function (response) { chrome.runtime.sendMessage({ action: "startRecording", tutorShotId:data.tutorShot._id }, async function (response) {
recording = response.recording recording = response.recording
......
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