Skip to content

Commit 94842db

Browse files
committed
feat(ws): add new ws overload
1 parent e26d48d commit 94842db

File tree

1 file changed

+9
-3
lines changed
  • docs/pages/providers

1 file changed

+9
-3
lines changed

docs/pages/providers/ws.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ interface GetWsProvider {
2222
endpoints: Array<string | { uri: string; protocol: string[] }>,
2323
onStatusChanged?: (status: StatusChange) => void,
2424
): WsJsonRpcProvider
25+
(wsProviderConfig: WsProviderConfig): WsJsonRpcProvider
26+
}
27+
interface WsProviderConfig {
28+
endpoints: Array<string | { uri: string; protocol: string[] }>
29+
onStatusChanged?: (status: StatusChange) => void
30+
timeout?: number
2531
}
2632
```
2733

28-
In order to create the provider, there are three overloads for it. In a nutshell, one can pass one (or more) websocket `uri`s with its optional supported protocols. For example:
34+
In order to create the provider, there are four overloads for it. In a nutshell, one can pass one (or more) websocket `uri`s with its optional supported protocols. For example:
2935

3036
```ts
3137
import { getWsProvider } from "polkadot-api/ws-provider/web"
@@ -71,14 +77,14 @@ type WsClose = {
7177
type StatusChange = WsConnecting | WsConnected | WsError | WsClose
7278
```
7379
74-
- `CONNECTING`: The connection is still being opened. It includes which socket and protocols is trying to connect to.
80+
- `CONNECTING`: The connection is still being opened. It includes which socket and protocols is trying to connect to. The connection will be attempted for the time set in `timeout` option, defaulting to 3.5 seconds. Afterwards, in case it didn't succeed, it will go to `ERROR` status and proceed as if it was any other error.
7581
- `CONNECTED`: The connection has been established and is currently open. It includes which socket and protocols is trying to connect to.
7682
- `ERROR`: The connection had an error. The provider will try to reconnect to other websockets (if available) or the same one. It includes the event sent by the server.
7783
- `CLOSE`: The connection closed. If the server was the one closing the connection, the provider will try to reconnect to other websockets (if available) or the same one. It includes the event sent by the server.
7884
7985
`provider.getStatus()` returns the current status.
8086
81-
When creating the provider, the consumer can pass a callback that will be called every time the status changes:
87+
When creating the provider, the consumer can pass a callback (`onStatusChanged`) that will be called every time the status changes:
8288
8389
```ts
8490
const provider = getWsProvider("wss://myws.com", (status) => {

0 commit comments

Comments
 (0)