From 51d541b5e7c77f6a7b2c670397351616a8ec57db Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Fri, 2 Sep 2022 00:03:17 +0300 Subject: [PATCH] update for event emitter rtmt --- src/routes/LobyPage.tsx | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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,