From be002d3c84f981caaea255726e38f6fb087f0081 Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Sun, 15 Jan 2023 09:40:20 -0500 Subject: [PATCH] websockets working! --- frontend/src/Call/CallInfo.js | 5 -- frontend/src/Call/CallPlayer.js | 59 +++++++++++------------ frontend/src/features/calls/callsSlice.js | 6 +-- 3 files changed, 30 insertions(+), 40 deletions(-) diff --git a/frontend/src/Call/CallInfo.js b/frontend/src/Call/CallInfo.js index 9d1543d..1818242 100644 --- a/frontend/src/Call/CallInfo.js +++ b/frontend/src/Call/CallInfo.js @@ -12,8 +12,6 @@ import { // ---------------------------------------------------- function CallInfo(props) { - - let srcList = ""; let callLength = "-"; let callFreq = "-"; @@ -39,8 +37,6 @@ function CallInfo(props) { callTweet = "https://twitter.com/intent/tweet?url="+encodeURIComponent(document.location.origin+props.link)+"&via="+encodeURIComponent("OpenMHz"); } - - return (
@@ -86,7 +82,6 @@ function CallInfo(props) {
); - } export default CallInfo; diff --git a/frontend/src/Call/CallPlayer.js b/frontend/src/Call/CallPlayer.js index 21675b5..b794f64 100644 --- a/frontend/src/Call/CallPlayer.js +++ b/frontend/src/Call/CallPlayer.js @@ -70,6 +70,8 @@ function CallPlayer(props) { const navigate = useNavigate(); const dispatch = useDispatch(); const positionRef = useRef(); + const isPlayingRef = useRef(); // we need to do this to make the current value of isPlaying available in the socket message callback + isPlayingRef.current = isPlaying; const filterType = useSelector((state) => state.callPlayer.filterType); const filterGroupId = useSelector((state) => state.callPlayer.filterGroupId); @@ -91,7 +93,9 @@ function CallPlayer(props) { - const handlePlayPause = (playing) => setIsPlaying(playing); + const handlePlayPause = (playing) => { + setIsPlaying(playing); + } const handlePusherClick = () => { if (sidebarOpened) setSidebarOpened(false); @@ -155,19 +159,12 @@ function CallPlayer(props) { const ref = positionRef; setPrevScrollHeight(positionRef.clientHeight); setAddCallScroll(true); - dispatch(addCall(message)) - /*const refs = this.refs.current; - callActions.addCall(message); - const newCall = callsById[callsAllIds[0]]; - if (!isPlaying && autoPlay) { - this.playCall({ call: newCall }); - if (this.currentCallRef.current) { - this.currentCallRef.current.scrollIntoView({ - behavior: "smooth", - block: "center", - }); - } - }*/ + + if (!isPlayingRef.current) { + setCurrentCall(message); + } + + dispatch(addCall(message)); console.log("Got: " + message); break default: @@ -177,31 +174,18 @@ function CallPlayer(props) { const startSocket = () => { const filter = getFilterDescription(); + socket.emit("start", { - filterCode: filter.Code, - filterType: filter.Type, + filterCode: filter.code, + filterType: filter.type, filterName: "OpenMHz", - filterStarred: filter.Starred, + filterStarred: filter.starred, shortName: shortName }); } const stopSocket = () => { socket.emit("stop"); } - const handleLiveToggle = () => { - if (!live) { - dispatch(setDateFilter(false)); - dispatch(setLive(true)); - setCurrentCall(false); - - dispatch(getCalls({})); - - this.startSocket(); - } - } - - - const updateUri = () => { var search = "?" @@ -241,6 +225,16 @@ function CallPlayer(props) { } + const handleLiveToggle = () => { + if (!live) { + dispatch(setDateFilter(false)); + dispatch(setLive(true)); + setCurrentCall(false); + dispatch(getCalls({})); + + this.startSocket(); + } + } const handleCalendarClose = (didUpdate) => { setCalendarVisible(!calendarVisible); @@ -386,7 +380,7 @@ function CallPlayer(props) { } }) - socket.on("new message", handleSocketMessage); + socket.on("new message", handleSocketMessage ); return () => { socket.off('connect'); @@ -416,6 +410,7 @@ function CallPlayer(props) { }, [groupsData]) + var archiveLabel = ""; if (filterDate) { const filterDateObj = new Date(filterDate); diff --git a/frontend/src/features/calls/callsSlice.js b/frontend/src/features/calls/callsSlice.js index 9ed497c..22ee104 100644 --- a/frontend/src/features/calls/callsSlice.js +++ b/frontend/src/features/calls/callsSlice.js @@ -202,8 +202,8 @@ export const callsSlice = createSlice({ initialState, reducers: { - addCall: (call) => { - state.data = callsAdapter.addOne(state.data, call) + addCall: (state, action) => { + state.data = callsAdapter.addOne(state.data, action.payload) }, }, extraReducers: { @@ -269,5 +269,5 @@ export const callsSlice = createSlice({ } } }) - +export const { addCall } = callsSlice.actions export const callsReducer = callsSlice.reducer;