diff --git a/src/routes/LobyPage.tsx b/src/routes/LobyPage.tsx index c20ae89..dcccaa9 100644 --- a/src/routes/LobyPage.tsx +++ b/src/routes/LobyPage.tsx @@ -23,18 +23,19 @@ const LobyPage: FunctionComponent<{ let navigate = useNavigate(); - useEffect(() => { - listenMessages(); - context.rtmt.sendMessage("new_game", {}); - }, []); - - const listenMessages = () => { - context.rtmt.listenMessage(channel_on_game_start, (message: Object) => { - const newGame: CommonMancalaGame = message as CommonMancalaGame; - navigate(`/game/${newGame.id}`) - }); + const onGameStart = (message: Object) => { + const newGame: CommonMancalaGame = message as CommonMancalaGame; + navigate(`/game/${newGame.id}`) } + useEffect(() => { + context.rtmt.addMessageListener(channel_on_game_start, onGameStart); + context.rtmt.sendMessage("new_game", {}); + return () => { + context.rtmt.removeMessageListener(channel_on_game_start, onGameStart); + } + }, []); + const textColorOnAppBar = getColorByBrightness( context.themeManager.theme.appBarBgColor, context.themeManager.theme.textColor,