From 10f1194abd7c0a0e15f03c93a85938a01a5c1dab Mon Sep 17 00:00:00 2001 From: Sacha Bron Date: Sun, 18 Aug 2024 02:26:57 +0200 Subject: [PATCH 1/9] Hotfix dev mode --- client/.env.development | 1 + client/src/axios-common.ts | 5 ++++- client/src/ws.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client/.env.development b/client/.env.development index e69de29..89c6524 100644 --- a/client/.env.development +++ b/client/.env.development @@ -0,0 +1 @@ +VITE_ORBITAL_SERVER_URL=http://localhost:3000 \ No newline at end of file diff --git a/client/src/axios-common.ts b/client/src/axios-common.ts index 51a6d40..3eb58b5 100644 --- a/client/src/axios-common.ts +++ b/client/src/axios-common.ts @@ -1,7 +1,10 @@ import { Axios } from "axios"; +console.log(import.meta.env.DEV); +console.log(import.meta.env.VITE_ORBITAL_SERVER_URL); + export const axiosInstance = new Axios({ - baseURL: window.location.href ?? "", + baseURL: import.meta.env.DEV ? import.meta.env.VITE_ORBITAL_SERVER_URL ?? "" : window.location.href, transformRequest: (data) => JSON.stringify(data), headers: { "Content-Type": "application/json", diff --git a/client/src/ws.ts b/client/src/ws.ts index de7c261..b5d73a1 100644 --- a/client/src/ws.ts +++ b/client/src/ws.ts @@ -25,7 +25,7 @@ export const WebSocketHandler = { } console.log("Starting connection to WebSocket Server"); - const wsUrl = new URL(window.location.href); + const wsUrl = import.meta.env.DEV ? new URL(import.meta.env.SERVER_URL) : new URL(window.location.href); // const wsProtocol = window.location.protocol === "https:" ? "wss://" : "ws://"; // export const ws = new WebSocket(wsProtocol + location.host + "/"); From b3971f134f945db08c42b74671b09b25f021997d Mon Sep 17 00:00:00 2001 From: Sacha Bron Date: Sun, 18 Aug 2024 03:08:06 +0200 Subject: [PATCH 2/9] Sync lamp info --- client/src/views/LampPage.vue | 14 ++++++++++++++ server/lamp/index.ts | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/client/src/views/LampPage.vue b/client/src/views/LampPage.vue index af23705..0590442 100644 --- a/client/src/views/LampPage.vue +++ b/client/src/views/LampPage.vue @@ -93,8 +93,22 @@ onMounted(() => { axiosInstance.get("/lamp/brightness") .then(res => JSON.parse(res.data)) .then(data => brightness.value = data.brightness); + + refreshAnimationAndCharacteristics(); }); +function refreshAnimationAndCharacteristics() { + axiosInstance.get(`/lamp/animation`) + .then(res => { + return JSON.parse(res.data); + }) + .then(data => { + console.log(data); + currentConfig.selectedAnimation = data.animation.name; + onNewAnimation(); + }) +} + function onSmartColorUpdate(smartColor: SmartColor, i: number) { characteristics.array[i].value = smartColor; onChange(); diff --git a/server/lamp/index.ts b/server/lamp/index.ts index 7c02b7d..0cab217 100644 --- a/server/lamp/index.ts +++ b/server/lamp/index.ts @@ -136,6 +136,10 @@ export function initLamp() { res.send("OK"); }); + lamp.get("/animation", (req, res) => { + res.send({ animation: animationStore[currentAnimation] }); + }); + lamp.post("/animation", (req, res) => { const animation: string = req.body.animation; From ed4bb04a3d7c90eb42cd5b6075af9480180900f5 Mon Sep 17 00:00:00 2001 From: Sacha Bron Date: Mon, 19 Aug 2024 00:15:31 +0200 Subject: [PATCH 3/9] Fix root location --- client/src/axios-common.ts | 2 +- client/src/ws.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/axios-common.ts b/client/src/axios-common.ts index 3eb58b5..87d4ae2 100644 --- a/client/src/axios-common.ts +++ b/client/src/axios-common.ts @@ -4,7 +4,7 @@ console.log(import.meta.env.DEV); console.log(import.meta.env.VITE_ORBITAL_SERVER_URL); export const axiosInstance = new Axios({ - baseURL: import.meta.env.DEV ? import.meta.env.VITE_ORBITAL_SERVER_URL ?? "" : window.location.href, + baseURL: import.meta.env.DEV ? import.meta.env.VITE_ORBITAL_SERVER_URL ?? "" : window.location.origin, transformRequest: (data) => JSON.stringify(data), headers: { "Content-Type": "application/json", diff --git a/client/src/ws.ts b/client/src/ws.ts index b5d73a1..f0bcb74 100644 --- a/client/src/ws.ts +++ b/client/src/ws.ts @@ -25,7 +25,7 @@ export const WebSocketHandler = { } console.log("Starting connection to WebSocket Server"); - const wsUrl = import.meta.env.DEV ? new URL(import.meta.env.SERVER_URL) : new URL(window.location.href); + const wsUrl = import.meta.env.DEV ? new URL(import.meta.env.SERVER_URL) : new URL(window.location.origin); // const wsProtocol = window.location.protocol === "https:" ? "wss://" : "ws://"; // export const ws = new WebSocket(wsProtocol + location.host + "/"); From 6d7727fe93c4c7450a24ca6869c14040f9d60118 Mon Sep 17 00:00:00 2001 From: Sacha Bron Date: Mon, 19 Aug 2024 01:00:00 +0200 Subject: [PATCH 4/9] Sync color picker and other characteristics --- .../components/shared/SmartColorPicker.vue | 20 +++++++++- client/src/views/LampPage.vue | 39 +++++++++++-------- package-lock.json | 10 ++--- tsconfig.json | 3 +- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/client/src/components/shared/SmartColorPicker.vue b/client/src/components/shared/SmartColorPicker.vue index 3a62b6c..6d309d0 100644 --- a/client/src/components/shared/SmartColorPicker.vue +++ b/client/src/components/shared/SmartColorPicker.vue @@ -30,7 +30,7 @@