Add socket.io event handlers for voice:* messages

This commit is contained in:
Ceda EI 2021-01-04 00:59:02 +05:30
parent 2c80c4b279
commit 08e5c2e3d2
1 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import io from "socket.io-client";
import { WS_BASE } from "./config"; import { WS_BASE } from "./config";
import { useDispatch } from "react-redux"; import { useDispatch } from "react-redux";
import { setData, setPlugin } from "./coreSlice"; import { setData, setPlugin } from "./coreSlice";
import { setRecording, setText } from "./voiceSlice";
const WebSocketContext = createContext(null); const WebSocketContext = createContext(null);
@ -26,6 +27,20 @@ function WebSocketProvider({ children }) {
}, payload.time); }, 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 ( return (