1.2.1 • Published 1 year ago

bondz.io v1.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Bondzio

An npm package for interfacing with Bondzio ecosystem

Installation

To install bondz.io, run: npm i bondz.io

To use it in your application:

import Bondzio from 'bondz.io'

Usage

Methods

Top level element of the package, provides all the neccessary methods for interfacing with Bondzio system:

class Bondzio

Delete room with roomId from the database:

async function Bondzio.delete(roomId: string)

Check whether room with roomId exists in the database:

async function Bondzio.check(roomId: string): Promise<boolean>

Perform operation specified by food and return Room:

async function Bondzio.eat(food: BondzioFood): Promise<Room>   
throws {
    BondzioServerError,
    
}

Return current state of Bondzio object:

function Bondzio.state(): BondzioStatus

Return the nickname of currently connected player

function owner() : String

Connect to the websocket server as nickname

function connect(nickname: string)

Setup custom callbacks to be execcuted on ws events

function socketSetup(callbacks: BondzioSocketCallbacks)

Send a chat message to the room

function sendMessage(message: string)

Send coordinates from drawing to the room

function sendDraw(coords: DrawCoords)

Send the player's guess

function guess(word: string)

Get a new clue to be guessed based on category. Only to be called by the new drawing player

function getNewWord(category: string)

Types

interface Room {
    roomId: string,
    password: string,
    roomKey: string
}

An object containing information about the room bound to the Bondzio instance

interface BondzioStatus {
    roomId: string,
    password: string,
    roomKey: string,
    isValid: boolean
}

An object containing information about the state of Bondzio instance with a isValid flag indicating whether there is currently an async operation altering the state of the instance

interface BondzioFood {
    roomName: string,
    password: string,
    action: BondzioAction
}

An object containing parameters for Bondzio.food() method

enum BondzioAction{
    Login = 0,
    Register = 1,
}

An enum representing complex actions that can be scheduled for Bondzio to perform

interface BondzioSocketCallbacks {
    onConnect: (connectMessage: string) => void,
    onRoomConfirm: (confirmMessage: string) => void,
    onChatMessage: (chatMessage: Message) => void,
    onDraw: (coords: DrawData) => void,
    onCorrectGuess: () => void,
    onOpponentGuess: (opponent: string) => void,
    onNewWord: (word: string) => void
}

An object used for assigning custom callbacks to be executed on websocket events

interface DrawData {
    prevX: number,
    prevY: number,
    x: number,
    y: number,
    color: String,
    strokeSize: number
}

An object representing information about drawing

Errors

class BondzioServerNotFoundError extends Error {}

An error indicating that Bondzio could no establish connection to the server

class BondzioWrongPasswordError extends Error {}

An error indicating that user submitted wrong password while logging in

class BondzioRoomNotFoundError extends Error {}

An error indicating that user submitted wrong roomId while logging in

class BondzioServerError extends Error {}

An error indicating that internal server error occured

class BondzioRoomAlreadyExistsError extends Error {}

An error indicating that registered room already exists

class BondzioSocketError extends Error {}

An error indicating that an internal callback error occured or no callback has been provided

Collaborate

You can collaborate on this project by cloning the repository and running:

npm i

and

npm run dev

to run the package in development mode

Warning

The package utilizes fetch API, which requires node >= 18.0.0 to run

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.3

1 year ago

1.2.1

1 year ago

1.1.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago