From 20ba9be6ae17208d5fe6b376cae41da84be4ca8e Mon Sep 17 00:00:00 2001 From: Kostya Date: Sun, 4 Feb 2024 14:35:19 +0300 Subject: [PATCH] added logic for setvalue timer in crash --- luckydiamond/src/assets/js/chat/ChatLogic.js | 136 +++++++++--------- .../src/pages/games-pages/CrashgamePage.vue | 17 ++- 2 files changed, 86 insertions(+), 67 deletions(-) diff --git a/luckydiamond/src/assets/js/chat/ChatLogic.js b/luckydiamond/src/assets/js/chat/ChatLogic.js index 1280ec6..0bbece7 100644 --- a/luckydiamond/src/assets/js/chat/ChatLogic.js +++ b/luckydiamond/src/assets/js/chat/ChatLogic.js @@ -1,66 +1,70 @@ -// import { BackendWebSocketUrl } from '@/properties/Сonfig.js'; -// import { eventBus } from "@/main"; -// import { -// GetCookie -// } from "@/assets/js/storage/CookieStorage.js"; -// -// let webSocket; -// -// export function ConnectToChat() { -// try { -// webSocket = new WebSocket(BackendWebSocketUrl); -// -// webSocket.onopen = function () { -// console.log('Connection established'); -// }; -// -// webSocket.onmessage = function (event) { -// -// const dataObject = JSON.parse(event.data); -// -// if (dataObject && Object.prototype.hasOwnProperty.call(dataObject, 'SpUserName') && Object.prototype.hasOwnProperty.call(dataObject, 'Message')) { -// eventBus.emit('dataChat', event.data); -// } -// -// console.log('Message from Server:', event.data); -// }; -// -// webSocket.onclose = function () { -// -// webSocket = new WebSocket(BackendWebSocketUrl); -// -// console.log('Connection closed and reconnected'); -// }; -// -// webSocket.onerror = function (event) { -// console.error('WebSocket Error:', event); -// }; -// } catch (error) { -// console.error('Error in ConnectToChat:', error); -// } -// } -// -// export function SendMessageToChat(message) { -// try { -// -// if (!GetCookie("SpUserName") && !GetCookie("AUTHTOKEN") && !GetCookie("SearchToken")) { -// return; -// } -// -// const userCredentials = { -// SearchToken: GetCookie("SearchToken"), -// AUTHTOKEN: GetCookie("AUTHTOKEN") -// }; -// -// const messageObject = { -// UserCredentials: userCredentials, -// Message: message, -// MessageType: "Chat" -// }; -// -// webSocket.send(JSON.stringify(messageObject)); -// -// } catch (error) { -// console.error('Error in ConnectToChat:', error); -// } -// } \ No newline at end of file +import { BackendWebSocketUrl } from '@/properties/Сonfig.js'; +import { eventBus } from "@/main"; +import { + GetCookie +} from "@/assets/js/storage/CookieStorage.js"; + +let webSocket; + +export function ConnectToChat() { + try { + webSocket = new WebSocket(BackendWebSocketUrl); + + webSocket.onopen = function () { + console.log('Connection established'); + }; + + webSocket.onmessage = function (event) { + + const dataObject = JSON.parse(event.data); + + if (dataObject && Object.prototype.hasOwnProperty.call(dataObject, 'SpUserName') && Object.prototype.hasOwnProperty.call(dataObject, 'Message')) { + eventBus.emit('dataChat', event.data); + console.log('CHAT') + } + else { + eventBus.emit('crash', event.data) + } + + // console.log('Message from Server:', event.data); + }; + + webSocket.onclose = function () { + + webSocket = new WebSocket(BackendWebSocketUrl); + + console.log('Connection closed and reconnected'); + }; + + webSocket.onerror = function (event) { + console.error('WebSocket Error:', event); + }; + } catch (error) { + console.error('Error in ConnectToChat:', error); + } +} + +export function SendMessageToChat(message) { + try { + + if (!GetCookie("SpUserName") && !GetCookie("AUTHTOKEN") && !GetCookie("SearchToken")) { + return; + } + + const userCredentials = { + SearchToken: GetCookie("SearchToken"), + AUTHTOKEN: GetCookie("AUTHTOKEN") + }; + + const messageObject = { + UserCredentials: userCredentials, + Message: message, + MessageType: "Chat" + }; + + webSocket.send(JSON.stringify(messageObject)); + + } catch (error) { + console.error('Error in ConnectToChat:', error); + } +} \ No newline at end of file diff --git a/luckydiamond/src/pages/games-pages/CrashgamePage.vue b/luckydiamond/src/pages/games-pages/CrashgamePage.vue index d898a33..eafaa39 100644 --- a/luckydiamond/src/pages/games-pages/CrashgamePage.vue +++ b/luckydiamond/src/pages/games-pages/CrashgamePage.vue @@ -74,6 +74,7 @@ import '@/assets/css/PagesStyles/games-pages/crash.css' import SaperNumbers from "@/mocks/SaperNumbers"; import {GetCurrentMoney} from "@/assets/js/rest/RestMethods"; import {GetCookie} from "@/assets/js/storage/CookieStorage"; +import {eventBus} from "@/main"; export default { components: { HeaderComponent, AsideBarComponent, ChatComponent, CrashGraphComponent }, @@ -81,12 +82,26 @@ export default { return { SaperNumbers, amountDeposit: 0, - autoRatio: 0 + autoRatio: 0, + timerGame: '' } }, setup() { return { v$: useVuelidate() } }, + mounted() { + eventBus.on('crash', (dataCrash) => { + try { + const dataCrashParse = JSON.parse(dataCrash) + + this.timerGame = dataCrashParse.WaitingTime + console.log(this.timerGame) + } + catch (e) { + console.error(e) + } + }) + }, validations() { return { amountDeposit: { required, numeric, minValue: minValue(1), maxValue: maxValue(100), integer },