aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/socket.js4
-rw-r--r--src/lib/utils.js5
2 files changed, 9 insertions, 0 deletions
diff --git a/src/lib/socket.js b/src/lib/socket.js
index 9d0c472e..14555bd3 100644
--- a/src/lib/socket.js
+++ b/src/lib/socket.js
@@ -46,6 +46,10 @@ export function connect() {
interval = setInterval(() => send('heartbeat'), 5000);
}
+export function close() {
+ if (socket) socket.close();
+}
+
function onWebsocketMessage(msg) {
let { type, data } = JSON.parse(msg.data);
messages(data)[type] && messages(data)[type]();
diff --git a/src/lib/utils.js b/src/lib/utils.js
index c17b0a98..e9d1b73e 100644
--- a/src/lib/utils.js
+++ b/src/lib/utils.js
@@ -6,6 +6,11 @@ export function scroll(section) {
const base = browser ? '' : import.meta.env.VITE_COINOS_URL;
+export const get = (url) =>
+ fetch(base + url, {
+ headers: { accept: 'application/json'}
+ }).then((r) => r.json());
+
export const post = (url, body) =>
fetch(base + url, {
method: 'POST',