2024-03-24 14:23:08 +03:00
|
|
|
import * as React from 'react';
|
|
|
|
|
import { View, Text, Button } from 'react-native';
|
|
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
import { LobyScreenProps } from '../types';
|
2024-03-25 10:04:03 +03:00
|
|
|
import { useEffect } from 'react';
|
|
|
|
|
import { CommonMancalaGame } from 'mancala.js';
|
|
|
|
|
import { channel_on_game_start } from '../const/channel_names';
|
2024-03-24 14:23:08 +03:00
|
|
|
|
|
|
|
|
export default function LobyScreen({ navigation, route }: LobyScreenProps) {
|
2024-03-25 10:04:03 +03:00
|
|
|
|
|
|
|
|
const { context } = route.params;
|
2024-03-24 14:23:08 +03:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
|
2024-03-25 10:04:03 +03:00
|
|
|
const onGameStart = (message: Object) => {
|
|
|
|
|
const newGame: CommonMancalaGame = message as CommonMancalaGame;
|
|
|
|
|
navigation.navigate("Game", { context, gameId: 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);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
|
|
|
|
|
2024-03-24 14:23:08 +03:00
|
|
|
return (
|
|
|
|
|
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
|
2024-03-25 10:04:03 +03:00
|
|
|
<Text>{t('SearchingOpponent')}</Text>
|
2024-03-24 14:23:08 +03:00
|
|
|
</View>
|
|
|
|
|
);
|
|
|
|
|
}
|