Skip to content

Commit

Permalink
usage
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Dec 31, 2024
1 parent efda848 commit c915a34
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BrowserContainer } from "./container/browsercontainer"
import { logusage } from "./utils/usage"

initialise()

Expand All @@ -7,4 +8,5 @@ function initialise() {
const params = new URLSearchParams(location.search)
const browserContainer = new BrowserContainer(canvas3d, params)
browserContainer.start()
logusage()
}
37 changes: 27 additions & 10 deletions src/utils/usage.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
export function logusage() {
const params = new URLSearchParams(location.search)
const ruletype = params.get("ruletype") ?? "nineball"
const mode = params.get("state") ? "replay" : "play"
const url = `https://scoreboard-tailuge.vercel.app/usage/${mode}/${ruletype}`

fetch(url, {
method: "GET",
mode: "cors",
headers: { "Content-Type": "application/json" },
})
}
if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
console.log("Skipping usage fetch for localhost.")
return;
}

const url = `https://scoreboard-tailuge.vercel.app/api/usage/game`

try {
fetch(url, {
method: "PUT",
mode: "cors",
})
.then(response => {
if (!response.ok) {
// Log HTTP errors (e.g., 4xx, 5xx)
console.error("HTTP error:", response.status, response.statusText)
}
})
.catch(error => {
// Log network errors or other fetch-related errors
console.error("Fetch error:", error)
});
} catch (error) {
// Log any synchronous errors that occur in the try block
console.error("Error in logusage:", error)
}
}

0 comments on commit c915a34

Please sign in to comment.