update for event emitter rtmt
This commit is contained in:
parent
23d2edb23e
commit
51d541b5e7
@ -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,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user