'use strict'; import React from 'react'; import CreateGameForm from './CreateGameForm'; import io from '../io'; const Index = React.createClass({ propTypes: { io: React.PropTypes.object }, getInitialState() { return { link: '', hasExpired: false, time: '30', inc: '0' }; }, componentDidMount() { const io = this.props.io; io.on('created', data => { const {time, inc} = this.state; this.setState({ link: `${document.location.origin}/play/${data.token}/${time}/${inc}` }); }); io.on('ready', () => { window.location = this.state.link; }); io.on('token-expired', () => this.setState({hasExpired: true})); }, render() { return (
A lightweight real-time chess app build in Node, Express, Socket.IO, React, Flux and Immutable.
{this.state.link ? 'Waiting for opponent to connect' :this.state.hasExpired ? 'Game link has expired, generate a new one' :null}
Click the button to create a game. Send the link to your friend. Once the link is opened your friend‘s browser, game should begin shortly. Colors are picked randomly by computer.