Skip to content

Type Alias: NwjsServiceBridge ​

说明

本页由源码中的注释生成,内容为英文。

NwjsServiceBridge = object

The bridge nwjsServiceEntrypoint puts on the global object of NW.js (global[Symbol.for(key)]), which the windows share with the Node.js context: the trusted page of a window (the one holding the user interface in a <webview>) forwards to it the requests of the interface, and gives it the function pushing the events to it.

Methods ​

invoke() ​

invoke(data, clientId?): Promise<ServiceResponse>

Invoke a service action.

Parameters ​

data ​

Record<string, unknown>

The action's pattern and its input ({cmd: 'greet', name: 'you'}).

clientId? ​

string

The id of the page invoking: the clientId of the request's context.

Returns ​

Promise<ServiceResponse>

{success, error, payload} (see ServiceResponseCodec).


subscribe() ​

subscribe(clientId, push): void

Register a page as a client: the events pushed to it (Entrypoint.notify, broadcast) are given to push.

Parameters ​

clientId ​

string

The id of the page (a non-empty string of at most 200 characters).

push ​

(event, args) => void

Gives an event and its arguments to the page.

Returns ​

void


unsubscribe() ​

unsubscribe(clientId): void

Remove a client, when its page is loaded again or its window closed: its requests in progress are aborted.

Parameters ​

clientId ​

string

The id of the page.

Returns ​

void

Released under the MIT License.