@@ -112,6 +112,17 @@ const createRecordingDownloadName = (
112112 return `cap-recording-${ timestamp } .${ extension } ` ;
113113} ;
114114
115+ const triggerBrowserDownload = ( url : string , fileName : string ) => {
116+ const anchor = document . createElement ( "a" ) ;
117+ anchor . href = url ;
118+ anchor . download = fileName ;
119+ document . body . appendChild ( anchor ) ;
120+ anchor . click ( ) ;
121+ document . body . removeChild ( anchor ) ;
122+ } ;
123+
124+ const recoveredToastId = ( id : string ) => `recovered-${ id } ` ;
125+
115126export const useWebRecorder = ( {
116127 organisationId,
117128 selectedMicId,
@@ -285,6 +296,7 @@ export const useWebRecorder = ({
285296 } , [ ] ) ;
286297
287298 const dismissRecoveredDownload = useCallback ( ( id : string ) => {
299+ toast . dismiss ( recoveredToastId ( id ) ) ;
288300 const url = recoveredDownloadUrlsRef . current . get ( id ) ;
289301 if ( url ) {
290302 URL . revokeObjectURL ( url ) ;
@@ -344,11 +356,26 @@ export const useWebRecorder = ({
344356 } ) ;
345357
346358 setRecoveredDownloads ( nextDownloads ) ;
347- toast . info (
348- nextDownloads . length === 1
349- ? "Recovered an unfinished local recording."
350- : `Recovered ${ nextDownloads . length } unfinished local recordings.` ,
351- ) ;
359+ for ( const download of nextDownloads ) {
360+ toast . info ( "Recovered an unfinished recording" , {
361+ id : recoveredToastId ( download . id ) ,
362+ duration : Infinity ,
363+ description : new Date ( download . createdAt ) . toLocaleString ( ) ,
364+ action : {
365+ label : "Download" ,
366+ onClick : ( ) => {
367+ triggerBrowserDownload ( download . url , download . fileName ) ;
368+ setTimeout ( ( ) => dismissRecoveredDownload ( download . id ) , 500 ) ;
369+ } ,
370+ } ,
371+ cancel : {
372+ label : "Dismiss" ,
373+ onClick : ( ) => {
374+ dismissRecoveredDownload ( download . id ) ;
375+ } ,
376+ } ,
377+ } ) ;
378+ }
352379 } )
353380 . catch ( ( error ) => {
354381 console . error ( "Failed to recover orphaned recording spools" , error ) ;
@@ -357,7 +384,7 @@ export const useWebRecorder = ({
357384 return ( ) => {
358385 cancelled = true ;
359386 } ;
360- } , [ ] ) ;
387+ } , [ dismissRecoveredDownload ] ) ;
361388
362389 const disposeRecordingSpool = useCallback ( async ( ) => {
363390 const spool = recordingSpoolRef . current ;
0 commit comments