new RuntimePortTransport(onReceivedObject)
A RuntimePortTransport extends Transport to connect to a WebExtensions
runtime.port.
Parameters:
Name | Type | Description |
---|---|---|
onReceivedObject |
function | (optional) If supplied and the received object type field is not "Buffer" then just call this.onReceivedObject(obj). If this is null, then don't call it. |
Methods
(static) ConnectionInfo(port)
Create a new RuntimePortTransport.ConnectionInfo which extends
Transport.ConnectionInfo to hold the runtime.port used to connect.
Parameters:
Name | Type | Description |
---|---|---|
port |
runtime.port | The runtime.port object. |
connect(connectionInfo, elementListener, onOpenCallback, onClosedCallback)
Connect to the runtime.port in connectionInfo. For a received object obj, if
obj.type is "Buffer", read an entire packet element from obj.data and call
elementListener.onReceivedElement(element). Otherwise just call
onReceivedObject(obj) using the callback given to the constructor.
Parameters:
Name | Type | Description |
---|---|---|
connectionInfo |
RuntimePortTransport.ConnectionInfo | The ConnectionInfo with the runtime.port. |
elementListener |
object | The elementListener with function onReceivedElement which must remain valid during the life of this object. |
onOpenCallback |
function | Once connected, call onOpenCallback(). |
onClosedCallback |
function | (optional) If the connection is closed by the remote host, call onClosedCallback(). If omitted or null, don't call it. |
isLocal(connectionInfo, onResult, onError)
Determine whether this transport connecting according to connectionInfo is to
a node on the current machine. RuntimePortTransport is always local.
Parameters:
Name | Type | Description |
---|---|---|
connectionInfo |
RuntimePortTransport.ConnectionInfo | This is ignored. |
onResult |
function | This calls onResult(true) because a runtime.port is always local. |
onError |
function | This is ignored. |
send(buffer)
Send the buffer over the connection created by connect.
Parameters:
Name | Type | Description |
---|---|---|
buffer |
Buffer | The bytes to send. |
sendObject(obj)
Send the JavaScript object over the connection created by connect.
Parameters:
Name | Type | Description |
---|---|---|
obj |
object | The object to send. If it is a JSON Buffer then it is processed like an NDN packet. |
setOnReceivedObject(onReceivedObject)
Set the onReceivedObject callback, replacing any previous callback.
Parameters:
Name | Type | Description |
---|---|---|
onReceivedObject |
function | (optional) If supplied and the received object type field is not "Buffer" then just call this.onReceivedObject(obj). If this is null, then don't call it. |