import * as WebSocket from 'ws' ; import * as faker from 'faker' ; import { GameClient , IControlData , IParticipant , setWebSocket , } from '../lib' ; import { makeControls , updateControls } from './util' ; if ( process . argv . length < 4 ) { console . log ( 'Usage gameClient.exe <token> <versionId>' ) ; process . exit ( ) ; } setWebSocket ( WebSocket ) ; const client = new GameClient ( ) ; const delayTime = 1000 ; let controls = [ ] ; function loop ( ) { const scene = client . state . getScene ( 'default' ) ; scene . updateControls ( updateControls ( controls , ( ) => faker . name . firstName ( ) ) ) ; } let loopInterval ; client . on ( 'open' , ( ) => { console . log ( 'Connected to Interactive!' ) ; clearInterval ( loopInterval ) ; client . synchronizeState ( ) . then ( ( ) => { const scene = client . state . getScene ( 'default' ) ; scene . deleteAllControls ( ) ; controls = makeControls ( 8 , ( ) => faker . name . firstName ( ) ) ; scene . createControls ( controls ) ; } ) . then ( ( ) => client . ready ( true ) ) . then ( ( ) => { loopInterval = setInterval ( loop , delayTime ) ; } ) ; } ) ; client . open ( { authToken : process . argv [ 2 ] , versionId : parseInt ( process . argv [ 3 ] , 10 ) , } ) ; client . state . on ( 'participantJoin' , ( participant ) => { console . log ( `${ participant . username }(${ participant . sessionID }) Joined` ) ; } ) ; client . state . on ( 'participantLeave' , ( participantSessionID , participant ) => { console . log ( `${ participant . username }(${ participantSessionID }) Left` ) ; } ) ;