Stop Webcam recording by file size

CodeSandBox (Live Code):

How can I make the Webcam stop recording (stopRecording() function) when, while recording, it detects that it has reached a limit of 1 MegaByte or 1 minute?’

I been trying with:

    // converts bytes to megabytes
    const maxFileSize = ((streamRef.current.size/1024)/1024).toFixed(4)
    if(maxFileSize >= 1) {
      streamRecorderRef.current.stop();
      // OR
      stopRecording()
    }

but it wasn’t sucessful