Skip to main content

HyperswarmStreamTransport

@totemsdk/stream-transport


@totemsdk/stream-transport / HyperswarmStreamTransport

Class: HyperswarmStreamTransport

Adapts a raw Hyperswarm connection (a Node.js Duplex stream) to IStreamTransport, carrying the connection's info (publicKey, topics).

Extends​

Constructors​

Constructor​

new HyperswarmStreamTransport(conn, info): HyperswarmStreamTransport

Parameters​

conn​

unknown

info​
publicKey​

Buffer

topics?​

Buffer<ArrayBufferLike>[]

Returns​

HyperswarmStreamTransport

Overrides​

NodeStreamTransport.constructor

Properties​

pubkey​

readonly pubkey: string


topics​

readonly topics: Buffer<ArrayBufferLike>[]

Accessors​

state​

Get Signature​

get state(): TransportState

Explicit connection state.

Returns​

TransportState

Explicit connection state.

Inherited from​

NodeStreamTransport.state

Methods​

close()​

close(): Promise<void>

Close the transport. After the returned promise resolves, no further data or close deliveries occur. Calling close() more than once is safe (the second call resolves immediately).

Returns​

Promise<void>

Inherited from​

NodeStreamTransport.close


onClose()​

onClose(handler): () => void

Subscribe to connection close. Returns an unsubscribe function.

Parameters​

handler​

CloseHandler

Returns​

() => void

Inherited from​

NodeStreamTransport.onClose


onData()​

onData(handler): () => void

Subscribe to data chunks. Returns an unsubscribe function.

Parameters​

handler​

DataHandler

Returns​

() => void

Inherited from​

NodeStreamTransport.onData


onError()​

onError(handler): () => void

Subscribe to transport errors. Returns an unsubscribe function.

Parameters​

handler​

ErrorHandler

Returns​

() => void

Inherited from​

NodeStreamTransport.onError


send()​

send(data): Promise<void>

Send bytes to the remote peer.

  • Returns a promise that resolves once the bytes are accepted by the underlying transport (or after the documented backpressure policy).
  • Rejects with ClosedTransportError if the transport is closed.
  • Rejects with the underlying error if delivery fails.

Parameters​

data​

Uint8Array

Returns​

Promise<void>

Inherited from​

NodeStreamTransport.send