aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/socket.ts
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-10-22 00:04:17 -0700
committerAdam Soltys <[email protected]>2024-10-22 00:04:17 -0700
commitfe09eae6599c93d8d5bf0a398d11897508e2f1a4 (patch)
tree61b04387ecaf3d1acdcae66ead848994e45fdddc /src/lib/socket.ts
parent6aa43aaaa1bca2e925f32b487dea6cc1b18fdf79 (diff)
downloadcoinos-ui-fe09eae6599c93d8d5bf0a398d11897508e2f1a4.tar.gz
coinos-ui-fe09eae6599c93d8d5bf0a398d11897508e2f1a4.zip
get push subscription
Diffstat (limited to 'src/lib/socket.ts')
-rw-r--r--src/lib/socket.ts18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/lib/socket.ts b/src/lib/socket.ts
index bbedd3ed..02d441bf 100644
--- a/src/lib/socket.ts
+++ b/src/lib/socket.ts
@@ -1,9 +1,9 @@
+import { invalidate } from "$app/navigation";
import { navigating } from "$app/stores";
-import { get } from "svelte/store";
-import { event, invoice, request, last } from "$lib/store";
-import { success, sat, sleep, wait } from "$lib/utils";
import { PUBLIC_SOCKET } from "$env/static/public";
-import { invalidate } from "$app/navigation";
+import { event, invoice, last, request } from "$lib/store";
+import { sat, sleep, success, wait } from "$lib/utils";
+import { get } from "svelte/store";
let socket;
let token;
@@ -12,12 +12,12 @@ export const auth = () => token && send("login", token);
export const send = async (type, data) => {
try {
- await wait(() => socket && socket.readyState === 1, 100, 10);
+ await wait(() => socket && socket.readyState === 1, 1000, 10);
} catch (e: any) {
if (e.message === "timeout") reconnectToWebsocket();
}
- await wait(() => socket.readyState === 1, 100, 10);
+ await wait(() => socket.readyState === 1, 1000, 10);
socket.send(JSON.stringify({ type, data }));
};
@@ -38,7 +38,7 @@ export const messages = (data) => ({
},
async payment() {
- let { amount, confirmed } = data;
+ const { amount, confirmed } = data;
invalidate("app:user");
invalidate("app:invoice");
invalidate("app:payments");
@@ -72,10 +72,10 @@ export function close() {
}
async function onWebsocketMessage(msg) {
- let { type, data } = JSON.parse(msg.data);
+ const { type, data } = JSON.parse(msg.data);
if (get(navigating)) await sleep(2000);
- messages(data)[type] && messages(data)[type]();
+ if (messages(data)[type]) messages(data)[type]();
}
function onWebsocketOpen() {