mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-07-03 17:13:43 -04:00
API & WebSocket now working
Can Read Status File & Broadcast contents via websocket
This commit is contained in:
@ -1,13 +1,56 @@
|
||||
<script lang="ts">
|
||||
let x = $state(1)
|
||||
import * as signalR from "@microsoft/signalr"
|
||||
import {onMount} from "svelte";
|
||||
let x = $state(null);
|
||||
let textarea = $state("");
|
||||
|
||||
const increment = () => {
|
||||
x = x + 1;
|
||||
const connection = new signalR.HubConnectionBuilder()
|
||||
.withUrl("http://localhost:5000/api/events")
|
||||
.configureLogging(signalR.LogLevel.Information)
|
||||
.build();
|
||||
|
||||
onMount(async () => {
|
||||
|
||||
connection.onclose(async () => {
|
||||
console.log("Lost connection to Event Hub. Attempting to reconnect...");
|
||||
await connection.start();
|
||||
});
|
||||
|
||||
connection.on("StatusUpdated", (message) => {
|
||||
console.log('we did it!');
|
||||
console.log(message);
|
||||
textarea += JSON.stringify(message) + "\n"
|
||||
});
|
||||
|
||||
await connection.start();
|
||||
})
|
||||
|
||||
const getStatus = async () => {
|
||||
var response = await fetch("http://localhost:5000/api/status", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
});
|
||||
|
||||
if (response.ok)
|
||||
{
|
||||
const data = await response.text();
|
||||
console.log(data);
|
||||
x = data;
|
||||
}
|
||||
|
||||
console.log(response);
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1>Welcome to Pulsar</h1>
|
||||
|
||||
<button on:click={increment} > Increment </button>
|
||||
<button on:click={getStatus}> GetStatus </button>
|
||||
|
||||
<span> {x} </span>
|
||||
|
||||
<br/>
|
||||
|
||||
<textarea bind:value={textarea}></textarea>
|
||||
|
Reference in New Issue
Block a user