UNPKG

@libp2p/websockets

Version:

JavaScript implementation of the WebSockets module that libp2p uses and that implements the interface-transport spec

67 lines 2.26 kB
/** * @packageDocumentation * * A [libp2p transport](https://docs.libp2p.io/concepts/transports/overview/) based on [WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API). * * @example * * ```TypeScript * import { createLibp2p } from 'libp2p' * import { webSockets } from '@libp2p/websockets' * import { multiaddr } from '@multiformats/multiaddr' * * const node = await createLibp2p({ * transports: [ * webSockets() * ] * //... other config * }) * await node.start() * * const ma = multiaddr('/dns4/example.com/tcp/9090/tls/ws') * await node.dial(ma) * ``` */ import type { Transport, MultiaddrFilter, AbortOptions, ComponentLogger, OutboundConnectionUpgradeEvents, Metrics, CounterGroup, Libp2pEvents } from '@libp2p/interface'; import type { WebSocketOptions } from 'it-ws/client'; import type { TypedEventTarget } from 'main-event'; import type http from 'node:http'; import type https from 'node:https'; import type { ProgressEvent } from 'progress-events'; import type { ClientOptions } from 'ws'; export interface WebSocketsInit extends AbortOptions, WebSocketOptions { /** * @deprecated Use a ConnectionGater instead */ filter?: MultiaddrFilter; /** * Options used to create WebSockets */ websocket?: ClientOptions; /** * Options used to create the HTTP server */ http?: http.ServerOptions; /** * Options used to create the HTTPs server. `options.http` will be used if * unspecified. */ https?: https.ServerOptions; /** * Inbound connections must complete their upgrade within this many ms * * @deprecated Use the `connectionManager.inboundUpgradeTimeout` libp2p config key instead */ inboundConnectionUpgradeTimeout?: number; } export interface WebSocketsComponents { logger: ComponentLogger; events: TypedEventTarget<Libp2pEvents>; metrics?: Metrics; } export interface WebSocketsMetrics { dialerEvents: CounterGroup; } export type WebSocketsDialEvents = OutboundConnectionUpgradeEvents | ProgressEvent<'websockets:open-connection'>; export declare function webSockets(init?: WebSocketsInit): (components: WebSocketsComponents) => Transport; //# sourceMappingURL=index.d.ts.map