项目作者: Brinkbit

项目描述 :
Javascript Brinkbit SDK
高级语言: JavaScript
项目地址: git://github.com/Brinkbit/brinkbit.js.git
创建时间: 2017-02-23T16:35:10Z
项目社区:https://github.com/Brinkbit/brinkbit.js

开源协议:MIT License

下载


Brinkbit

fast, extensible, and scalable BaaS platform for game services, content management, live ops, and more

This is the client-side javascript SDK for the Brinkbit Game BaaS.
This repository includes installation instructions and basic examples.
For full API documentation see https://brinkbit.com/docs/.

Contents

Installation

Via npm

  1. $ npm init
  2. $ npm install --save brinkbit.js

Via yarn

  1. $ yarn init
  2. $ yarn add brinkbit.js

Via cdn

Include the following script tag in your html:

  1. <script crossorigin src="https://unpkg.com/brinkbit.js/dist/brinkbit.min.js"></script>

Examples

Import

CommonJS

  1. const Brinkbit = require( 'brinkbit.js' );

ES6

  1. import Brinkbit from 'brinkbit.js';

Initialize

  1. // create a new Brinkbit instance
  2. const brinkbit = new Brinkbit({
  3. gameId: 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx', // your unique game id (can be retrieved from brinkbit control center)
  4. });
  1. // create a new Brinkbit instance using custom proxy
  2. const brinkbit = new Brinkbit({
  3. base: 'https://yourproxydomain.com/api/', // the route of your application on which the server-side sdk is listening
  4. gameId: 'xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx', // your unique game id (can be retrieved from brinkbit control center)
  5. });

Create a New Player

  1. // create a new player
  2. const player = new brinkbit.Player({
  3. username: 'Violet',
  4. email: 'violet@trialbyfireball.com',
  5. password: 'FireballsAreTheWorst',
  6. });
  7. player.save()
  8. .then(() => {
  9. // player has been created on server
  10. });

Login

  1. brinkbit.on( 'login', ( event ) => {
  2. console.log( event.player );
  3. });
  4. // login a player
  5. brinkbit.login({
  6. username: 'Violet', // can also be email
  7. password: 'FireballsAreTheWorst',
  8. })
  9. .then(( player ) => {
  10. // player is an authenticated player object
  11. // You can also access the primary player via Brinkbit.Player.primary
  12. console.log( player.id === Brinkbit.Player.primary.id );
  13. });

Check if Logged In

  1. if ( brinkbit.loggedIn()) {
  2. console.log( 'player is logged in' );
  3. }
  4. else {
  5. console.log( 'player is not logged in' );
  6. }

Logout

  1. brinkbit.logout();
  2. // player is logged out
  3. // alternative
  4. player.logout();

Low Level Requests

  1. brinkbit.get( '/players/12345/' )
  2. .then(( response ) => {
  3. console.log( response );
  4. });
  1. brinkbit.put({
  2. uri: '/players/12345/',
  3. data: {
  4. email: 'violet2@trialbyfireball.com',
  5. },
  6. });

Github
Facebook
Twitter
LinkedIn
Google Plus
Medium