spot: rotate mime types
This commit is contained in:
parent
07391a1577
commit
1e17e349fa
2 changed files with 33 additions and 34 deletions
|
|
@ -959,7 +959,6 @@ export default defineBackground(() => {
|
||||||
target: { tabId: tab.id },
|
target: { tabId: tab.id },
|
||||||
files: ["/content-scripts/content.js"],
|
files: ["/content-scripts/content.js"],
|
||||||
});
|
});
|
||||||
console.log("restoring content at", tab);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Error restoring content script", e);
|
console.error("Error restoring content script", e);
|
||||||
}
|
}
|
||||||
|
|
@ -1147,7 +1146,6 @@ export default defineBackground(() => {
|
||||||
state: getRecState(),
|
state: getRecState(),
|
||||||
activeTabId: null,
|
activeTabId: null,
|
||||||
};
|
};
|
||||||
console.log(tabId, "activation for new");
|
|
||||||
attachDebuggerToTab(tabId);
|
attachDebuggerToTab(tabId);
|
||||||
void sendToActiveTab(msg);
|
void sendToActiveTab(msg);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ class ScreenRecorder {
|
||||||
this.chunks = [];
|
this.chunks = [];
|
||||||
this.stream = null;
|
this.stream = null;
|
||||||
this.audioTrack = null;
|
this.audioTrack = null;
|
||||||
|
this.ignoreHandleStop = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(settings) {
|
init(settings) {
|
||||||
|
|
@ -161,45 +162,42 @@ class ScreenRecorder {
|
||||||
mimeType: this.settings.mimeType,
|
mimeType: this.settings.mimeType,
|
||||||
videoKeyFrameIntervalDuration: 1000,
|
videoKeyFrameIntervalDuration: 1000,
|
||||||
};
|
};
|
||||||
|
const retryRecorder = (e) => {
|
||||||
|
if (!this.stream) {
|
||||||
|
console.error("MediaRecorder error + stream is not available.", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.ignoreHandleStop = true;
|
||||||
|
this.mRecorder.stop();
|
||||||
|
|
||||||
|
mimeTypeNum = (mimeTypeNum + 1) % mimeTypes.length;
|
||||||
|
const nextType = mimeTypes[mimeTypeNum];
|
||||||
|
if (!nextType) {
|
||||||
|
console.error("No more mime types to try, stopping recording.");
|
||||||
|
this.isRecording = false;
|
||||||
|
this.clearDurationInterval();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
console.error(`MediaRecorder error; retrying with ${nextType}`, e);
|
||||||
|
this.settings.mimeType = nextType;
|
||||||
|
mRecorderSettings.mimeType = nextType;
|
||||||
|
|
||||||
|
this.mRecorder = new MediaRecorder(this.stream, mRecorderSettings);
|
||||||
|
this.mRecorder.ondataavailable = this._handleDataAvailable;
|
||||||
|
this.mRecorder.onstop = this._handleStop;
|
||||||
|
this.mRecorder.onerror = retryRecorder;
|
||||||
|
this.mRecorder.start(1000);
|
||||||
|
};
|
||||||
|
|
||||||
this.stream = combinedStream;
|
this.stream = combinedStream;
|
||||||
this.mRecorder = new MediaRecorder(combinedStream, mRecorderSettings);
|
this.mRecorder = new MediaRecorder(combinedStream, mRecorderSettings);
|
||||||
|
|
||||||
this.mRecorder.ondataavailable = this._handleDataAvailable;
|
this.mRecorder.ondataavailable = this._handleDataAvailable;
|
||||||
this.mRecorder.onstop = this._handleStop;
|
this.mRecorder.onstop = this._handleStop;
|
||||||
this.mRecorder.onerror = (ev) => {
|
this.mRecorder.onerror = retryRecorder;
|
||||||
const nextType = mimeTypes[mimeTypeNum + 1];
|
|
||||||
console.error(
|
|
||||||
`MediaRecorder error (depth = ${mimeTypeNum}; restarting with ${nextType}):`,
|
|
||||||
ev.error,
|
|
||||||
);
|
|
||||||
this.settings.mimeType = nextType;
|
|
||||||
mRecorderSettings.mimeType = this.settings.mimeType;
|
|
||||||
mimeTypeNum++;
|
|
||||||
setTimeout(() => {
|
|
||||||
this.mRecorder = new MediaRecorder(combinedStream, mRecorderSettings);
|
|
||||||
this.mRecorder.ondataavailable = this._handleDataAvailable;
|
|
||||||
this.mRecorder.onstop = this._handleStop;
|
|
||||||
this.mRecorder.start(1000);
|
|
||||||
}, 1);
|
|
||||||
};
|
|
||||||
this.isRecording = true;
|
this.isRecording = true;
|
||||||
this.mRecorder.start(1000);
|
this.mRecorder.start(1000);
|
||||||
this.trackDuration();
|
this.trackDuration();
|
||||||
|
|
||||||
let checks = 0;
|
|
||||||
const int = setInterval(() => {
|
|
||||||
if (checks < 50) {
|
|
||||||
checks++;
|
|
||||||
console.log(
|
|
||||||
this.settings.mimeType,
|
|
||||||
this.mRecorder.state,
|
|
||||||
this.mRecorder.stream.active,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
clearInterval(int);
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
|
|
@ -349,10 +347,14 @@ class ScreenRecorder {
|
||||||
};
|
};
|
||||||
|
|
||||||
recorded = false;
|
recorded = false;
|
||||||
|
ignoreHandleStop = false;
|
||||||
_handleStop = () => {
|
_handleStop = () => {
|
||||||
|
if (this.ignoreHandleStop) {
|
||||||
|
this.ignoreHandleStop = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const blob = new Blob(this.chunks, { type: this.settings.mimeType });
|
const blob = new Blob(this.chunks, { type: this.settings.mimeType });
|
||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
console.log("offscreen: raw blob byteLength =", blob.size);
|
|
||||||
this.videoBlob = blob;
|
this.videoBlob = blob;
|
||||||
this.videoUrl = url;
|
this.videoUrl = url;
|
||||||
this.videoStream.getTracks().forEach((track) => track.stop());
|
this.videoStream.getTracks().forEach((track) => track.stop());
|
||||||
|
|
@ -426,7 +428,6 @@ browser.runtime.onMessage.addListener((message, _, respond) => {
|
||||||
respond({ status: "empty" });
|
respond({ status: "empty" });
|
||||||
}
|
}
|
||||||
convertBlobToBase64(data.blob).then(({ result, size }) => {
|
convertBlobToBase64(data.blob).then(({ result, size }) => {
|
||||||
console.log("offscreen: base64 payload length:", size);
|
|
||||||
if (size > hardLimit) {
|
if (size > hardLimit) {
|
||||||
respond({ status: "parts" });
|
respond({ status: "parts" });
|
||||||
result.forEach((chunk, i) => {
|
result.forEach((chunk, i) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue