diff --git a/README.md b/README.md index 6de0565..22375d7 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ After this step, the Client should be available on the `Client Host` at port `80 ## Configuration - Client 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./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./api` ## Installation - API diff --git a/scripts/clientsync.js b/scripts/clientsync.js index 253dd17..7c604fe 100644 --- a/scripts/clientsync.js +++ b/scripts/clientsync.js @@ -1,4 +1,5 @@ import { requestAPI } from "./utils.js"; +import { API } from "../vars.js"; export async function setupClientSync (callback) { let scheme = localStorage.getItem("sync-scheme"); @@ -29,9 +30,23 @@ export async function setupClientSync (callback) { }, rate * 1000); } 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 { + console.error("clientsync: recieved unexpected message from server, closing socket.") + socket.close(); + } + }); } else { - + console.error(`clientsync: unsupported scheme ${scheme} selected.`) } } \ No newline at end of file diff --git a/vars.js.template b/template.vars.js similarity index 100% rename from vars.js.template rename to template.vars.js