PROTOCOL
TransportDriver
Abstract Transport Driver API
Describes anything capable of sending messages and subscribing to incoming messages (e.g. udp socket). Despite some complications due to not tracking message delivery, this is the most simple approach to bidirectional message transfer, which may be implemented via any kind of socket, http+sse etc.
Methods
send(meta:data:)
Send a message via transport
This method awaits until the message is sent (not until it's delivered) and throws if sending is impossible. Specific destination and delivery is handled by implementation.
Parameters
Name | Description |
---|---|
meta | message identifiers |
data | message data |
Returns
void
on(filter:callback:)
Subscribe to specific kinds of messages
It is possible to subscribe to the same message twice, which may be used in advanced message filtering strategies.
Parameters
Name | Description |
---|---|
filter | incoming message filter |
callback | to be invoked with messages matching to a provided filter |
Returns
String
subscription identifier, used to cancel this subscription
off(id:data:)
Cancel an existing subscription
Does not throw if there were no subscriptions with this id. If current subscriber is actively awaiting a message one may use the optional data field to resolve that.
Parameters
Name | Description |
---|---|
id | subscription identifier returned upon creation |
data | (optional) message data to be sent to a current subscriber’s callback |
Returns
void