Build an Interactive Robot

Introduction

Our interactive platform communicates using Google's Protocol Buffer
specification over a standard secure websocket protocol (wss) connection. Viewers' inputs from the site are sent to Mixer's aggregator
server, which analyzes them for you, before being sent to your Robot.

Registering a Game On Mixer

Head over to the Developer Lab and click the 'Interactive Games' tab. Click the plus
button next to 'My Games', and name the game whatever you'd like.
Hit 'Create Game'.

You’re now in the control editor. For our simple robot, we just want to
be able to record joystick input. Click the Joystick Tab on the right
side of the screen and then click 'New'.

Expand the joystick's settings by clicking the arrow on the right of your new joystick and check the 'Coords (Mean)' analysis. Drag the Joystick onto the control grid on the left.

The final result should look like this:

Everything else can be left as default. Click Save. We're finished with the control editor. Let's get started on writing the code!

Writing the Code

We’re going to be using our Node,
Java
and Python to build a simple Robot.
Users will be able to visit your channel on Mixer, and control the mouse
movement on your screen.

We'll be using OAuth for authentication. In the tutorial code below, click "Click here to get your token" to grab a token for the tutorial. You can read more about how OAuth works on our OAuth reference page

To connect to Mixer Interactive we need to authenticate as our user specified above
using beam-client-node we'll use an implicit OAuth token to do this. The required scopes are interactive:robot:self.
Once authenticated we're asking the api to join a channel as a robot with beam.game.join.
We'll use the response from this to create a robot in the next step.

Once we have a robot we need to perform a handshake with the interactive servers and then
hook up event handlers so that a joystick on beam is bound to your mouse.
We do this by creating the performRobotHandShake and setupRobotEvents functions.

This function takes our Robot instance and initiates a handshake, An error will be
reported if a problem occurs during this process. Once its complete you'll get regular
reports from Mixer as a report event on the robot object.

As we've only registered a Joystick control on Mixer we'll only get joystick updates.
These come in an array within the report. As we've selected mean, the mean of all
the viewers joysticks will be contained within the coordMean object. We take this
mean and apply it to the mouse position.
The final code can be found below:

Usage

Let's start by creating a Main class for the Java application and
importing all of the required packages. We'll also initialize a few
objects. A instance of the MixerAPI and an instance of the AWT Robot class
which will allow us to control the mouse.