Here is a little bit of my preload.js code.
const webmFixDuration = require('webm-fix-duration').webmFixDuration;
let fixedBlob = "";
contextBridge.exposeInMainWorld("api", {
fixDuration: function (buggyBlob, duration) {
if(buggyBlob instanceof Blob) {
webmFixDuration(buggyBlob, duration, "video/mp4").then(function(value) {
fixedBlob = value;
});
}
},
getFixedBlob: function () {
return fixedBlob;
}
});
Then, here is a little bit of my renderer code.
//recorder is a mediaRecorder
recorder.onstop = function () {
let mostRecentChunk = [];
mostRecentChunk.push(...chunks);
blob = new Blob(mostRecentChunk, { 'type': 'video/mp4' });
let milliseconds = seconds * 1000;
window.api.fixDuration(blob, milliseconds);
let realBlob = window.api.getFixedBlob();
videoURL = window.URL.createObjectURL(realBlob); //This line causes an error
//Before you ask, yes videoURL is declared previously in the code
//Rest of my code goes here, but it's irrelevant
}
Now, the webmFixDuration function returns a Promise. As such, the getFixedBlob() function should return a blob. Therefore, the line in my renderer process videoURL = window.URL.createObjectURL(realBlob); should work since the createObjectURL function takes in a blob. However, the console in my application reveals that this line creates an error that says that the parameter realBlob is not a blob object. If I replaced the offending line in question with:
if(realBlob instanceof Blob) {
videoURL = window.URL.createObjectURL(realBlob);
} else {
console.log(realBlob);
}
The application goes to the else condition, and the console reveals realBlob to simply be an Object (not a blob), and the object doesn't even give any details in its properties.
In short, it seems that even though my preload.js function getFixedBlob() returns a blob, my renderer process is for some reason reading it as only being an object.
How can I get my preload.js to return a blob?