1.0.15 • Published 3 years ago

node-rnw-rpc v1.0.15

Weekly downloads
157
License
MIT
Repository
-
Last release
3 years ago

node-rnw-rpc

node-rnw-rpc adds support for remote procedure calls from a node client to react-native-windows server on the same machine.

Example

node app

import {waitForConnection} from 'node-rnw-rpc'

const rpcConnection = await waitForConnection({port: 8305});
const result = await rpcConnection.invoke("add", [2, 2])

react-native-windows app

#include "winrt/NodeRpc.Server.h"

// NodeRPC::Handler allows registering methods
winrt::NodeRPC::Handler handler();

// Binding to a simple method
handler.BindOperation("add", [](const JSonValue& params) noexcept {
  auto addends = params.GetArray();

  auto sum = 0;
  for (const auto& addend : addends) {
    sum += addend.GetNumber();
  }
  
  return JSonValue::CreateNumberValue(sum);
});

// Methods may be bound to IAsyncAction or IAsyncOperation
handler.BindAsyncAction("performAsyncOperation", [](const JSonValue& params) noexcept -> IAsyncAction {
  co_await performLongOperation();
});

// Start server
winrt::NodeRPC::Server rpcServer(handler);
co_await rpcServer.ProcessAllClientRequests(8305, 50ms);

Installing

node-rnw-rpc supports auto-linking to allow installation into react-native-windows applications.

Architecture

Reverse TCP server: Traditional server/client roles are reversed, where the node client creates a TCP server to connect to. This helps to bypass restrictions on inbound loopback traffic to UWP apps. This low-effort solution allows bypassing the UWP AppContainer.

Alternative approaches

  • Named pipe created inside AppContainer: Node provides first-class support for named-pipes through net.socket. It is possible to create a named pipe from a UWP process which a Win32 process can then connect to, allowing traditional server/client roles. Doing this requires locating the resource local to the AppContainer, using an API like GetAppContainerNamedObjectPath. This likely requires FFI (with node-gyp) or native extenssions.
  • Proxy to full-trust process The RNW application could create a full-trust process which proxies from TCP to named-pipe internal to the AppContainer. This bypasses inbound loopback restrictions, but adds complexity of deploying a separate process, requires two IPC channels.

Protocol

node-rnw-rpc uses a TCP channel, sending JSON messages across the wire prefixed with length. Messages themselves are conformant to the JSON-RPC version 2.0 protocol.

1.0.15-1

3 years ago

1.0.15

3 years ago

1.0.15-0

3 years ago

1.0.14

3 years ago

1.0.13-0

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.12-16

3 years ago

1.0.12-17

3 years ago

1.0.12-15

3 years ago

1.0.12-14

3 years ago

1.0.12-13

3 years ago

1.0.12-12

3 years ago

1.0.12-10

3 years ago

1.0.12-11

3 years ago

1.0.12-9

3 years ago

1.0.12-8

3 years ago

1.0.12-7

3 years ago

1.0.12-6

3 years ago

1.0.12-5

3 years ago

1.0.12-4

3 years ago

1.0.12-3

3 years ago

1.0.12-2

3 years ago

1.0.12-1

3 years ago

1.0.12-0

3 years ago

1.0.11

3 years ago

1.0.11-19

3 years ago

1.0.11-18

3 years ago

1.0.11-17

3 years ago

1.0.11-16

3 years ago

1.0.11-15

3 years ago

1.0.11-14

3 years ago

1.0.11-13

3 years ago

1.0.11-12

3 years ago

1.0.11-11

3 years ago

1.0.11-10

3 years ago

1.0.11-9

3 years ago

1.0.11-8

3 years ago

1.0.11-7

3 years ago

1.0.11-6

3 years ago

1.0.11-5

3 years ago

1.0.11-4

3 years ago

1.0.11-3

3 years ago

1.0.11-2

3 years ago

1.0.11-1

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.10-0

3 years ago

1.0.11-0

3 years ago

1.0.10

3 years ago

1.0.7-1

3 years ago

1.0.6

3 years ago

1.0.6-10

3 years ago

1.0.5

3 years ago

1.0.6-12

3 years ago

1.0.6-11

3 years ago

1.0.6-7

3 years ago

1.0.6-6

3 years ago

1.0.6-9

3 years ago

1.0.6-8

3 years ago

1.0.6-3

3 years ago

1.0.6-2

3 years ago

1.0.6-5

3 years ago

1.0.6-4

3 years ago

1.0.6-1

3 years ago

1.0.6-0

3 years ago

1.0.5-29

3 years ago

1.0.5-27

3 years ago

1.0.5-28

3 years ago

1.0.5-25

3 years ago

1.0.5-26

3 years ago

1.0.7-0

3 years ago

1.0.5-24

3 years ago

1.0.5-23

3 years ago

1.0.5-22

3 years ago

1.0.5-21

3 years ago

1.0.5-20

3 years ago

1.0.5-19

3 years ago

1.0.5-18

3 years ago

1.0.5-17

3 years ago

1.0.5-16

3 years ago

1.0.5-15

3 years ago

1.0.5-14

3 years ago

1.0.5-13

3 years ago

1.0.5-12

3 years ago

1.0.5-11

3 years ago

1.0.5-10

3 years ago

1.0.5-9

3 years ago

1.0.5-8

3 years ago

1.0.5-7

3 years ago

1.0.5-6

3 years ago

1.0.5-5

3 years ago

1.0.5-4

3 years ago

1.0.5-3

3 years ago

1.0.5-2

3 years ago

1.0.5-0

3 years ago

1.0.5-1

3 years ago

1.0.4

3 years ago

1.0.2-0

3 years ago

1.0.1

3 years ago

1.0.1-6

3 years ago

1.0.1-5

3 years ago

1.0.1-4

3 years ago

1.0.1-3

3 years ago

1.0.1-2

3 years ago

1.0.1-1

3 years ago

1.0.1-0

3 years ago

1.0.0

3 years ago