[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / chat/ChatManager

# chat/ChatManager

## Classes

- [ChatManager](https://jsprismarine.dev/api/@jsprismarine/prismarine/chat/ChatManager/classes/ChatManager.md)

## Interfaces

### ChatDelivery

Defined in: [packages/prismarine/src/chat/ChatManager.ts:13](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L13)

One chat line as a player's client receives it.

#### Properties

##### kind

> `readonly` **kind**: [`MessageKind`](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/presenter/SessionPresenter/index.md#messagekind)

Defined in: [packages/prismarine/src/chat/ChatManager.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L15)

##### message

> `readonly` **message**: `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:14](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L14)

##### needsTranslation

> `readonly` **needsTranslation**: `boolean`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L17)

##### parameters

> `readonly` **parameters**: `string`[]

Defined in: [packages/prismarine/src/chat/ChatManager.ts:16](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L16)

##### sender?

> `readonly` `optional` **sender?**: [`ShownChatSender`](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/presenter/SessionPresenter/index.md#shownchatsender)

Defined in: [packages/prismarine/src/chat/ChatManager.ts:23](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L23)

The author's UUID and signature, for a player's own chat only.

##### sourceName?

> `readonly` `optional` **sourceName?**: `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:19](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L19)

The author's name, for a player's own chat only.

##### xuid?

> `readonly` `optional` **xuid?**: `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L21)

The author's XUID, for a player's own chat only, and empty without one.

***

### ChatRecipient

Defined in: [packages/prismarine/src/chat/ChatManager.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L32)

A connected player as the chat fan-out sees one: who they are and where their lines go.

The name and the operator check are read when a message arrives rather than when the player
joins, so a name or an operator grant that changes in between is the one that counts.

#### Properties

##### key

> `readonly` **key**: `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L34)

The player's key; see `keyOfPlayer`.

#### Methods

##### getName()

> **getName**(): `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L36)

The name a `*.player.<name>` channel addresses.

###### Returns

`string`

##### isOp()

> **isOp**(): `boolean`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L38)

Whether the `*.ops` channel reaches this player.

###### Returns

`boolean`

##### receive()

> **receive**(`delivery`): `Promise`\<`void`\>

Defined in: [packages/prismarine/src/chat/ChatManager.ts:40](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L40)

Sends one line to the player's client.

###### Parameters

###### delivery

[`ChatDelivery`](#chatdelivery)

###### Returns

`Promise`\<`void`\>

***

### ChatRecipientServer

Defined in: [packages/prismarine/src/chat/ChatManager.ts:50](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L50)

What a recipient built by [chatRecipientOf](#chatrecipientof) reads of the server.

#### Methods

##### getPermissionManager()

> **getPermissionManager**(): `object`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:52](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L52)

###### Returns

`object`

###### isOp()

> **isOp**(`subject`): `boolean`

###### Parameters

###### subject

[`Subject`](https://jsprismarine.dev/api/@jsprismarine/prismarine/identity/Subject/index.md#subject)

###### Returns

`boolean`

##### getSessionManager()

> **getSessionManager**(): [`ChatSessions`](#chatsessions)

Defined in: [packages/prismarine/src/chat/ChatManager.ts:51](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L51)

###### Returns

[`ChatSessions`](#chatsessions)

***

### ChatSessions

Defined in: [packages/prismarine/src/chat/ChatManager.ts:44](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L44)

The session registry, as a recipient finds its player's client in it.

#### Methods

##### sessionOf()

> **sessionOf**(`id`): \{ `sendMessage`(`delivery`): `Promise`\<`void`\>; \} \| `null`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:46](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L46)

The client of the online player with this entity id, or null when no online player has it.

###### Parameters

###### id

`bigint`

###### Returns

\{ `sendMessage`(`delivery`): `Promise`\<`void`\>; \} \| `null`

***

### PlayerChatIntent

Defined in: [packages/prismarine/src/chat/ChatManager.ts:82](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L82)

A line a player typed, as the chat action's guard stage sees it.

#### Properties

##### message

> `readonly` **message**: `string`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:85](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L85)

##### sender

> `readonly` **sender**: `bigint`

Defined in: [packages/prismarine/src/chat/ChatManager.ts:84](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L84)

The entity id of the player who typed it.

## Type Aliases

### ChatBus

> **ChatBus** = `Pick`\<[`ServerEventBus`](https://jsprismarine.dev/api/@jsprismarine/prismarine/events/ServerEvents/index.md#servereventbus), `"post"`\>

Defined in: [packages/prismarine/src/chat/ChatManager.ts:79](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L79)

The part of the server's event bus chat uses.

***

### PlayerChatGuard

> **PlayerChatGuard** = (`intent`) => \{ `veto`: `true`; \} \| \{ `intent`: [`PlayerChatIntent`](#playerchatintent); `veto`: `false`; \}

Defined in: [packages/prismarine/src/chat/ChatManager.ts:92](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L92)

A guard in the chat action's guard stage ([ADR 0013](https://jsprismarine.dev/adr/0013-vetoable-actions-are-staged.md)).
It reads the line, writes nothing, and lets it through or vetoes it.

#### Parameters

##### intent

[`PlayerChatIntent`](#playerchatintent)

#### Returns

\{ `veto`: `true`; \} \| \{ `intent`: [`PlayerChatIntent`](#playerchatintent); `veto`: `false`; \}

## Functions

### chatRecipientOf()

> **chatRecipientOf**(`player`, `server`): [`ChatRecipient`](#chatrecipient)

Defined in: [packages/prismarine/src/chat/ChatManager.ts:68](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/chat/ChatManager.ts#L68)

A connected player as the chat fan-out reaches them, built from who they are.

The key and the name come from the identity and the operator check from the permission list.
Each line goes to the session the registry finds under the player's entity id, so the
recipient holds neither the player nor its client, and a line for a player who has left
reaches nobody.

#### Parameters

##### player

The player's entity id and identity, as its session holds them.

###### identity

[`PlayerIdentity`](https://jsprismarine.dev/api/@jsprismarine/prismarine/playerIdentity/index.md#playeridentity)

The name, XUID and UUID the login named.

###### runtimeId

`bigint`

The entity id the registry finds the session by.

##### server

[`ChatRecipientServer`](#chatrecipientserver)

The session registry and the permission list.

#### Returns

[`ChatRecipient`](#chatrecipient)

The recipient, to join once and leave with.
