Skip to content

Commit

Permalink
fix: Auto-claim host when first connecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderson1993 committed Feb 10, 2023
1 parent 945dd22 commit 52b4d75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client/src/components/QuoteOfTheDay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ const quotes = [
"Life's like a movie, write your own ending, keep believing, keep pretending.",
"There's not a word yet for old friends who've just met.",
"Life is made up of meetings and partings and that is the way of it.",
// Chantastic
"It's only dark until your eyes adjust.",
];

const QuoteOfTheDay = () => {
Expand Down
14 changes: 14 additions & 0 deletions server/src/init/liveQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,25 @@ export class Client<TRouter extends AnyRouter> extends ServerClient<TRouter> {
return {id, name, isHost};
}
connectionOpened(): void {
// Claim host if there isn't one already claimed
const ctx = getDataContext(this.id);
if (ctx) {
const hasHost = Object.values(ctx.server.clients).some(
client => client.isHost && client.connected
);
if (!hasHost) {
this.isHost = true;
}
}
pubsub.publish.client.get({clientId: this.id});
pubsub.publish.client.all();
pubsub.publish.thorium.hasHost();
}
connectionClosed(): void {
pubsub.publish.client.get({clientId: this.id});
pubsub.publish.client.all();
if (this.isHost) {
pubsub.publish.thorium.hasHost();
}
}
}
1 change: 0 additions & 1 deletion shared/live-query/adapters/fastify-adapter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ export class ServerClient<TRouter extends AnyRouter> {
) {}
encode(data: any) {
return encode(data);
// return JSON.stringify(data);
}
public async initWebSocket(
connection: SocketStream,
Expand Down

0 comments on commit 52b4d75

Please sign in to comment.