Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanMillett committed Nov 15, 2024
1 parent 46321d1 commit 8851414
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Layout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@
{
Settings.RefreshNavigation += RefreshNavigation;
}


protected override async Task OnInitializedAsync()
{
await Runtime.InvokeVoidAsync("logTraffic");
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
await Settings.ApplySettings();
Expand Down
1 change: 1 addition & 0 deletions wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<link rel="apple-touch-icon" sizes="192x192" href="images/icon_192.png" />

<script src="https://cdn.rawgit.com/satazor/SparkMD5/master/spark-md5.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/platform/1.3.6/platform.min.js"></script>

<script src="js/audio.js"></script>
<script src="js/helpers.js"></script>
Expand Down
66 changes: 66 additions & 0 deletions wwwroot/js/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,72 @@ async function isServerOnline()
}
}

async function logTraffic()
{
if (await isServerOnline())
{
try
{
var trafficMessage;

if (typeof navigator.userAgentData === 'undefined')
{
var info = platform.parse(navigator.userAgent);

trafficMessage =
{
name: info.name || "",
version: info.version || "",
product: info.product || "",
manufacturer: info.manufacturer || "",
layout: info.layout || "",
system: `${info.os.architecture || ""} ${info.os.family || ""} ${info.os.version || ""}`,
description: info.description || "",
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "",
language: navigator.language || "",
}

} else
{
trafficMessage =
{
name: platform.name || "",
version: platform.version || "",
product: platform.product || "",
manufacturer: platform.manufacturer || "",
layout: platform.layout || "",
system: `${platform.os.architecture || ""} ${platform.os.family || ""} ${platform.os.version || ""}`,
description: platform.description || "",
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone || "",
language: navigator.language || "",
}
}

console.log(JSON.stringify(trafficMessage));

const response = await fetch("https://vetra.jordanmillett.net/api/traffic", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(trafficMessage),
});

if (response.ok)
{
console.log('Traffic data sent successfully');
} else
{
console.error('Failed to send traffic data', response.statusText);
}
} catch (error)
{
console.error('Error collecting or sending traffic data:', error);
}

}
}

async function loadServiceWorker()
{
if ('serviceWorker' in navigator)
Expand Down

0 comments on commit 8851414

Please sign in to comment.