-
Notifications
You must be signed in to change notification settings - Fork 4
Client API
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')
All client events use callback listeners. You can add as many callbacks as you like to these events
Called when the client successfully connects to the game server
const client = new Client('wss://blueboat-games.com')
client.onConnect.add(() => console.log('Connected!'))
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))
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()
A client can create or join a room, it's up to you!
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
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
Unique client ID -- remains the same across game sessions if using the same device & browser
Unique ID for this current game session -- changes on refresh or reconnect