Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
Fix title getting lost due to multiple callbacks firing. Closes #2351
Gabe Kangasfa25b32ea858
diff --git a/web/components/TitleNotifier/TitleNotifier.tsx b/web/components/TitleNotifier/TitleNotifier.tsxindex 4ff3a3d0bf..e095f636e4 100644--- a/web/components/TitleNotifier/TitleNotifier.tsx+++ b/web/components/TitleNotifier/TitleNotifier.tsx@@ -5,31 +5,33 @@* page is backgrounded, this component will update the title to reflect it. ** @component*/-import { FC, useEffect } from 'react';+import { FC, useEffect, useState } from 'react';import { useRecoilValue } from 'recoil';import { serverStatusState, chatMessagesAtom } from '../stores/ClientConfigStore';-export const TitleNotifier: FC = () => {+export type TitleNotifierProps = {+ name: string;+};++export const TitleNotifier: FC<TitleNotifierProps> = ({ name }) => {const chatMessages = useRecoilValue(chatMessagesAtom);const serverStatus = useRecoilValue(serverStatusState);- let backgrounded = false;- let defaultTitle = '';+ const [backgrounded, setBackgrounded] = useState(false);++ const { online } = serverStatus;const setTitle = (title: string) => {- console.trace('Debug: Setting title to', title);- window.document.title = title;+ document.title = title;};const onBlur = () => {- console.log('onBlur: Saving defaultTitle as', window.document.title);- backgrounded = true;- defaultTitle = window.document.title;+ setBackgrounded(true);};const onFocus = () => {- backgrounded = false;- setTitle(defaultTitle);+ setBackgrounded(false);+ setTitle(name);};const listenForEvents = () => {@@ -38,40 +40,44 @@ export const TitleNotifier: FC = () => {window.addEventListener('focus', onFocus);};- useEffect(() => {- console.log('useEffect: Saving defaultTitle as', window.document.title);+ const removeEvents = () => {+ window.removeEventListener('blur', onBlur);+ window.removeEventListener('focus', onFocus);+ };- defaultTitle = window.document.title;+ useEffect(() => {listenForEvents();return () => {- window.removeEventListener('focus', onFocus);- window.removeEventListener('blur', onBlur);+ removeEvents();};- }, []);+ }, [name]);useEffect(() => {- const { online } = serverStatus;-if (!backgrounded || !online) {return;}- setTitle(`π¬ :: ${defaultTitle}`);- }, [chatMessages]);++ // Only alert on real chat messages from people.+ const lastMessage = chatMessages[chatMessages.length - 1];+ if (lastMessage.type !== 'CHAT') {+ return;+ }++ setTitle(`π¬ :: ${name}`);+ }, [chatMessages, name]);useEffect(() => {if (!backgrounded) {return;}- const { online } = serverStatus;-if (online) {- setTitle(` π’ :: ${defaultTitle}`);+ setTitle(` π’ :: ${name}`);} else if (!online) {- setTitle(` π΄ :: ${defaultTitle}`);+ setTitle(` π΄ :: ${name}`);}- }, [serverStatusState]);+ }, [online, name]);return null;};diff --git a/web/components/layouts/Main.tsx b/web/components/layouts/Main.tsxindex c609486c98..1ead29ee97 100644--- a/web/components/layouts/Main.tsx+++ b/web/components/layouts/Main.tsx@@ -71,7 +71,7 @@ export const Main: FC = () => {{isProduction ? (<Head>- {name ? <title>{name}</title> : <title>{`{{.Name}}`}</title>}+ {name ? <title>{name}</title> : <title>{'{{.Name}}'}</title>}<meta name="description" content="{{.Summary}}" /><meta property="og:title" content="{{.Name}}" />@@ -108,7 +108,7 @@ export const Main: FC = () => {)}<ClientConfigStore />- <TitleNotifier />+ <TitleNotifier name={name} /><Theme /><Layout ref={layoutRef} style={{ minHeight: '100vh' }}><Header name={title || name} chatAvailable={isChatAvailable} chatDisabled={chatDisabled} />