# SwitchableHandlers

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

Defined in: [relay-sdks/ts/src/switchable.ts:29](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L29)

Callbacks for a switchable subscription. Each runs synchronously, for the active subscription's
events only, and receives the active track's name as its last argument. A pending subscription
reaches no handler before its cutover.

## Methods

### onError()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:40](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L40)

The active subscription ended with REQUEST_ERROR: the first one was rejected, or an accepted one
was refused later. The switchable has ended. A pending subscription's rejection rejects its
`switchTo` instead.

#### Parameters

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

#### Returns

`void`

***

### onGoaway()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:55](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L55)

GOAWAY on the active subscription's request stream. Informational; nothing is retried.

#### Parameters

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

#### Returns

`void`

***

### onObject()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:42](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L42)

One object from the active subscription. Payloads are uninterpreted bytes.

#### Parameters

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

#### Returns

`void`

***

### onPublisherDone()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:51](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L51)

The active track's publisher finished with it (PUBLISH_DONE). Not an ending, as on
`RelaySubscriptionHandlers.onPublisherDone`; a pending switch carries on.

#### Parameters

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

#### Returns

`void`

***

### onStateNotify()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:53](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L53)

The publisher changed the active subscription's state (PUBLISH_STATE_NOTIFY).

#### Parameters

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

#### Returns

`void`

***

### onSubgroupEnd()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:44](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L44)

One of the active subscription's subgroup streams finished cleanly (FIN).

#### Parameters

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

#### Returns

`void`

***

### onSubgroupReset()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:46](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L46)

One of the active subscription's subgroup streams was reset; objects from it may be missing.

#### Parameters

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

#### Returns

`void`

***

### onSubscribed()?

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

Defined in: [relay-sdks/ts/src/switchable.ts:34](https://github.com/caprids/relay-sdks/blob/main/ts/src/switchable.ts#L34)

The first subscription accepted (SUBSCRIBE_OK). A later subscription's acceptance arrives with
its cutover, in `onSwitched`.

#### Parameters

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

#### Returns

`void`

***

### onSwitched()?

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

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

A cutover: `to` is now active and `from` has been cancelled. Runs before the first object of
`to`, which is the one that passed `until`. Decoders drop state that assumed continuity here.

#### Parameters

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

#### Returns

`void`
