From 209f536693933b4137792617a7a4c8edfafd5e39 Mon Sep 17 00:00:00 2001 From: Kakabay <2kakabayashyrberdyew@gmail.com> Date: Fri, 24 Jan 2025 18:20:46 +0500 Subject: [PATCH] websocket and api updates --- components/lottery/LotteryWinnersSection.tsx | 6 ++++-- hooks/useWebSocketLottery.ts | 1 + models/lottery/lottery.model.ts | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/lottery/LotteryWinnersSection.tsx b/components/lottery/LotteryWinnersSection.tsx index 123cabe..a8a0728 100644 --- a/components/lottery/LotteryWinnersSection.tsx +++ b/components/lottery/LotteryWinnersSection.tsx @@ -10,7 +10,7 @@ import { useWebsocketLottery } from "@/hooks/useWebSocketLottery"; import Confetti from "../common/Confetti"; import { AnimatePresence, motion } from "framer-motion"; -const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst=0506"; +const WEBSOCKET_URL = "wss://sms.turkmentv.gov.tm/ws/lottery?dst="; const SLOT_COUNTER_DURATION = 30000; const LotteryWinnersSection = ({ @@ -36,7 +36,9 @@ const LotteryWinnersSection = ({ >([]); // Queue for incoming WebSocket messages const [isProcessing, setIsProcessing] = useState(false); // Track if a message is being processed - const { wsStatus, subscribeToMessages } = useWebsocketLottery(WEBSOCKET_URL); + const { wsStatus, subscribeToMessages } = useWebsocketLottery( + `${WEBSOCKET_URL}${lotteryData?.data.sms_number}` + ); // Simulate WebSocket messages for testing const simulateMessage = () => { diff --git a/hooks/useWebSocketLottery.ts b/hooks/useWebSocketLottery.ts index ca44011..c190106 100644 --- a/hooks/useWebSocketLottery.ts +++ b/hooks/useWebSocketLottery.ts @@ -22,6 +22,7 @@ export const useWebsocketLottery = (url: string) => { if (!isMounted) return; console.log("✅ WebSocket connected"); + console.log("WebSocket url", url); setWsStatus("connected"); if (reconnectTimeoutRef.current) clearTimeout(reconnectTimeoutRef.current); diff --git a/models/lottery/lottery.model.ts b/models/lottery/lottery.model.ts index e8e95e4..f6c08f1 100644 --- a/models/lottery/lottery.model.ts +++ b/models/lottery/lottery.model.ts @@ -7,7 +7,6 @@ export interface ILotteryWinner { } export interface ILotteryRule { title: string; - content: string; } export interface ILotteryData { @@ -18,6 +17,7 @@ export interface ILotteryData { start_time: string; end_time: string; sms_code: string; + sms_number: string; winners: ILotteryWinner[]; rules: ILotteryRule[] | null; }