/**
 * This example is for custom bundles. In this script, this assumes
 * that your bundle will giveInput on a control with the controlID "setup",
 * with the event being "create", that passes a property controls that is
 * and array of strings.
 *
 * These controls will have a kind of generic, as we don't actually care
 * what they are, as the event will be broadcasted back to everyone, where
 * the bundle will handle these events.
 *
 * Example:
 *     mixer.socket.call('giveInput', {
 *      controlID: 'setup',
 *      event: 'create',
 *      controls: ['btn-one', 'hello-world'],
 *    });
 *
 */ import * as WebSocket from 'ws' ; import { GameClient , IControl , IControlData , IInputEvent , IParticipant , setWebSocket , } from '../lib' ; 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 : [ { controlID : 'setup' , kind : 'generic' , } , ] , } ) . then ( ( ) => client . synchronizeState ( ) ) . then ( ( ) => client . ready ( true ) ) . then ( ( ) => client . state . getControl ( 'setup' ) ) . then ( ( control ) => { return new Promise ( ( resolve , reject ) => { control . once ( 'create' , ( event , _participant ) => { const controls = [ ] ; if ( event . input . controls ) { event . input . controls . forEach ( id => { controls . push ( { controlID : id , kind : 'generic' , } ) ; } ) ; } client . createControls ( { sceneID : 'default' , controls , } ) . then ( ( ) => resolve ( ) ) . catch ( ( _err ) => reject ( ) ) ; } ) ; } ) ; } ) ; } ) ; 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` ) ; } ) ; client . on ( 'message' , ( str ) => { const blob = JSON . parse ( str ) ; if ( blob . type === 'method' && blob . method === 'giveInput' && blob . params . input . controlID !== 'setup' ) { broadcast ( blob ) ; } } ) ; function broadcast ( params ) { client . broadcastEvent ( { scope : [ 'everyone' ] , data : params , } ) ; }