Class: Port

Port(messageManager)

new Port(messageManager)

Communication port wrapping the message manager API to send and receive messages.
Parameters:
Name Type Description
messageManager nsIMessageManager
Source:

Methods

disconnect()

Disables the port and makes it stop listening to incoming messages.
Source:

emit(messageName, payloadopt)

Sends a message.
Parameters:
Name Type Attributes Description
messageName string message identifier
payload <optional>
data to attach to the message
Source:

emitSync(messageName, payloadopt)

Sends a synchonous message (DO NOT USE unless absolutely unavoidable).
Parameters:
Name Type Attributes Description
messageName string message identifier
payload <optional>
data to attach to the message
Source:
Returns:
response returned by the handler

emitWithResponse(messageName, payloadopt) → {Promise}

Sends a message and expects a response.
Parameters:
Name Type Attributes Description
messageName string message identifier
payload <optional>
data to attach to the message
Source:
Returns:
promise that will be resolved with the response
Type
Promise

off(messageName, callback)

Removes a handler for the specified message.
Parameters:
Name Type Description
messageName string message that would trigger the callback
callback Port~messageHandler
Source:

on(messageName, callback)

Adds a handler for the specified message.
Parameters:
Name Type Description
messageName string message that would trigger the callback
callback Port~messageHandler
Source:

Type Definitions

messageHandler(payload, sender)

Function to be called when a particular message is received
Parameters:
Name Type Description
payload data attached to the message if any
sender LightWeightPort object that can be used to communicate with the sender of the message, could be null
Source:
Returns:
the handler can return undefined (no response), a value (response to be sent to sender immediately) or a promise (asynchronous response).