Class: JSONBottleMessage

JSONBottleMessage

JSONBottleMessage

new JSONBottleMessage(data, owner [, origin])

Constructor
Parameters:
Name Type Argument Description
data string | JSONBottleMessage~data Message data
owner JSONBottleInterface JSONBottleInterface that created the message
origin external:Socket <optional>
If passed, represents the socket that the message came from (and can be replied to), otherwise message is treated as local

Members


body :object|undefined

Message body
Type:
  • object | undefined

id :string

Message id
Type:
  • string

origin :string|undefined

Message origin (if message is not local)
Type:
  • string | undefined

path :string|undefined

Message path
Type:
  • string | undefined

Methods


<static> isValidId(id)

Check if valid id
Parameters:
Name Type Description
id mixed Id to check
Returns:
- True if valid, false otherwise
Type
boolean

<static> isValidPath(path)

Check if valid subject
Parameters:
Name Type Description
path mixed Path to check
Returns:
- True if valid, false otherwise
Type
boolean

copy( [data])

Prepopulate new message with data from the current one
Parameters:
Name Type Argument Description
data JSONBottleMessage~data <optional>
Data to override props from the current message
Returns:
- New message
Type
JSONBottleMessage

isLocal()

Check if message is local (self injected)
Returns:
- True if local, false otherwise
Type
boolean

isReplied()

Check if message was already replied to
Returns:
- True if replied, false otherwise
Type
boolean

isValid()

Check if message is valid
Returns:
- True if (assumed) valid, false otherwise
Type
boolean

respond( [body])

Respond to the message
Parameters:
Name Type Argument Default Description
body Object <optional>
{} Body to send with a response
Returns:
- Self, for chaining
Type
JSONBottleMessage

send( [destination] [, callback])

Send the message
Parameters:
Name Type Argument Description
destination string | Array.<string> <optional>
If provided, sends to socket id(s) specified, otherwise sends to all socket
callback JSONBottleInterface~outgoingMessageCallback <optional>
Outgoing message callback
Returns:
- Self for chaining
Type
JSONBottleMessage

sendAsRequest( [destination] [, timeout])

Send the message as a request
Parameters:
Name Type Argument Default Description
destination string <optional>
Socket id to send the request to. If not present will send to the first socket found on this interface
timeout number <optional>
10000 Request timeout in milliseconds
Returns:
- Promise representing the request
Type
Promise

toJSON()

Return message data object ready to be stringified
Returns:
- Message data object
Type
JSONBottleMessage~data

toString()

Get string representation of this message
Returns:
- String representation of the message
Type
string

Type Definitions


data

Message data
Type:
  • Object
Properties:
Name Type Description
id string Message unique id (will be generated if not passed)
path string Message path
body Object Message body, defaults to an empty object