-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement disable method (#14)
* feat: add disable types * feat: add disable method to contollers * docs: add disable method tutorials
- Loading branch information
1 parent
ffd752d
commit fd37807
Showing
18 changed files
with
705 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,239 @@ | ||
import Tabs from '@theme/Tabs'; | ||
import TabItem from '@theme/TabItem'; | ||
import TOCInline from '@theme/TOCInline'; | ||
|
||
# Disabling A Client | ||
|
||
<TOCInline | ||
maxHeadingLevel={4} | ||
toc={toc} | ||
/> | ||
|
||
## Overview | ||
|
||
The disable method is not required for providers to implement. However, it is useful for providers that have a sessioning system in place when a client has previously called [`enable()`](../../api-reference/avm-web-client#enableparams). | ||
|
||
The aim of the disable method is for clients to request that these sessions be removed from the provider. | ||
|
||
## Disabling the client with all providers | ||
|
||
Assuming a client has been [enabled](enabling-a-client) with one or all providers, you can remove the client from all available providers by: | ||
|
||
<Tabs | ||
defaultValue="javascript" | ||
values={[ | ||
{ label: 'Javascript', value: 'javascript' }, | ||
{ label: 'TypeScript', value: 'typescript' }, | ||
]}> | ||
<TabItem value="javascript"> | ||
|
||
```js | ||
// initialized client | ||
client.onDisable((result, error) => { | ||
if (error) { | ||
console.error('error:', error); | ||
|
||
return; | ||
} | ||
|
||
console.log(result); | ||
/* | ||
{ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
} | ||
*/ | ||
}); | ||
|
||
// broadcast a disable request | ||
client.disable(); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="typescript"> | ||
|
||
```typescript | ||
import type { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; | ||
|
||
// initialized client | ||
client.onDisable((result: IDisableResult: null, error: BaseARC0027Error | null) => { | ||
if (error) { | ||
console.error('error:', error); | ||
|
||
return; | ||
} | ||
|
||
console.log(result); | ||
/* | ||
{ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
} | ||
*/ | ||
}); | ||
|
||
// broadcast a disable request | ||
client.disable(); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
:::caution | ||
|
||
If any providers do not support the `disable` method, then a [`MethodNotSupportedError`](../../api-reference/errors#methodnotsupportederror) will be returned. | ||
|
||
::: | ||
|
||
## Disabling the client with a specific provider and network | ||
|
||
If you want to target a specific provider and network, you can simply pass the ID of the provider and the genesis hash of the network in the params: | ||
|
||
<Tabs | ||
defaultValue="javascript" | ||
values={[ | ||
{ label: 'Javascript', value: 'javascript' }, | ||
{ label: 'TypeScript', value: 'typescript' }, | ||
]}> | ||
<TabItem value="javascript"> | ||
|
||
```js | ||
// initialized client | ||
client.onDisable((result, error) => { | ||
if (error) { | ||
console.error('error:', error); | ||
|
||
return; | ||
} | ||
|
||
console.log(result); | ||
/* | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
} | ||
*/ | ||
}); | ||
|
||
// broadcast an disable request | ||
client.disable({ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="typescript"> | ||
|
||
```typescript | ||
import type { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; | ||
const providerId: string = '02657eaf-be17-4efc-b0a4-19d654b2448e'; | ||
// initialized client | ||
client.onEnable((result: IDisableResult: null, error: BaseARC0027Error | null) => { | ||
if (error) { | ||
console.error('error:', error); | ||
return; | ||
} | ||
console.log(result); | ||
/* | ||
{ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
} | ||
*/ | ||
}); | ||
// broadcast an disable request | ||
client.disable({ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
:::caution | ||
|
||
If the network and the provider ID is specified, and the provider does not support the network, then a [`NetworkNotSupportedError`](../../api-reference/errors#networknotsupportederror) will be thrown. | ||
|
||
::: | ||
|
||
## Disabling a client for a specific session | ||
|
||
If you want to remove a specific session, you can provide the session ID(s) in the params: | ||
|
||
<Tabs | ||
defaultValue="javascript" | ||
values={[ | ||
{ label: 'Javascript', value: 'javascript' }, | ||
{ label: 'TypeScript', value: 'typescript' }, | ||
]}> | ||
<TabItem value="javascript"> | ||
|
||
```js | ||
// initialized client | ||
client.onDisable((result, error) => { | ||
if (error) { | ||
console.error('error:', error); | ||
return; | ||
} | ||
console.log(result); | ||
/* | ||
{ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
sessionIds: ['ab192498-0c63-4028-80fd-f148710611d8'], | ||
} | ||
*/ | ||
}); | ||
// broadcast an disable request | ||
client.disable({ | ||
sessionIds: ['ab192498-0c63-4028-80fd-f148710611d8'], | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem value="typescript"> | ||
|
||
```typescript | ||
import type { BaseARC0027Error, IDisableResult } from '@agoralabs-sh/avm-web-provider'; | ||
// initialized client | ||
client.onEnable((result: IDisableResult: null, error: BaseARC0027Error | null) => { | ||
if (error) { | ||
console.error('error:', error); | ||
return; | ||
} | ||
console.log(result); | ||
/* | ||
{ | ||
genesisHash: 'SGO1GKSzyE7IEPItTxCByw9x8FmnrCDexi9/cOUJOiI=', | ||
genesisId: 'testnet-v1.0', | ||
providerId: '02657eaf-be17-4efc-b0a4-19d654b2448e', | ||
sessionIds: ['ab192498-0c63-4028-80fd-f148710611d8'], | ||
} | ||
*/ | ||
}); | ||
// broadcast an disable request | ||
client.disable({ | ||
sessionIds: ['ab192498-0c63-4028-80fd-f148710611d8'], | ||
}); | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.