feat: Save state debug function.

This commit is contained in:
damencho
2025-04-04 09:17:11 -05:00
committed by Дамян Минков
parent 471853ef15
commit 58b73d8dbd
2 changed files with 24 additions and 2 deletions

View File

@@ -1060,6 +1060,14 @@ export default {
downloadJSON(logs, filename);
},
/**
* Download app state, a function that can be called from console while debugging.
* @param filename (optional) specify target filename
*/
saveState(filename = 'meet-state.json') {
downloadJSON(APP.store.getState(), filename);
},
/**
* Exposes a Command(s) API on this instance. It is necessitated by (1) the
* desire to keep room private to this instance and (2) the need of other

View File

@@ -5,8 +5,22 @@
* @param {string} filename - The filename to give to the downloaded file.
* @returns {void}
*/
export function downloadJSON(json: Object, filename: string) {
const data = encodeURIComponent(JSON.stringify(json, null, ' '));
export function downloadJSON(json: Object, filename: string): void {
const replacer = () => {
const seen = new WeakSet();
return (_: any, value: any) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
return '[circular ref]';
}
seen.add(value);
}
return value;
};
};
const data = encodeURIComponent(JSON.stringify(json, replacer(), ' '));
const elem = document.createElement('a');