Fix viewer compatibility with older browsers and (hopefully) Safari

Closes #260
This commit is contained in:
chylex 2024-05-08 21:08:24 +02:00
parent 2d55ca4013
commit f54465e5fe
No known key found for this signature in database
GPG Key ID: 4DE42C8F19A80548
2 changed files with 36 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import discord from "./discord.mjs";
import gui from "./gui.mjs";
import state from "./state.mjs";
import "./polyfills.mjs";
window.DISCORD = discord;

View File

@ -0,0 +1,35 @@
// https://gist.github.com/MattiasBuelens/496fc1d37adb50a733edd43853f2f60e/088f061ab79b296f29225467ae9ba86ff990195d
ReadableStream.prototype.values ??= function({ preventCancel = false } = {}) {
const reader = this.getReader();
return {
async next() {
try {
const result = await reader.read();
if (result.done) {
reader.releaseLock();
}
return result;
} catch (e) {
reader.releaseLock();
throw e;
}
},
async return(value) {
if (!preventCancel) {
const cancelPromise = reader.cancel(value);
reader.releaseLock();
await cancelPromise;
}
else {
reader.releaseLock();
}
return { done: true, value };
},
[Symbol.asyncIterator]() {
return this;
}
};
};
ReadableStream.prototype[Symbol.asyncIterator] ??= ReadableStream.prototype.values;