Skip to content

Client Reference

On This Page

A complete reference for all functions that can be called for the HighNoon client.


init

async

Initializes a new client instance with the provided options.

const { data, error } = await client.init();

Where the return is in the form of:

data: {
client: string
} | error: string

connectToRoom

async

Connects the client to a room.

const { data, error } = await client.connectToRoom(room);

Where the return is in the form of:

data: {
room: string,
connectedClients: number
} | error: string

getConnectedClients

async

Returns the number of clients connected to the room.

const { data, error } = await client.getConnectedClients();

Where the return is in the form of:

data: {
clients: {
userId: string,
socketId: string,
},
count: number
} | error: string

send

Sends a message to the server using webRTC. This function will call JSON.stringify on the message before sending it. This function does not return anything.

const message = {
type: 'message',
data: 'Hello, World!'
};
client.send(message);

relay

Relayes a message to all clients connected to the room. This function uses the WebSocket connection to send information, so it should be used sparingly to avoid rate limiting. It does not return anything.

const message = {
type: 'message',
data: 'Hello, World!'
};
client.relay(message);

relayTo

Relayes a message to a specific client connected to the room. This function uses the WebSocket connection to send information, so it should be used sparingly to avoid rate limiting. It does not return anything.

const message = {
type: 'message',
data: 'Hello, World!'
};
client.relayTo(socketId, message);

on

listener

The on listener can be used to listen to events emitted by the client. These are listed below, with their respective payloads.

client.on("listener", () =>{})

Events

serverConnectionEstablished

Emitted when the client has successfully connected to the server. This event has no payload.

relayFromClient

Emitted when a message is received from another client in the room.

Payload:

{
meta: {
userId: string,
socketId: string,
roomId: string
},
to?: string,
payload: any
}
relayFromServer

Emitted when a message is received from the server.

Payload:

{
meta: {
roomId: string,
initalized: boolean,
connectedToRoom: boolean
},
to?: string,
payload: any
}
relay

A more generic event that is emitted alongside relayFromClient and relayFromServer. This event is emitted when a message is received from either the server or another client.

Payload:

{
meta: {
userId: string,
socketId: string,
roomId: string
} |
{
roomId: string,
initalized: boolean,
connectedToRoom: boolean
},
to?: string,
payload: any
}
packet

Emitted when a message is received from the WebRTC connection.

Payload:

data: any
ClientListUpdated

This event will fire when a new client joins the server. The server will inform all clients of the update list of clients in the room. It will also differentiate between join and leave events, although it is up to you to handle how to display this information.

Payload:

data: {
clients: {
userId: string,
socketId: string,
}[],
isJoin: boolean,
newClient?: {
userId: string,
socketId: string,
},
removedClient?: {
userId: string,
socketId: string,
},
count: number
}
disconnected

Emitted when the client is disconnected from the server. This event has no payload.