From fc93259f1e79fa1e0e36cdff7b588e4a03b1aa21 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 17 Sep 2024 14:08:19 +0200 Subject: [PATCH] add wss back --- src/routes/crypto/[tickerID]/+layout.svelte | 2 +- src/routes/etf/[tickerID]/+layout.svelte | 4 ++-- src/routes/options-flow/+page.svelte | 10 +++++----- src/routes/stocks/[tickerID]/+layout.svelte | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/routes/crypto/[tickerID]/+layout.svelte b/src/routes/crypto/[tickerID]/+layout.svelte index cbfa1410..e50e7fd4 100644 --- a/src/routes/crypto/[tickerID]/+layout.svelte +++ b/src/routes/crypto/[tickerID]/+layout.svelte @@ -305,7 +305,7 @@ onMount(async () => { //const endTime = currentDateTime.set({ hour: 22, minute: 0 }); // Check if it's not a weekend and the current time is within the specified range - //await websocketRealtimeData() + await websocketRealtimeData() // Add a scroll event listener diff --git a/src/routes/etf/[tickerID]/+layout.svelte b/src/routes/etf/[tickerID]/+layout.svelte index 11693591..84f1a354 100644 --- a/src/routes/etf/[tickerID]/+layout.svelte +++ b/src/routes/etf/[tickerID]/+layout.svelte @@ -314,12 +314,12 @@ async function fetchPortfolio() //const endTime = currentDateTime.set({ hour: 22, minute: 0 }); // Check if it's not a weekend and the current time is within the specified range - /* + if ($isOpen) //&& currentDateTime > startTime && currentDateTime < endTime { await websocketRealtimeData() } - */ + // Add a scroll event listener window.addEventListener('scroll', handleScroll); diff --git a/src/routes/options-flow/+page.svelte b/src/routes/options-flow/+page.svelte index 9ac73db4..87ae79a7 100644 --- a/src/routes/options-flow/+page.svelte +++ b/src/routes/options-flow/+page.svelte @@ -374,11 +374,12 @@ async function websocketRealtimeData() { let newData = []; try { socket = new WebSocket(data?.wsURL + "/options-flow-reader"); - + /* socket.addEventListener("open", () => { const ids = rawData.map(item => item.id); sendMessage(JSON.stringify({ ids })); }); + */ socket.addEventListener('message', (event) => { previousCallVolume = displayCallVolume ?? 0; @@ -389,14 +390,14 @@ async function websocketRealtimeData() { newData.forEach((item) => { item.dte = daysLeft(item?.date_expiration); }); - rawData = [...newData, ...rawData]; + rawData = newData; } if (ruleOfList?.length !== 0 || filterQuery?.length !== 0) { shouldLoadWorker.set(true); } if (previousCallVolume !== displayCallVolume && !muted && audio) { - audio.play(); + audio?.play(); } } catch (e) { console.error('Error processing WebSocket message:', e); @@ -463,11 +464,10 @@ function daysLeft(targetDate) { }); isLoaded = true; - /* + if ($isOpen) { await websocketRealtimeData(); } - */ diff --git a/src/routes/stocks/[tickerID]/+layout.svelte b/src/routes/stocks/[tickerID]/+layout.svelte index 5a196a7c..37de7e1c 100644 --- a/src/routes/stocks/[tickerID]/+layout.svelte +++ b/src/routes/stocks/[tickerID]/+layout.svelte @@ -226,12 +226,12 @@ async function fetchPortfolio() //SellTrade = (await import('$lib/components/SellTrade.svelte')).default; PriceAlert = (await import("$lib/components/PriceAlert.svelte")).default; } - /* + if ($isOpen) { //&& currentDateTime > startTime && currentDateTime < endTime await websocketRealtimeData(); - }*/ - + } + }); afterUpdate(async () => {