class · Browser and Node

# RelayTransport

`@toip-tools/trust-core` · [View source](https://github.com/yourbuddyconner/toip-tools/blob/main/packages/trust-core/src/relayTransport.ts#L35)

Import:

```ts
import { RelayTransport } from "@toip-tools/trust-core";
```

## Constructor

Constructor:

```ts
new (opts: {
    url: string;
    identity: Identity;
    outbox?: OutboxStore;
    webSocket?: typeof WebSocket;
}): RelayTransport;
```

### Parameters

**`opts` (required)**

`{ url: string; identity: Identity; outbox?: OutboxStore; webSocket?: typeof WebSocket; }`

**Fields of `opts`**

**`url` (required)**

`string`

**`identity` (required)**

`Identity`

**`outbox` (optional)**

`OutboxStore | undefined`

**`webSocket` (optional)**

`{ new (url: string | URL, protocols?: string | string[]): WebSocket; prototype: WebSocket; readonly CONNECTING: 0; readonly OPEN: 1; readonly CLOSING: 2; readonly CLOSED: 3; } | undefined`

A WebSocket implementation, when the global one isn't suitable (e.g. under jsdom in tests).

### Returns

`RelayTransport`

## Properties

- **`status` (required)**: `RelayStatus`
- **`url` (required)**: `string`

## Methods

### `start`

Signature:

```ts
start(): void;
```

No parameters.

#### Returns

`void`

### `stop`

Signature:

```ts
stop(): void;
```

No parameters.

#### Returns

`void`

### `onStatus`

Signature:

```ts
onStatus(fn: (s: RelayStatus) => void): () => void;
```

#### Parameters

- **`fn` (required)**: `(s: RelayStatus) => void`

#### Returns

`() => void`

### `pending`

Messages waiting to be handed to the relay.

Signature:

```ts
pending(): number;
```

No parameters.

#### Returns

`number`

### `attach`

Signature:

```ts
attach(vid: string, deliver: (wire: Uint8Array) => Promise<void>): void;
```

#### Parameters

- **`vid` (required)**: `string`
- **`deliver` (required)**: `(wire: Uint8Array) => Promise<void>`

#### Returns

`void`

### `detach`

Signature:

```ts
detach(vid: string): void;
```

#### Parameters

- **`vid` (required)**: `string`

#### Returns

`void`

### `post`

Hands a sealed message to the relay, or keeps it in the outbox until the relay is reachable.

Signature:

```ts
post(from: string, to: string, wire: Uint8Array): Promise<Delivery>;
```

#### Parameters

- **`from` (required)**: `string`
- **`to` (required)**: `string`
- **`wire` (required)**: `Uint8Array<ArrayBufferLike>`

#### Returns

`Promise<Delivery>`

[Usage guide](https://toip.tools/toolkit/trust-core/#usage) · [Error handling](https://toip.tools/toolkit/trust-core/#errors) · [All exports](https://toip.tools/toolkit/trust-core/api/)

---

This is the Markdown version of https://toip.tools/toolkit/trust-core/api/RelayTransport/. An index of the documentation for AI assistants is at https://toip.tools/llms.txt.
