@andyfischer/remote-streams
v0.1.1
Published
Send and receive streams (using @andyfischer/streams) across remote connections
Readme
Outline
Library for remote transmission of data on Stream objects. (using @andyfischer/streams).
Each connection is multiplexed so it can support multiple streams at once. For example, the HTTP client can receive data for multiple Streams as part of a single HTTP request.
Supports a few builtin transport types and supports custom transports.
Provides a generic Connection interface, so that most of the code can be agnostic about what the connection's transport is.
Builtin transports
- HttpClient - Client using
fetchto make HTTP requests. - MessagePort - Client using Javascript
MessagePortobjects (used in web workers) - WebSocket - Client using a WebSocket connection.
- HttpServer - Server that handles HTTP requests.
- WebSocketServer - Server that handles WebSocket connections.
Overview
Each remote connection has two layers:
Connection layer
- Implemented by the
Connectionclass. - Same class used for all types of protocols.
- Handles multiplexing of request & response streams across the transport.
- Handles the connection state (connected / closed / etc)
- Handles creating the Transport as needed.
- Handles queueing of incoming messages if we're waiting to establish the connection.
- Implemented by the
Transport layer
- Seperate implementations for different protocols: HTTP, WebSocket, etc.
- Lower level, handles the details of sending the message across some remote protocol.
- Responsible for transporting messages to & from the Connection.
How to write a new Transport
The transport interface looks like:
interface ConnectionTransport<RequestType, ResponseType> {
send(message: TransportMessage<RequestType>): void
incomingEvents: Stream< TransportMessage<RequestType> >
close(): void
}