ic-websocket-js
Version:
IC WebSocket on the Internet Computer
57 lines (56 loc) • 2.27 kB
TypeScript
import { Principal } from '@dfinity/principal';
import { HttpAgent, SignIdentity } from '@dfinity/agent';
import { WsAgentRequest, WsAgentRequestTransformFn } from './types';
export interface WsAgentOptions {
source?: WsAgent;
ws: WebSocket;
httpAgent: HttpAgent;
identity: SignIdentity | Promise<SignIdentity>;
/**
* Prevents the agent from providing a unique {@link Nonce} with each call.
* Enabling may cause rate limiting of identical requests
* at the boundary nodes.
*
* To add your own nonce generation logic, you can use the following:
* @example
* import {makeNonceTransform, makeNonce} from '@dfinity/agent';
* const agent = new HttpAgent({ disableNonce: true });
* agent.addTransform(makeNonceTransform(makeNonce);
* @default false
*/
disableNonce?: boolean;
/**
* Number of times to retry requests before throwing an error
* @default 3
*/
retryTimes?: number;
}
export declare class WsAgent {
private readonly _pipeline;
private _identity;
private readonly _ws;
private _timeDiffMsecs;
private _httpAgent;
private readonly _retryTimes;
readonly _isAgent = true;
constructor(options: WsAgentOptions);
addTransform(fn: WsAgentRequestTransformFn, priority?: number): void;
getPrincipal(): Promise<Principal>;
call(canisterId: Principal | string, options: {
methodName: string;
arg: ArrayBuffer;
effectiveCanisterId?: Principal | string;
}): Promise<void>;
/**
* Sends a fire-and-forget request body to the WebSocket Gateway.
* If the request fails, the request
*/
private _requestAndRetry;
/**
* Allows agent to sync its time with the network. Can be called during intialization or mid-lifecycle if the device's clock has drifted away from the network time. This is necessary to set the Expiry for a request
* @param {Principal} canisterId - Pass a canister ID if you need to sync the time with a particular replica. Uses the management canister by default
*/
syncTime(canisterId?: Principal): Promise<void>;
replaceIdentity(identity: SignIdentity): void;
protected _transform(request: WsAgentRequest): Promise<WsAgentRequest>;
}