Messenger

Represents and duplex stream for dispatching messages to a given transport adapter and receiving messages to process through middleware stacks

Constructor

new Messenger(optionsopt)

Parameters:
NameTypeAttributesDescription
optionsobject<optional>
Properties
NameTypeAttributesDescription
serializerMessenger~serializer<optional>

Serializer function

deserializerMessenger~deserializer<optional>

Deserializer function

Methods

(static) JsonRpcDeserializer(rawMessage, callback)

Parameters:
NameTypeDescription
rawMessagebuffer

Incoming message as buffer

callbackfunction

Transform stream callback(err, data)

(static) JsonRpcSerializer(data, sender, receiver, callback)

Parameters:
NameTypeDescription
dataarray

Object to transform

Properties
NameTypeDescription
0object

JSON payload, parsed into an object

senderBucket~contact

Origin peer for message

receiverBucket~contact

Destination peer for message

callbackfunction

Transform stream callback(err, data)

(inner) deserializer(data, encoding, callback)

Parameters:
NameTypeDescription
dataobject | buffer

Incoming message buffer or parsed JSON data

encodingstring | null

Encoding of incoming data

callbackMessenger~deserializerCallback

(inner) serializer(data, encoding, callback)

Parameters:
NameTypeDescription
dataobject | buffer

Outgoing message buffer or parsed JSON data

encodingstring | null

Encoding of incoming data

callbackMessenger~serializerCallback

Type Definitions

deserializerCallback(error, data)

Parameters:
NameTypeDescription
errorerror | null
databuffer | object

Deserialized data to pass through middleware

serializerCallback(error, data)

Parameters:
NameTypeDescription
errorerror | null
databuffer | object

Serialized data to pass through middleware