-
Notifications
You must be signed in to change notification settings - Fork 4
API Callbacks
Mathieu edited this page Jun 17, 2015
·
4 revisions
Each data that is received from the server is passed through the .on('type', function(){});
callback.
Called after a successful connection to the Websocket server.
COUCHFRIENDS.on('connect', function() {
console.log('Ready for action!');
});
Game is started and ready for players to connect.
/**
* Callback after the server started the game and let players allow to join.
*
* @param {object} data List with game data
* @param {string} data.code The game code players need to fill to join this game
*/
COUCHFRIENDS.on('gameStart', function(data) {
console.log('Game started with code: '+ data.code);
});
A new player joined the game.
/**
* Callback when a player connected to the game.
*
* @param {object} data list with the player information
* @param {int} data.id The unique identifier of the player
* @param {string} [data.name] The name of the player
*/
COUCHFRIENDS.on('playerJoined', function(data) {
console.log('Player joined. Player id: ' + data.id);
});
One of the players disconnected or left the game.
/**
* Callback when a player disconnect from the game.
*
* @param {object} data list with the player information
* @param {int} data.id the unique identifier of the player that left
*/
COUCHFRIENDS.on('playerLeft', function(data) {
console.log('Player left. Player id: ' + data.id);
});
A player's device orientation has changed.
/**
* Callback when a player chances the orientation of his device. Useful for movement tracking.
*
* For performance reasons this function will only be called if the orientation has changed since the previous frame.
*
* @param {object} data list with the player id and orientation
* @param {int} data.id The unique identifier of the player
* @param {float} [data.x] The x-as orientation (-1 to 1). E.g. -0.871
* @param {float} [data.y] The y-as orientation (-1 to 1). E.g. 0.12
* @param {float} [data.z] The z-as orientation (-1 to 1). E.g. -0.301
*/
COUCHFRIENDS.on('playerOrientation', function(data) {
console.log('Player orientation changed. Player id: ' + data.id + ' Orientation: ' + data.x + ', ' + data.y + ', ' + data.z);
});
A player's tapped/clicked on his device.
/**
* Callback when a player tapped canvas up and down
*
* @param {object} data list with the player information
* @param {int} data.id The unique identifier of the player
* @param {float} data.x Left position clicked in percentage
* @param {float} data.y Top position clicked in percentage
*/
COUCHFRIENDS.on('playerClick', function(data) {
//console.log('Player clicked. Player id: ' + data.id + ' Click position: ' + data.x + ', ' + data.y);
});
A player is holding down or touching the screen. This event is fired once until the playerClickUp event is fired.
/**
* Callback when a player is holding down its finger or mouse button on the screen
*
* @param {object} data list with the player information
* @param {int} data.id The unique identifier of the player
* @param {float} data.x Left position clicked in percentage
* @param {float} data.y Top position clicked in percentage
*/
COUCHFRIENDS.on('playerClickDown', function(data) {
//console.log('Player holding down on the screen. Player id: ' + data.id + ' Down position: ' + data.x + ', ' + data.y);
});
A player is holding down or touching the screen. This event is fired once until the playerClickUp event is fired.
/**
* Callback when a player is removing its finger from the screen. Is only fired once after the playerCLickDown event.
*
* @param {object} data list with the player information
* @param {int} data.id The unique identifier of the player
* @param {float} data.x Left position clicked in percentage
* @param {float} data.y Top position clicked in percentage
*/
COUCHFRIENDS.on('playerClickUp', function(data) {
//console.log('Player holding down on the screen. Player id: ' + data.id + ' Up position: ' + data.x + ', ' + data.y);
});
/**
* Callback when a player changed its name or added additional information like selected color.
*
* @param {object} data list with the player information
* @param {int} data.id The unique identifier of the player
* @param {float} [data.name] The (new) name of the player. See http://couchfriends.com/pages/profile.html for possible
* names and characters that might be included in the name.
*/
COUCHFRIENDS.on('playerIdentify', function(data) {
//console.log('Player with id: '+ data.id +' changed its name to: ' + data.name);
});
/**
* Callback when a player tapped a button
*
* @param {object} data list with the player and button information
* @param {int} data.id The unique identifier of the button
* @param {int} data.playerId The unique identifier of the player
*/
COUCHFRIENDS.on('buttonClick', function(data) {
//console.log('Player clicked a button. Player id: ' + data.playerId + ' Button id: ' + data.id);
});