With the Couchfriends Controller API you can connect your phone or tablet to your HTML5 game and use it as a controller. The Controller API uses Websockets to send and receive input.

Quick setup

Add the following code in the <head> of your game.

<script src="http://cdn.couchfriends.com/api/couchfriends.api-latest.js"></script>

Connect to the Couchfriends services.


Start a game and allow players to join after connecting.

COUCHFRIENDS.on('connect', function() {
    var jsonData = {
        topic: 'game',
        action: 'host'

Add and remove players from your game when they connect/disconnect.

COUCHFRIENDS.on('playerJoined', function(data) {
    console.log('Player joined. Player id: ' + data.id);
COUCHFRIENDS.on('playerLeft', function(data) {
    console.log('Player left. Player id: ' + data.id);

Move players around in your game depending on they device orientation.

COUCHFRIENDS.on('playerOrientation', function(data) {
    console.log('Player orientation changed. Player id: ' + data.id + ' Orientation: ' + data.x + ', ' + data.y);

Add interaction with buttons.

COUCHFRIENDS.on('buttonUp', function(data) {
    console.log('Player pressed button. Player id: ' + data.playerId + ', button: ' + data.id);

Further read

Complete list with API references and callbacks in our wiki.