[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/client](https://jsprismarine.dev/api/@jsprismarine/client/index.md) / SubClient

# Class: SubClient

Defined in: [client/src/SubClient.ts:59](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L59)

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](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L70)

#### Parameters

##### session

[`ClientSession`](https://jsprismarine.dev/api/@jsprismarine/client/classes/ClientSession.md)

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

##### options

[`SubClientOptions`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#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](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L83)

The id the player's packets are stamped with.

##### Returns

`number`

## Methods

### connect()

> **connect**(): `Promise`\<[`StartGame`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#startgame)\>

Defined in: [client/src/SubClient.ts:97](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L97)

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

#### Returns

`Promise`\<[`StartGame`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#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](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L173)

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`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#startgame) \| `null`

Defined in: [client/src/SubClient.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L88)

Null until the server has spawned the player.

#### Returns

[`StartGame`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#startgame) \| `null`

***

### send()

> **send**(`packet`): `Promise`\<`void`\>

Defined in: [client/src/SubClient.ts:164](https://github.com/JSPrismarine/JSPrismarine/blob/5e63e9419d81262a4d009cacfb60d845d68658cf/packages/client/src/SubClient.ts#L164)

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

#### Parameters

##### packet

[`NetworkPacket`](https://jsprismarine.dev/api/@jsprismarine/protocol/classes/NetworkPacket.md)\<`any`\>

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

#### Returns

`Promise`\<`void`\>
