import React from 'react'; import CreateGameForm from './CreateGameForm'; import io from '../io'; const Index = React.createClass({ propTypes: { io: React.PropTypes.object.isRequired }, getInitialState() { return { link: '', hasExpired: false, time: '30', inc: '0' }; }, componentDidMount() { const io = this.props.io; io.on('created', data => { const {time, inc} = this.state; const loc = window.location; const origin = loc.origin || `${loc.protocol}//${loc.hostname}` + (loc.port ? ':' + loc.port : ''); this.setState({ link: `${origin}/play/${data.token}/${time}/${inc}`, hasExpired: false }); }); io.on('ready', () => { window.location = this.state.link; }); io.on('token-expired', () => this.setState({hasExpired: true})); }, render() { return (
{this.state.hasExpired ? 'Game link has expired, generate a new one' :this.state.link ? 'Waiting for opponent to connect' :null}