Skip to content

Client API

Josh Feinsilber edited this page Jul 29, 2019 · 4 revisions

To start connecting to a Blueboat server, you will want to create a client. To make a client, you will only need the address where the server is located.

import { Client } from 'blueboat-client'
const client = new Client('wss://blueboat-games.com')

Client Events

All client events use callback listeners. You can add as many callbacks as you like to these events

onConnect

Called when the client successfully connects to the game server

const client = new Client('wss://blueboat-games.com')
client.onConnect.add(() => console.log('Connected!'))

onConnectError

Called when there is an error connecting to the server. Will pass in the error from socket.io

client.onConnectError.add(e => console.log('Error connecting', e))

onDisconnect

Called when the client is disconnected from the game server

client.onDisconnect.add(() => console.log('Disconnected!'))

You can clear the listeners from any event by running event.clear() -- for example: client.onConnectError.clear()

Client Methods

A client can create or join a room, it's up to you!

createRoom

This method creates a new room! It takes two parameters:

key type required
roomName string true
options Object false

Example

const gameRoom = client.createRoom('TriviaRoom', {hostAuthenticationKey: 'xxxxxx'})

This method returns a Room


joinRoom

This method joins a room! It takes two parameters:

key type required
roomId string true
options Object false

Example

const gameRoom = client.joinRoom('HdFGWWbgUOw')

This method returns a Room

Client Values

id

Unique client ID -- remains the same across game sessions if using the same device & browser

sessionId

Unique ID for this current game session -- changes on refresh or reconnect

Clone this wiki locally