Skip to content

API reference / @jsprismarine/client / SubClient

Class: SubClient ​

Defined in: client/src/SubClient.ts:59

A split screen player: a second, third or fourth local player sharing a client's connection, as a console adds one.

It logs in with SubClientLoginPacket once the connection's own player is in, and from then on every packet it sends carries its sub-client id in the header's target bits. The server's packets for it carry the id in the sender bits, and reach its packet event instead of the client's. The join has no handshake and no resource pack exchange: the server follows PlayStatus(LoginSuccess) with StartGame, as protocols 2193, 2225 and 2259's pinned servers do.

Example ​

typescript
const client = new Client({ host: '127.0.0.1', displayName: 'Steve' });
await client.connect();
const alex = client.subClient({ subClientId: 1, displayName: 'Alex' });
await alex.connect();

Extends ​

  • EventEmitter

Constructors ​

Constructor ​

new SubClient(session, options): SubClient

Defined in: client/src/SubClient.ts:70

Parameters ​

session ​

ClientSession

The primary connection's session, which the player's packets travel on.

options ​

SubClientOptions

Who the player is and what its login reports.

Returns ​

SubClient

Throws ​

Error when the sub-client id is not 1, 2 or 3.

Overrides ​

EventEmitter.constructor

Accessors ​

subClientId ​

Get Signature ​

get subClientId(): number

Defined in: client/src/SubClient.ts:83

The id the player's packets are stamped with.

Returns ​

number

Methods ​

connect() ​

connect(): Promise<StartGame>

Defined in: client/src/SubClient.ts:97

Logs the player in and resolves once the server has spawned it.

Returns ​

Promise<StartGame>

The StartGame the server described the player's world with.

Throws ​

Error when the server refuses or disconnects the player, or the join times out.


disconnect() ​

disconnect(): Promise<void>

Defined in: client/src/SubClient.ts:173

Takes the player out of the game, as a console does when the player leaves split screen. The primary's connection stays open.

Returns ​

Promise<void>


getStartGame() ​

getStartGame(): StartGame | null

Defined in: client/src/SubClient.ts:88

Null until the server has spawned the player.

Returns ​

StartGame | null


send() ​

send(packet): Promise<void>

Defined in: client/src/SubClient.ts:164

Sends a packet as this player: stamped with its sub-client id, on the primary's connection.

Parameters ​

packet ​

NetworkPacket<any>

A packet carrying its typed payload, or a field packet with its fields set.

Returns ​

Promise<void>