import * as WebSocket from 'ws' ; import { GameClient , IButton , IParticipant , setWebSocket , } from '../lib' ; import { makeControls } from './util' ; if ( process . argv . length < 4 ) { console . log ( 'Usage gameClient.exe <token> <versionId>' ) ; process . exit ( ) ; } setWebSocket ( WebSocket ) ; const client = new GameClient ( ) ; client . on ( 'open' , ( ) => { console . log ( 'Connected to Interactive!' ) ; client . createControls ( { sceneID : 'default' , controls : makeControls ( 5 , i => `Button ${ i }` ) , } ) . then ( controls => { controls . forEach ( ( control ) => { control . on ( 'mousedown' , ( inputEvent , participant ) => { console . log ( `${ participant . username } pushed, ${ inputEvent . input . controlID }` ) ; if ( inputEvent . transactionID ) { client . captureTransaction ( inputEvent . transactionID ) . then ( ( ) => { console . log ( `Charged ${ participant . username } ${ control . cost } sparks!` ) ; } ) ; } } ) ; } ) ; return client . ready ( true ) ; } ) ; } ) ; 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` ) ; } ) ;