From 08e5c2e3d2e0da4e83d744e130847eb8e1b75384 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Mon, 4 Jan 2021 00:59:02 +0530 Subject: [PATCH] Add socket.io event handlers for voice:* messages --- src/WebSocket.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/WebSocket.js b/src/WebSocket.js index 1612a5a..6de1d75 100644 --- a/src/WebSocket.js +++ b/src/WebSocket.js @@ -4,6 +4,7 @@ import io from "socket.io-client"; import { WS_BASE } from "./config"; import { useDispatch } from "react-redux"; import { setData, setPlugin } from "./coreSlice"; +import { setRecording, setText } from "./voiceSlice"; const WebSocketContext = createContext(null); @@ -26,6 +27,20 @@ function WebSocketProvider({ children }) { }, payload.time); } }); + + socket.on("voice:wakeword", () => { + dispatch(setRecording(true)); + dispatch(setText(null)); + }); + socket.on("voice:record_end", () => { + dispatch(setRecording(false)); + dispatch(setText(null)); + }); + socket.on("voice:utterance", payload => { + dispatch(setRecording(false)); + dispatch(setText(payload.text)); + setTimeout(() => dispatch(setText(null)), 3000); + }); } return (