change vars.js.template to tempalte.vars.js,

implement interrupt based client sync
This commit is contained in:
Arthur Lu 2023-07-13 22:53:57 +00:00
parent 995513c9b8
commit c8919307af
3 changed files with 18 additions and 3 deletions

View File

@ -33,7 +33,7 @@ After this step, the Client should be available on the `Client Host` at port `80
## Configuration - Client ## Configuration - Client
1. In `Client Host`, navigate to this repo's root folder 1. In `Client Host`, navigate to this repo's root folder
2. Copy `vars.js.template` to `vars.js` and assign the `API` variable with the value of the API's URL. This will likely be `client.<FQDN>/api` 2. Rename `tempalte.vars.js` to `vars.js` and assign the `API` variable with the value of the API's URL. This will likely be `client.<FQDN>/api`
## Installation - API ## Installation - API

View File

@ -1,4 +1,5 @@
import { requestAPI } from "./utils.js"; import { requestAPI } from "./utils.js";
import { API } from "../vars.js";
export async function setupClientSync (callback) { export async function setupClientSync (callback) {
let scheme = localStorage.getItem("sync-scheme"); let scheme = localStorage.getItem("sync-scheme");
@ -29,9 +30,23 @@ export async function setupClientSync (callback) {
}, rate * 1000); }, rate * 1000);
} }
else if (scheme === "interrupt") { else if (scheme === "interrupt") {
callback();
const socket = new WebSocket(`wss://${API.replace("https://", "")}/sync/interrupt`);
socket.addEventListener("open", (event) => {
socket.send(`rate ${rate}`);
});
socket.addEventListener("message", (event) => {
let message = event.data.toString();
if (message === "sync") {
callback();
} }
else { else {
console.error("clientsync: recieved unexpected message from server, closing socket.")
socket.close();
}
});
}
else {
console.error(`clientsync: unsupported scheme ${scheme} selected.`)
} }
} }