import * as React from 'react'; import { View, Text, Button, Pressable } from 'react-native'; import { useTranslation } from 'react-i18next'; import { LobyScreenProps } from '../types'; import { useEffect } from 'react'; import { CommonMancalaGame } from 'mancala.js'; import { channel_cancel_new_game, channel_on_game_start } from '../const/channel_names'; import CircularPanel from '../components/CircularPanel'; export default function LobyScreen({ navigation, route }: LobyScreenProps) { const { context } = route.params; const { t } = useTranslation(); const onGameStart = async (message: Object) => { const newGame: CommonMancalaGame = message as CommonMancalaGame; const userKey = await context.userKeyStore.getUserKey(); navigation.replace("Game", { context, gameId: newGame.id, userKey }) } const onCancelNewGameClick = () => { if (context.rtmt.connectionState === "connected") { context.rtmt.sendMessage(channel_cancel_new_game, ""); } navigation.replace("Home", { context }) } useEffect(() => { context.rtmt.addMessageListener(channel_on_game_start, onGameStart); context.rtmt.sendMessage("new_game", {}); return () => { context.rtmt.removeMessageListener(channel_on_game_start, onGameStart); } }, []); return ( {t('SearchingOpponent') + " " + t('PleaseWait') + "..."}} /> {t('Cancel')}} /> ); }