update for event emitter rtmt

This commit is contained in:
Halit Aksoy 2022-09-02 00:03:17 +03:00
parent 23d2edb23e
commit 51d541b5e7

View File

@ -23,18 +23,19 @@ const LobyPage: FunctionComponent<{
let navigate = useNavigate(); let navigate = useNavigate();
useEffect(() => { const onGameStart = (message: Object) => {
listenMessages(); const newGame: CommonMancalaGame = message as CommonMancalaGame;
context.rtmt.sendMessage("new_game", {}); navigate(`/game/${newGame.id}`)
}, []);
const listenMessages = () => {
context.rtmt.listenMessage(channel_on_game_start, (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( const textColorOnAppBar = getColorByBrightness(
context.themeManager.theme.appBarBgColor, context.themeManager.theme.appBarBgColor,
context.themeManager.theme.textColor, context.themeManager.theme.textColor,