Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use window dispatch event #25

Merged
merged 4 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 94 additions & 83 deletions docs/api-reference/avm-web-client.mdx

Large diffs are not rendered by default.

108 changes: 51 additions & 57 deletions docs/api-reference/avm-web-provider.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,127 +38,121 @@ import TOCInline from '@theme/TOCInline';
|--------------------------------------------------------|-------------------------------|
| [`IAVMWebProviderConfig`](types#iavmwebproviderconfig) | The provider's configuration. |

### `onDisable(listener)`
### `onDisable(callback)`

> Listens to `disable` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.
> Listens to `disable` messages sent from clients.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IDisableResult`](types#idisableresult) \| [`Promise<IDiscoverResult>`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`IDisableResult`](types#idisableresult) \| [`Promise<IDiscoverResult>`](types#idiscoverresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `onDiscover(listener)`
### `onDiscover(callback)`

> Listens to `discover` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IDiscoverResult`](types#idiscoverresult) \| [`Promise<IDiscoverResult>`](types#idiscoverresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`IDiscoverResult`](types#idiscoverresult) \| [`Promise<IDiscoverResult>`](types#idiscoverresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `onEnable(listener)`
### `onEnable(callback)`

> Listens to `enable` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IEnableResult`](types#ienableresult) \| [`Promise<IEnableResult>`](types#ienableresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`IEnableResult`](types#ienableresult) \| [`Promise<IEnableResult>`](types#ienableresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `onPostTransactions(listener)`
### `onPostTransactions(callback)`

> Listens to `post_transactions` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise<IPostTransactionsResult>`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise<IPostTransactionsResult>`](types#iposttransactionsresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `onSignAndPostTransactions(listener)`
### `onSignAndPostTransactions(callback)`

> Listens to `sign_and_post_transactions` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise<IPostTransactionsResult>`](types#iposttransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`IPostTransactionsResult`](types#iposttransactionsresult) \| [`Promise<IPostTransactionsResult>`](types#iposttransactionsresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `onSignTransactions(listener)`
### `onSignTransactions(callback)`

> Listens to `sign_transactions` messages sent from clients. This will replace any previous set listeners. If null is supplied, the listener will be removed.

#### Parameters

| Name | Type | Required | Default | Description |
|----------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|----------------------------------------------------------------------------------------|
| listener | (`options`: [`IAVMWebProviderListenerOptions`](types#iavmwebproviderlisteneroptions)) => ([`ISignTransactionsResult`](types#isigntransactionsresult) \| [`Promise<ISignTransactionsResult>`](types#isigntransactionsresult)) \| `null` | yes | - | The listener to call when the request message is sent, or null to remove the listener. |
| Name | Type | Required | Default | Description |
|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|---------|--------------------------------------------------------|
| callback | (`options`: [`IAVMWebProviderCallbackOptions`](types#iavmwebproviderlcallbackoptions)) => ([`ISignTransactionsResult`](types#isigntransactionsresult) \| [`Promise<ISignTransactionsResult>`](types#isigntransactionsresult)) | yes | - | The listener to call when the request message is sent. |

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |
| Type | Description |
|----------|-------------------------|
| `string` | the ID of the listener. |

### `startListening()`
### `removeAllListeners()`

> Starts listening to requests from clients. This method should not have to be manually called, as it is called as part of the [initialization](#initoptions) process. This method essentially closes a previous connection and opens a new connection to the BroadcastChannel.

:::note

This method must be called if the client needs listen to messages if the [`stopListening()`](#stoplistening) method was previously called.

:::
> Removes all listeners.

#### Returns

| Type | Description |
|--------|-------------|
| `void` | - |

### `stopListening()`
### `removeListener(id)`

> Stops listening to requests from clients. This method closes the connection to the BroadcastChannel.
> Removes the listener, by the ID.

:::caution

It is highly recommended you call this method when you no longer need to listen to client's requests or are cleaning up.
#### Parameters

:::
| Name | Type | Required | Default | Description |
|------|----------|----------|---------|----------------------------|
| id | `string` | yes | - | The listener ID to remove. |

#### Returns

Expand Down
Loading