Skip to content

Commit

Permalink
feat: use window dispatch event (#25)
Browse files Browse the repository at this point in the history
* feat: use window.dispatchevent over broadcast channel

* chore: squash

* docs: update docs to reflect new dispatch event function

* chore: squash
  • Loading branch information
kieranroneill authored Apr 22, 2024
1 parent 5719d67 commit 4e59039
Show file tree
Hide file tree
Showing 28 changed files with 556 additions and 682 deletions.
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

0 comments on commit 4e59039

Please sign in to comment.