# withWebSocketFallback

URL: https://www.caprid.com/docs/reference/typescript/caprid/relay-websocket/functions/withwebsocketfallback/

```ts
function withWebSocketFallback(options?): FallbackTransportFactory;
```

Defined in: [relay-sdks/ts/packages/relay-websocket/src/index.ts:101](https://github.com/caprids/relay-sdks/blob/main/ts/packages/relay-websocket/src/index.ts#L101)

A transport factory for the SDK's `createTransport` option that dials the runtime's `WebTransport` first and, unless
that handshake completes within `webSocketDelayMs` (default 250 ms, as Happy Eyeballs, RFC 8305), dials QMux over
WebSocket alongside it. The first ready carries the session and the other dial is closed; a WebTransport handshake
that fails sooner starts the WebSocket at once. Where the runtime has no usable `WebTransport` (Safari before
WebTransport, Node), it dials WebSocket at once. Each connection decides afresh.

```ts
import { connectRelayPublisher } from '@caprid/relay';
import { withWebSocketFallback } from '@caprid/relay-websocket';

const publisher = await connectRelayPublisher({ url, getToken, createTransport: withWebSocketFallback() });
```

## Parameters

| Parameter | Type |
| ------ | ------ |
| `options?` | [`WebSocketFallbackOptions`](https://www.caprid.com/docs/reference/typescript/caprid/relay-websocket/interfaces/websocketfallbackoptions/) |

## Returns

[`FallbackTransportFactory`](https://www.caprid.com/docs/reference/typescript/caprid/relay-websocket/type-aliases/fallbacktransportfactory/)
