Add twitch chat integration

This commit is contained in:
2026-01-13 17:55:08 +01:00
parent 9abb5e88dc
commit 4f1eb2fc82
6 changed files with 240 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ export class BroadcastRenderer {
this.scriptWorkerReady = false;
this.scriptErrorKeys = new Set();
this.scriptAttachmentCache = new Map();
this.chatMessages = [];
this.obsBrowser = !!globalThis.obsstudio;
this.supportsAnimatedDecode =
@@ -409,6 +410,7 @@ export class BroadcastRenderer {
},
);
this.scriptWorkerReady = true;
this.updateScriptWorkerChatMessages();
}
updateScriptWorkerCanvas() {
@@ -424,6 +426,29 @@ export class BroadcastRenderer {
});
}
updateScriptWorkerChatMessages() {
if (!this.scriptWorker || !this.scriptWorkerReady) {
return;
}
this.scriptWorker.postMessage({
type: "chatMessages",
payload: {
messages: this.chatMessages,
},
});
}
receiveChatMessage(message) {
if (!message) {
return;
}
const now = Date.now();
const entry = { ...message, timestamp: now };
const cutoff = now - 120_000;
this.chatMessages = [...this.chatMessages, entry].filter((item) => item.timestamp >= cutoff);
this.updateScriptWorkerChatMessages();
}
extractScriptErrorLocation(stack, scriptId) {
if (!stack || !scriptId) {
return "";