Example: Connectivity

Plug and unplug your gamepad(s) and see the changes below:

Waiting...

In some browsers, you may need to press a button after plugging in the gamepad.

How it works

There are two event associated to gameControl that you can use:

And an event handler can be easily associated to any of them using the .on() method:

gameControl.on(EVENT_NAME, CALLBACK);

As an example, here is the code that manages the interaction above:

gameControl.on('connect', function() {
  document.querySelector('#round-button').className = 'connected';
  document.querySelector('#status').textContent = 'Device connected!';
});

gameControl.on('disconnect', function() {
  document.querySelector('#round-button').className = 'disconnected';
  document.querySelector('#status').textContent = 'Device disconnected!';
});