Play with friends using WebRTC peer-to-peer connection
How to Play (P2P Connection):
Player 1: Click "Create Game" → Copy the invitation code
Player 2: Click "Join Game" → Paste invitation → You'll get an ANSWER code
Player 2: Copy the answer code and send it to Player 1
Player 1: Click "Complete Connection" → Paste the answer code
Both players should now be connected! Start playing and chatting.
Initializing...
0 peers
Connection
Connected Players:
No players connected
Game Board
Waiting for connection...
💬 Chat with Your Opponent
0
`;
}
// Handle page visibility changes (pause game when tab is hidden)
document.addEventListener('visibilitychange', () => {
if (document.hidden) {
console.log('[TicTacToe Page] Page hidden, pausing game');
} else {
console.log('[TicTacToe Page] Page visible, resuming game');
}
});
// Handle beforeunload (warn about leaving active game)
window.addEventListener('beforeunload', (event) => {
// Check if there's an active game
const gameContainer = document.getElementById('tic-tac-toe-container');
const roomControls = gameContainer?.querySelector('#room-controls');
if (roomControls && roomControls.style.display !== 'none') {
event.preventDefault();
event.returnValue = 'You have an active game. Are you sure you want to leave?';
return event.returnValue;
}
});