Skip to content

Commit

Permalink
Merge branch 'master' of github.com:LiveTL/HyperChat
Browse files Browse the repository at this point in the history
  • Loading branch information
KentoNishi committed May 6, 2022
2 parents c03fe60 + 4880742 commit 1936416
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/components/Hyperchat.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
case 'themeUpdate':
ytDark = response.dark;
break;
case 'registerClientResponse':
break;
default:
console.error('Unknown payload type', { port, response });
break;
Expand Down
2 changes: 1 addition & 1 deletion src/components/changelog/Changelog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
broken when using HyperChat with LiveTL
</li>
<li class="ml-3.5">
Fixed issues with the chat freezing or clearning
Fixed issues with the chat freezing or clearing
when watching VODs
</li>
<li class="ml-3.5">
Expand Down
24 changes: 23 additions & 1 deletion src/scripts/chat-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,29 @@ const registerClient = (
frameInfo,
{ interceptors, port, frameInfo }
);
if (!interceptor) return;
if (!interceptor) {
port.postMessage(
{
type: 'registerClientResponse',
success: false,
failReason: 'Interceptor not found'
}
);
return;
}

if (interceptor.clients.some((client) => client.name === port.name)) {
console.debug(
'Client already registered. Not registering',
{ interceptors, port, frameInfo }
);
port.postMessage(
{
type: 'registerClientResponse',
success: false,
failReason: 'Client already registered'
}
);
return;
}

Expand All @@ -187,6 +203,12 @@ const registerClient = (
// Add client to array
interceptor.clients.push(port);
console.debug('Register client successful', { port, interceptor });
port.postMessage(
{
type: 'registerClientResponse',
success: true
}
);

if (getInitialData && isYtcInterceptor(interceptor)) {
const payload = {
Expand Down
8 changes: 6 additions & 2 deletions src/scripts/chat-injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const chatLoaded = async (): Promise<void> => {
}
};

setTimeout(() => {
if (isLiveTL) {
chatLoaded().catch(console.error);
}, isLiveTL ? 0 : 500);
} else {
setTimeout(() => {
chatLoaded().catch(console.error);
}, 500);
}
8 changes: 6 additions & 2 deletions src/scripts/chat-interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ const chatLoaded = async (): Promise<void> => {
document.body.appendChild(fixLeakScript);
};

setTimeout(() => {
if (isLiveTL) {
chatLoaded().catch(console.error);
}, isLiveTL ? 0 : 500);
} else {
setTimeout(() => {
chatLoaded().catch(console.error);
}, 500);
}
8 changes: 7 additions & 1 deletion src/ts/typings/chat.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,13 @@ declare namespace Chat {
message: LtlMessage;
}

type BackgroundResponse = Actions | InitialData | ThemeUpdate | LtlMessageResponse;
interface registerClientResponse {
type: 'registerClientResponse';
success: boolean;
failReason?: string;
}

type BackgroundResponse = Actions | InitialData | ThemeUpdate | LtlMessageResponse | registerClientResponse;

type InterceptorSource = 'ytc' | 'ltlMessage';

Expand Down

0 comments on commit 1936416

Please sign in to comment.