Members
appName
Properties:
Name |
Type |
Description |
appName |
String
|
The name of the application. This information
is prepended to the appTitle. |
- Source:
appTitle
Properties:
Name |
Type |
Description |
appTitle |
String
|
The title of the application as it should appear in
the main browser window / tab and any new windows / tabs. If running as a desktop
(Electron) application, this is the name that appears on all child windows of
the main process. |
- Source:
appVersion
Properties:
Name |
Type |
Description |
appVersion |
String
|
The version of the application. This information
is appended to the appTitle. |
- Source:
hostEnv
Properties:
Name |
Type |
Default |
Description |
hostEnv |
Object
|
null
|
Contains settings and references supplied by
a non-browser host environment such as Electron. When running as a standard web
page in a browser this value should remain null. |
- Source:
ipcID
Properties:
Name |
Type |
Default |
Description |
ipcID |
String
|
null
|
an interprocess communication ID used to
identify this window (child process) to the main process. If not running
in a desktop (Electron) environment, this value will remain null . |
- Source:
ipcRenderer
Properties:
Name |
Type |
Default |
Description |
ipcRenderer |
Object
|
null
|
A reference to the ipcRenderer
object of the host desktop (Electron) environment. If this script is running
within a standard web browser this reference will remain null . |
- Source:
The platform object.
Type:
- Source:
Methods
buildJSONRPC(typeopt, optionsopt, versionopt) → {Object}
Builds a valid JSON-RPC request, result, or notification object.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
type |
String
|
<optional>
|
"request"
|
The JSON-RPC message type. Valid types include:
"request" : A request / method invocation object.
"result" : An invocation result object.
"notification" : A notification object.
|
options |
Object
|
<optional>
|
null
|
An object containing additional options
for the returned object depending on its type.
Properties
Name |
Type |
Attributes |
Default |
Description |
id |
Object
|
<optional>
|
null
|
An id value for the object. If type
is a "result" or "request" and this value is null or omiited,
a random value is used. If type is "notification" the id
is ommitted according to specification. |
method |
String
|
<optional>
|
null
|
A remote RPC method to invoke. If type
is "request" and this value is null or omiited, an exception is thrown.
If type is not "request" this option is ignored. |
params |
Object
|
Array
|
<optional>
|
null
|
Parameters to invoke the remote method
with. If type is not "request" this option is ignored. |
|
version |
String
|
<optional>
|
"2.0"
|
The JSON-RPC version identifier. |
- Source:
- See:
-
Returns:
A JSON-RPC-formatted object of the defined type.
-
Type
-
Object
(async) handleRPCResponses(transport, type, expectedResponseID, resolve, reject)
Handles asynchronous JSON-RPC 2.0 responses where a response ID must match a request ID before
associated promises can be resolved.
Parameters:
Name |
Type |
Description |
transport |
Object
|
A reference to the network transport handling thr response. |
type |
String
|
The transport type being handled. Supported types include: "websocket" |
expectedResponseID |
String
|
Number
|
The expected response ID to match from messages
received by the transport before resolving. |
resolve |
function
|
A promise resolve function to invoke with the response data when
the response ID matches expectedResponseID |
reject |
function
|
A promise reject function. Not currently used. |
- Source:
IPCSend(command, dataopt, asyncopt) → {Object|Promise}
Sends an IPC command to the main Electron process if this script is
running within a desktop (Electron) environment.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
command |
String
|
|
|
The command to send to the main process via IPC. |
data |
*
|
<optional>
|
null
|
Any accompanying data to include with the command .
If omitted or null , an empty object is created. |
async |
Boolean
|
<optional>
|
false
|
Sends the request asynchronously, immediately
returning a promise instead of the synchronous response object. Synchronous requests
async=false will block the main thread. |
- Source:
Returns:
A reply object is immediately returned if the desktop IPC
interface is available otherwise null
is returned. If async=true
,
a promise is returned instead that resolves with the reply object or rejects with an error.
The behaiour of the promise matches the behaviour of the synchronous reply.
-
Type
-
Object
|
Promise
isDesktop() → {Boolean}
Tests whether or not the host environment is a desktop (Electron) one.
- Source:
Returns:
True if the host environment is a desktop (Electron) one
otherwise it's a standard web (browser) host environment.
-
Type
-
Boolean
parseURLParameters(urlString) → {URLSearchParams}
Parses a supplied URL string that may contain parameters (e.g. document.location),
and returns an object with the parameters parsed to name-value pairs. Any URL-encoded
properties are decoded to native representations prior to being parsed.
Parameters:
Name |
Type |
Description |
urlString |
String
|
The URL string, either absolute or relative, to parse. |
- Source:
- See:
-
Returns:
A
URLSearchParams
instance containing the parsed name-value pairs found in the
urlString
.
-
Type
-
URLSearchParams
RPC(method, param, transport, generateOnlyopt, msgIDopt, resolveOnIDopt) → {Promise|Object}
Invokes a RPC (API) request through a HTTP, WebSocket, or routed interface.
Parameters:
Name |
Type |
Attributes |
Default |
Description |
method |
String
|
|
|
The remote procedure/method/function to invoke. |
param |
Object
|
|
|
The parameters to include with the remote method. |
transport |
XMLHttpRequest
|
WebSocket
|
router
|
|
|
The transport object to use for
for the request. The request is handled automatically based on this object
type. |
generateOnly |
Boolean
|
<optional>
|
false
|
Flag denoting whether the
request should only be generated and returned (true), or processed and a
Promise object returned (false). |
msgID |
String
|
Number
|
<optional>
|
null
|
ID to include with the request.
In order to differentiate requests/responses, this value should always
be unique. If not provided, an internal integer value is used instead. |
resolveOnID |
Boolean
|
<optional>
|
true
|
If true, the returned promise resolves
only when a response is received matching the message ID of the request,
otherwise the first server response or notification resolves the returned promise. |
- Source:
Returns:
An asynchorous Promise or JSON-RPC 2.0 object if
(generateOnly=true).
The returned Promise will resolve with either the immediate response (if resolveOnID=false
)
or when the mathing response ID matches the request ID (if resolveOnID=true
).
It will reject if the request could not be processed. Note that the result data
for WebSocket objects is returned as the data property, a string, of
the result while for XHR objects the result is the target.response
property which is a native (parsed) object.
The generated JSON-RPC 2.0 object can be stringified and sent using another
communication channel.
-
Type
-
Promise
|
Object
Examples
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8080");
RPC("Hello", {}, xhr).then((event) => {
//event.target.response is a native (parsed) object in XHR replies
var dataObj = event.target.response;
alert("Hello" + JSON.stringify(dataObj));
});
async function callHTTPRPC() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:8080");
var event = await RPC("Hello", {}, xhr);
var dataObj = event.target.response;
alert("Hello" + JSON.stringify(dataObj));
}
callHTTPRPC();
var ws = new WebSocket("ws://localhost:8090");
RPC("Hello", {}, ws).then((event) => {
//event.data is a string in WebSocket replies
var dataObj = JSON.parse(event.data);
alert("Hello" + JSON.stringify(dataObj));
});
async function callWSRPC() {
var ws = new WebSocket("ws://localhost:8090");
var event = await RPC("Hello", {}, ws);
var dataObj = JSON.parse(event.data);
alert("Hello" + JSON.stringify(dataObj));
}
callWSRPC();
//note that this is just a regular function call and returns an object, not a
//promise!
let JSONRequest = RPC("Hello", {}, null, true);
uniqueRPCID() → {String}
Returns a unique RPC id
value that can be used to identify
JSON-RPC 2.0 messages.
- Source:
Returns:
A unique id
.
-
Type
-
String
Type Definitions
keypair
An encryption/decryption key pair and associated prime value. A null
object indicates that the keypair is being generated. All values
are either in hexadecimal (pre-pended with "0x"), or decimal. Keys may be
swapped prior to first use if desired.
Type:
Properties:
Name |
Type |
Description |
encKey |
String
|
A string representation of the encryption key. |
decKey |
String
|
A String representation of the decryption key. |
prime |
String
|
A string representation of the associated prime number. |
- Source:
PeerConnectionObject
An object containing information and references to connectivity
options for an individual peer.
Type:
Properties:
Name |
Type |
Description |
options |
Object
|
Contains the transport options (supported connectivity)
for the peer.
Properties
Name |
Type |
Default |
Description |
wss |
Boolean
|
false
|
Does the peer support WebSocket Sessions connecivity? |
webrtc |
Boolean
|
false
|
Does the peer support WebRTC connecivity? |
ortc |
Boolean
|
false
|
Does the peer support ORTC connecivity? |
|
status |
Object
|
Contains the connection status of each transport option
Properties
Name |
Type |
Default |
Description |
wss |
String
|
"closed"
|
The WebSocket Sessions transport may either be "closed" ,
the connection may be "pending" , it may be "open" for bi-directional
communication, or a connection attempt may have "failed" . |
webrtc |
String
|
"closed"
|
The WebRTC transport may either be "closed" ,
the connection may be "pending" , it may be "open" for bi-directional
communication, or a connection attempt may have "failed" . |
ortc |
String
|
"closed"
|
The ORTC transport may either be "closed" ,
the connection may be "pending" , it may be "open" for bi-directional
communication, or a connection attempt may have "failed" . |
|
transport |
Object
|
Contains references to any transports defined in
the conectivity options .
Properties
Name |
Type |
Default |
Description |
wss |
Object
|
null
|
A reference to the WebSocket Sessions / Tunnel transport
with which to communicate with the peer. |
webrtc |
Object
|
null
|
A reference to the WebRTC transport
with which to communicate with the peer. |
ortc |
Object
|
null
|
A reference to the ORTC transport
with which to communicate with the peer. |
|
connectTimeout |
Object
|
References to Timeout objects
used when attempting to establish a connection to the peer.
Properties
Name |
Type |
Default |
Description |
wss |
Object
|
null
|
The Timeout object
used when attempting to establish a WebSocket Sessions connection. |
webrtc |
Object
|
null
|
The Timeout object
used when attempting to establish a WebRTC connection. |
ortc |
Object
|
null
|
The Timeout object
used when attempting to establish a ORTC connection. |
|
connectPromise |
Object
|
References to Promise function
references that are resolved or rejected when the associated transport is attempting
a connection.
Properties
Name |
Type |
Description |
wss |
Object
|
The Promise functions that resolve
or reject when the WebSocket Sessions / Tunnel transport connects or fails to connect.
Properties
Name |
Type |
Default |
Description |
resolve |
function
|
null
|
The Promise.resolve
function invoked on a successfull WebSocket Sessions connection. |
reject |
function
|
null
|
The Promise.reject
function invoked on a failed WebSocket Sessions connection. |
|
webrtc |
Object
|
The Promise functions that resolve
or reject when the WebRTC transport connects or fails to connect.
Properties
Name |
Type |
Default |
Description |
resolve |
function
|
null
|
The Promise.resolve
function invoked on a successfull WebRTC connection. |
reject |
function
|
null
|
The Promise.reject
function invoked on a failed WebRTC connection. |
|
ortc |
Object
|
The Promise functions that resolve
or reject when the ObjectRTC transport connects or fails to connect.
Properties
Name |
Type |
Default |
Description |
resolve |
function
|
null
|
The Promise.resolve
function invoked on a successfull ObjectRTC connection. |
reject |
function
|
null
|
The Promise.reject
function invoked on a failed ObjectRTC connection. |
|
|
- Source: