Socket
Socket
Sign inDemoInstall

node-rnw-rpc

Package Overview
Dependencies
1
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    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.


Version published
Weekly downloads
5
increased by400%
Maintainers
1
Install size
237 kB
Created
Weekly downloads
 

Readme

Source

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.

FAQs

Last updated on 01 Sep 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc