From a2d5754e4be91250f4354010e373fa979bc29203 Mon Sep 17 00:00:00 2001 From: ElMoribond Date: Mon, 21 Jun 2021 17:07:14 +0200 Subject: [PATCH] Add ability to restart --- web/src/api/mqtt.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/src/api/mqtt.jsx b/web/src/api/mqtt.jsx index 6268b3d62..e0413efdf 100644 --- a/web/src/api/mqtt.jsx +++ b/web/src/api/mqtt.jsx @@ -72,13 +72,14 @@ export function MqttProvider({ return {children}; } -export function useMqtt(watchTopic, publishTopic) { +export function useMqtt(watchTopic, publishTopic, defaultValue = null) { const { state, ws } = useContext(Mqtt); - const value = state[watchTopic] || { payload: null }; + const value = state[watchTopic] || { payload: defaultValue }; const send = useCallback( (payload) => { + payload = payload || defaultValue; ws.send( JSON.stringify({ topic: publishTopic || watchTopic, @@ -118,3 +119,12 @@ export function useSnapshotsState(camera) { } = useMqtt(`${camera}/snapshots/state`, `${camera}/snapshots/set`); return { payload, send, connected }; } + +export function useRestart() { + const { + value: { payload }, + send, + connected, + } = useMqtt(``, `restart`, "container"); + return { send, connected }; +}