this.kickPlayer(clientID)}
.onToggleNameReveal=${(clientID: string) =>
this.toggleNameReveal(clientID)}
.nameReveals=${this.nameReveals}
.anonymizeNames=${this.anonymizeNames}
>
`;
}
protected onOpen(): void {
this.startLobbyUpdates();
// The server mints the game id, so we don't know it until createLobby
// resolves. clientID is assigned by the server when we join the lobby.
// Pass auth token for creator identification (server extracts persistentID from it)
createLobby()
.then(async (lobby) => {
this.lobbyId = lobby.gameID;
if (!isValidGameID(this.lobbyId)) {
throw new Error(`Invalid lobby ID format: ${this.lobbyId}`);
}
crazyGamesSDK.showInviteButton(this.lobbyId);
// Now that we have the id, build and copy the share link. If lobby
// creation fails, the catch below clears the clipboard.
const url = await this.constructUrl();
this.updateLobbyHistory(url);
await this.updateComplete;
void (this.querySelector("copy-button") as CopyButton)?.handleCopy();
})
.then(() => {
this.dispatchEvent(
new CustomEvent("join-lobby", {
detail: {
gameID: this.lobbyId,
source: "host",
} as JoinLobbyEvent,
bubbles: true,
composed: true,
}),
);
})
.catch(() => {
// Clear clipboard so the host doesn't accidentally share a dead link
void navigator.clipboard.writeText("").catch(() => {});
});
// BaseModal.firstUpdated() owns modalEl.onClose so the o-modal close path
// (backdrop / close button) runs confirmBeforeClose(). Don't override it
// here — doing so would bypass the leave-lobby confirmation.
this.loadNationCount();
}
private leaveLobby() {
if (!this.lobbyId) {
return;
}
this.dispatchEvent(
new CustomEvent("leave-lobby", {
detail: { lobby: this.lobbyId },
bubbles: true,
composed: true,
}),
);
}
public confirmBeforeClose(): boolean | Promise