# RelaySubscriptionHandlers

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

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

Callbacks for one subscription made through [RelaySubscriber.subscribe](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaysubscriber/#subscribe). Each is optional
and runs synchronously as the protocol layer delivers the event; the SDK adds no queue. The
names say what happened between this connection and the relay. The borrowed
[RelaySubscriber.trackSource](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/relaysubscriber/#tracksource) keeps the core's protocol names (`onOk`, `onDone`) instead.

## Methods

### onError()?

```ts
onError?(error): void;
```

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

The relay answered the request with REQUEST_ERROR: it rejected the subscription, or the request
failed before acceptance (request timeout, or the request stream failing). A REQUEST_ERROR can
also arrive after acceptance, for example when the relay refuses an `update()`, and it ends the
subscription then too (issue #94). Connection shutdown and GOAWAY never arrive here: a pending
subscription ends through `subscribed` and `ended`, and an accepted one surfaces them as
subgroup resets and connection closure.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `error` | [`RequestError`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/requesterror/) |

#### Returns

`void`

***

### onGoaway()?

```ts
onGoaway?(goaway): void;
```

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

GOAWAY on this request stream: the relay wants this request re-issued, possibly elsewhere. A
GOAWAY on the connection itself ends the connection instead; observe `closed` for that.

#### Parameters

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

#### Returns

`void`

***

### onObject()?

```ts
onObject?(object): void;
```

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

One object arrived. Payloads are uninterpreted bytes. Objects can arrive after onPublisherDone.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `object` | [`MoqtObject`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/moqtobject/) |

#### Returns

`void`

***

### onPublisherDone()?

```ts
onPublisherDone?(info): void;
```

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

The publisher finished with the track (PUBLISH_DONE). This is a control notification, not the
end of the subscription: objects still in transit can arrive after it, and the request stays
open until `cancel()` or connection shutdown. The SDK does not resubscribe, and resubscribing
cannot bring back a finished track: against moq-relay, a subscribe after the publisher has gone
is refused (request error 16 `unroutable`), and one while its namespace stays announced replays
the track's cached last group and another done one round trip later. Back off, and do not
resubscribe to a track the publisher ended. A done that follows this subscription's own
`update()` is different: moq-relay ends the subscription on any update, the track is still live,
and resubscribing is how to apply the change. After a publisher crash the done arrives only at
the relay's QUIC idle timeout, about 11 s later on moq-relay 0.17.0. See spec/relay-interop.md,
"Publisher restarts".

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `info` | [`PublishDone`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/publishdone/) |

#### Returns

`void`

***

### onStateNotify()?

```ts
onStateNotify?(parameters): void;
```

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

The publisher changed the subscription's state on its own (PUBLISH_STATE_NOTIFY); `parameters`
carries only what changed. Informational.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `parameters` | [`MessageParameters`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/messageparameters/) |

#### Returns

`void`

***

### onSubgroupEnd()?

```ts
onSubgroupEnd?(info): void;
```

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

A subgroup stream finished cleanly (FIN).

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `info` | \{ `endOfGroup`: `boolean`; `groupId`: `number`; `subgroupId`: `number`; \} |
| `info.endOfGroup` | `boolean` |
| `info.groupId` | `number` |
| `info.subgroupId` | `number` |

#### Returns

`void`

***

### onSubgroupReset()?

```ts
onSubgroupReset?(info): void;
```

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

A subgroup stream was reset; objects from it may be missing. Called for every reset the relay
forwards. The relay may drop a reset for a subgroup it had not begun forwarding, so an abandoned
group can arrive as nothing at all, only a gap in group IDs.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `info` | \{ `error`: `unknown`; `groupId`: `number`; \} |
| `info.error` | `unknown` |
| `info.groupId` | `number` |

#### Returns

`void`

***

### onSubscribed()?

```ts
onSubscribed?(info): void;
```

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

The relay accepted the subscription (SUBSCRIBE_OK) and will forward objects. `info` carries
the track alias, the relay's parameters (LARGEST_OBJECT when the track already has content),
and the track properties as the relay sends them, which can differ from what the publisher
declared.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `info` | [`SubscribeOk`](https://www.caprid.com/docs/reference/typescript/caprid/relay/index/interfaces/subscribeok/) |

#### Returns

`void`

***

### onUpdateOk()?

```ts
onUpdateOk?(): void;
```

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

The relay acknowledged an `update()` on this subscription (REQUEST_OK). moq-relay never does: it
ends the subscription with PUBLISH_DONE on any update (spec/behavior.md, relay interop
deviation 4).

#### Returns

`void`
