# RelaySubscriber

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

Defined in: [relay-sdks/ts/src/connect.ts:123](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L123)

A connection that can only subscribe. Create one with [connectRelaySubscriber](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/functions/connectrelaysubscriber/). Publishing
uses a separate connection and token; see `connectRelayPublisher`.

## Properties

### closed

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

Defined in: [relay-sdks/ts/src/connect.ts:159](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L159)

Resolves once for local shutdown, peer closure, or failure. It never rejects.

***

### expiresAt

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

Defined in: [relay-sdks/ts/src/connect.ts:168](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L168)

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.

***

### maxAgeSupported

```ts
readonly maxAgeSupported: boolean;
```

Defined in: [relay-sdks/ts/src/connect.ts:175](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L175)

Whether the relay's SETUP declared subscriber max age (the MoQ Timestamp extension's MAX_AGE option, `0x915C4`), so
a `parameters.maxAge` on `subscribe`, `subscribeSwitchable`, `subscribeEvents`, `update()` or `trackSource.subscribe`
reaches it. While false the SDK leaves `maxAge` off every request, as the extension requires. moq-dev main declares
it; moq-relay 0.17.x does not. Fixed for the connection's life.

***

### trackSource

```ts
readonly trackSource: MoqTrackSource;
```

Defined in: [relay-sdks/ts/src/connect.ts:157](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L157)

This connection seen through the generic `MoqTrackSource` contract, for integrations such as
players: `subscribe`, `fetch`, and `trackStatus` in protocol terms, plus `closed`. It lists no
tracks and cannot close the connection; the application that opened the connection owns
shutdown.

## Methods

### close()

```ts
close(): void;
```

Defined in: [relay-sdks/ts/src/connect.ts:177](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L177)

Close this connection and all requests on it. Idempotent.

#### Returns

`void`

***

### namespaceEvents()

```ts
namespaceEvents(options): NamespaceEvents;
```

Defined in: [relay-sdks/ts/src/connect.ts:150](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L150)

Discover which namespaces under a prefix are announced, as bounded async events with the same
ownership rules as `subscribeEvents`: the iterator owns one SUBSCRIBE_NAMESPACE request, and
break/return, `close()` or the signal cancels it. It first yields `announced` for each namespace
already announced, then one event per announce and withdrawal. The relay sends no marker between
the two. A relay rejection ends it with `SubscriptionRequestError`, the connection ending with
`SubscriptionConnectionClosedError`, a full queue with `SubscriptionOverflowError`; a relay that
finishes the request ends it cleanly. See spec/behavior.md, "Discovery", for the timing.

#### Parameters

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

#### Returns

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

***

### subscribe()

```ts
subscribe(options, handlers?): RelaySubscription;
```

Defined in: [relay-sdks/ts/src/connect.ts:130](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L130)

Ask the relay for a track's objects, in any payload format, without discovering or loading a
catalog. Returns at once with a cancellable handle whose `subscribed` settles when the relay
answers and whose `ended` settles once the subscription can no longer deliver;
`handlers.onSubscribed` and `handlers.onError` report the same answer as callbacks.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`RelayTrackOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaytrackoptions/) |
| `handlers?` | [`RelaySubscriptionHandlers`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaysubscriptionhandlers/) |

#### Returns

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

***

### subscribeEvents()

```ts
subscribeEvents(options, buffer?): SubscriptionEvents;
```

Defined in: [relay-sdks/ts/src/connect.ts:140](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L140)

Bounded async events. Owns its subscription; break/return cancels it.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`RelayTrackOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaytrackoptions/) |
| `buffer?` | [`SubscriptionEventOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/subscriptioneventoptions/) |

#### Returns

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

***

### subscribeSwitchable()

```ts
subscribeSwitchable(options, handlers?): SwitchableSubscription;
```

Defined in: [relay-sdks/ts/src/connect.ts:138](https://github.com/caprids/relay-sdks/blob/main/ts/src/connect.ts#L138)

Subscribe to a track through a handle that can move to another track in the same namespace
make-before-break: `switchTo` opens the new subscription while this one keeps delivering, and
cuts over once the new one's object passes `until`. Use it to change layers (simulcast, ABR), or
to change a subscription's filter or priority, which `update()` cannot do against moq-relay.
Handlers see only the active subscription, with its track name.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `options` | [`RelayTrackOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaytrackoptions/) |
| `handlers?` | [`SwitchableHandlers`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/switchablehandlers/) |

#### Returns

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