# RelayPublisher

URL: https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaypublisher/

Defined in: [relay-sdks/ts/src/publish.ts:196](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L196)

A connection that can only publish, serving one namespace. Create one with
[connectRelayPublisher](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/functions/connectrelaypublisher/). Subscribing uses a separate connection; see `connectRelaySubscriber`.

## Properties

### announced

```ts
readonly announced: Promise<void>;
```

Defined in: [relay-sdks/ts/src/publish.ts:215](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L215)

Settles once the namespace announce has reached the wire on a solicitation that covers it,
which is no earlier than the first registered track. It is the strongest fact the publisher
has: the relay acknowledges an announce with nothing and routes subscribes for the namespace
about a round trip later, so a subscribe that races it is rejected (request error 16
`unroutable` on moq-relay 0.15.8 and later; see spec/behavior.md). It stays pending while no
solicitation covers the namespace, where the first write reports `NAMESPACE_NOT_SOLICITED`, and
the connection's closure terminates it if that comes first: the closure's error, or a `CLOSED`
RelayError after a clean shutdown. Pre-handled, so nobody has to await it.

***

### closed

```ts
readonly closed: Promise<{
  error?: unknown;
}>;
```

Defined in: [relay-sdks/ts/src/publish.ts:217](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L217)

Ends when the connection shuts down. Errors are returned as data; this never rejects.

***

### expiresAt

```ts
readonly expiresAt: Date | undefined;
```

Defined in: [relay-sdks/ts/src/publish.ts:226](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L226)

When the relay will end this connection for its credential's expiry: the `RelayCredential`'s `expiresAt`, or the
JWT's `exp` claim, read without verifying it. `undefined` when neither is known. The relay closes the session then
with `UNAUTHORIZED` in phase `connection`; open a replacement before it. Supervised connections do.

## Methods

### close()

```ts
close(): Promise<void>;
```

Defined in: [relay-sdks/ts/src/publish.ts:232](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L232)

End all tracks, retract the namespace, and wait for transport shutdown. First waits, for up to
the largest writeTimeoutMs among the tracks, for completed groups the relay has not yet
acknowledged; any still unacknowledged after that may be lost. Idempotent.

#### Returns

`Promise`\<`void`\>

***

### registerTrack()

```ts
registerTrack(options): RelayTrackWriter;
```

Defined in: [relay-sdks/ts/src/publish.ts:204](https://github.com/caprids/relay-sdks/blob/main/ts/src/publish.ts#L204)

Register a track this publisher will serve and return its writer. Nothing is sent: the relay
learns of the track when a subscriber asks for it, and bytes move when the writer's `write()`
or `openGroup()` runs, after waiting for that relay demand. No capture starts and no media
catalog is published. Track names are unique per publisher connection, including after their
writer closes.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`RegisterTrackOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/registertrackoptions/) |

#### Returns

[`RelayTrackWriter`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaytrackwriter/)
