@@ -1671,6 +1671,7 @@ class Activity {
16711671 let mediaRecorder ;
16721672 var clickEvent = new Event ( "click" ) ;
16731673 let flag = 0 ;
1674+ let stream = null ;
16741675
16751676 /**
16761677 * Records the screen using the browser's media devices API.
@@ -1693,8 +1694,6 @@ class Activity {
16931694 } ) ;
16941695 }
16951696
1696- const that = this ;
1697-
16981697 /**
16991698 * Saves the recorded chunks as a video file.
17001699 * @param {Blob[] } recordedChunks - The recorded video chunks.
@@ -1711,7 +1710,6 @@ class Activity {
17111710 alert ( _ ( "File save canceled" ) ) ;
17121711 flag = 0 ;
17131712 recording ( ) ;
1714- doRecordButton ( ) ;
17151713 return ; // Exit without saving the file
17161714 }
17171715
@@ -1726,18 +1724,13 @@ class Activity {
17261724 flag = 0 ;
17271725 // eslint-disable-next-line no-use-before-define
17281726 recording ( ) ;
1729- doRecordButton ( ) ;
1730- that . textMsg ( _ ( "Click on stop saving" ) ) ;
17311727 }
17321728 /**
17331729 * Stops the recording process.
17341730 */
17351731 function stopRec ( ) {
17361732 flag = 0 ;
17371733 mediaRecorder . stop ( ) ;
1738- const node = document . createElement ( "p" ) ;
1739- node . textContent = "Stopped recording" ;
1740- document . body . appendChild ( node ) ;
17411734 }
17421735
17431736 /**
@@ -1748,13 +1741,11 @@ class Activity {
17481741 */
17491742 function createRecorder ( stream , mimeType ) {
17501743 flag = 1 ;
1751- recInside . classList . add ( "blink" ) ;
1752- start . removeEventListener ( "click" , createRecorder , true ) ;
17531744 let recordedChunks = [ ] ;
17541745 const mediaRecorder = new MediaRecorder ( stream ) ;
1746+
17551747 stream . oninactive = function ( ) {
17561748 // eslint-disable-next-line no-console
1757- console . log ( "Recording is ready to save" ) ;
17581749 stopRec ( ) ;
17591750 flag = 0 ;
17601751 } ;
@@ -1773,11 +1764,9 @@ class Activity {
17731764 } ;
17741765
17751766 mediaRecorder . start ( 200 ) ;
1776- setTimeout ( ( ) => {
1777- // eslint-disable-next-line no-console
1778- console . log ( "Resizing for Record" , that . canvas . height ) ;
1779- that . _onResize ( ) ;
1780- } , 500 ) ;
1767+ recInside . classList . add ( "blink" ) ;
1768+ recInside . setAttribute ( "fill" , "red" ) ;
1769+ start . addEventListener ( "click" , stopRec ) ;
17811770 return mediaRecorder ;
17821771 }
17831772
@@ -1786,31 +1775,23 @@ class Activity {
17861775 */
17871776 function recording ( ) {
17881777 start . addEventListener ( "click" , async function handler ( ) {
1789- const stream = await recordScreen ( ) ;
1778+ if ( ! stream || stream . active == false ) {
1779+ stream = await recordScreen ( ) ;
1780+ }
17901781 const mimeType = "video/webm" ;
17911782 mediaRecorder = createRecorder ( stream , mimeType ) ;
17921783 if ( flag == 1 ) {
17931784 this . removeEventListener ( "click" , handler ) ;
17941785 }
1795- const node = document . createElement ( "p" ) ;
1796- node . textContent = "Started recording" ;
1797- document . body . appendChild ( node ) ;
1798- recInside . setAttribute ( "fill" , "red" ) ;
17991786 } ) ;
18001787 }
18011788
18021789 // Start recording process if not already executing
1803- if ( flag == 0 && isExecuting ) {
1790+ if ( flag == 0 ) {
18041791 recording ( ) ;
18051792 start . dispatchEvent ( clickEvent ) ;
18061793 flag = 1 ;
18071794 }
1808-
1809- // Stop recording if already executing
1810- if ( flag == 1 && isExecuting ) {
1811- start . addEventListener ( "click" , stopRec ) ;
1812- flag = 0 ;
1813- }
18141795 } ;
18151796
18161797 /*
0 commit comments