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 }; +}