@gamefast/ching-sdk

1.0.1 • Public • Published

Client Usage Examle

import Client from '@gamefast/ching-sdk';

const client = new Client({
    host: '127.0.0.1',
    port: 3001,
    secure: false
});

/** Player */
/**
 * @param data Object
 * {
 *   status: Boolean,
 *   room: {
 *     players: [
 *          { id: id1, name: String, avatar: String, ....? },
 *     ],
 *     bet: Number,
 *     type: String,
 *     id: String,
 *     timer: Number
 *   }
 *
 * }
 * */


client.onPlayerSubscribe(data => {
    console.log('======SUBSCRIBE========')
    console.log(data);
    console.log('=======================');
    client.ready(true);
});

/**
 *
 * @param timer Number
 *
 * */


/** Room */
client.onGameStart((data) => {
    console.log("===========Game Start============");
    console.log(data)
});

/**
 *
 * @param winnerId? String
 * @param draw? Boolean
 * /..YOUR_API_RESPONSE_DATA../
 * */

client.onGameFinish(data => {
    console.log("===========Game Finish============");
    console.log(data)
});

/**
 *
 * @param player
 * {
 *  id: String
 * }
 *
 * */

client.onPlayerLeave(player => {
    console.log('===========ROOM PLAYER LEAVE========');
    console.log(player);
});

/**
 *
 * @param player
 * {
 *  id: String,
 *  status: Boolean
 * }
 *
 * */
client.onPlayerReady(console.log);

/**
 * @param status Boolean
 */

client.onPlayerJoinRoom(({ status }) => {
    console.log('============PLAYER JOIN ROOM==========');
    console.log(status);
});

/**
 * @description If both players skipped their turns, e.g. timer expired
 */

client.onMatchFinish(() => {
    console.log('============ROOM MATCH FINISH==========');
});

//** Socket Events
client.onConnect(() => console.log('SocketCluster onConnect'));
client.onDisconnect(() => console.log('SocketCluster onDisconnect'));

Readme

Keywords

none

Package Sidebar

Install

npm i @gamefast/ching-sdk

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

307 kB

Total Files

10

Last publish

Collaborators

  • varik77
  • artakvg