import * as WebSocket from 'ws' ; import { GameClient , IParticipant , ITextbox , ITextboxData , setWebSocket , } from '../lib' ; if ( process . argv . length < 4 ) { console . log ( 'Usage gameClient.exe <token> <versionId>' ) ; process . exit ( ) ; } setWebSocket ( WebSocket ) ; const client = new GameClient ( ) ; const txtChange = { kind : 'textbox' , controlID : 'txtChange' , placeholder : 'Text sends on change!' , position : [ { size : 'large' , width : 30 , height : 4 , x : 2 , y : 1 , } , { size : 'medium' , width : 15 , height : 4 , x : 1 , y : 0 , } , { size : 'small' , width : 15 , height : 4 , x : 1 , y : 0 , } , ] , } ; const txtSubmit = { kind : 'textbox' , controlID : 'txtSubmit' , placeholder : 'Text sends on submit!' , hasSubmit : true , position : [ { size : 'large' , width : 30 , height : 4 , x : 2 , y : 5 , } , { size : 'medium' , width : 15 , height : 4 , x : 0 , y : 4 , } , { size : 'small' , width : 15 , height : 4 , x : 0 , y : 4 , } , ] , } ; const txtCost = { kind : 'textbox' , controlID : 'txtCost' , placeholder : 'Forced Submit because cost!' , cost : 200 , position : [ { size : 'large' , width : 30 , height : 4 , x : 2 , y : 9 , } , { size : 'medium' , width : 15 , height : 4 , x : 0 , y : 8 , } , { size : 'small' , width : 15 , height : 4 , x : 0 , y : 8 , } , ] , } ; client . on ( 'open' , ( ) => { console . log ( 'Connected to Interactive!' ) ; client . createControls ( { sceneID : 'default' , controls : [ txtChange , txtSubmit , txtCost ] , } ) . then ( controls => { controls . forEach ( ( control ) => { control . on ( 'change' , ( inputEvent , participant ) => { console . log ( `${ participant . username } changed ${ inputEvent . input . controlID } with the value: ${ inputEvent . input . value }` ) ; if ( inputEvent . transactionID ) { client . captureTransaction ( inputEvent . transactionID ) . then ( ( ) => { console . log ( `Charged ${ participant . username } ${ control . cost } sparks!` ) ; } ) ; } } ) ; control . on ( 'submit' , ( inputEvent , participant ) => { console . log ( `${ participant . username } submit ${ inputEvent . input . controlID } with the value: ${ inputEvent . input . value }` ) ; if ( inputEvent . transactionID ) { client . captureTransaction ( inputEvent . transactionID ) . then ( ( ) => { console . log ( `Charged ${ participant . username } ${ control . cost } sparks!` ) ; } ) ; } } ) ; } ) ; client . ready ( true ) ; } ) ; } ) ; client . on ( 'message' , ( err ) => console . log ( '<<<' , err ) ) ; client . on ( 'send' , ( err ) => console . log ( '>>>' , err ) ) ; 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` ) ; } ) ;