For the complete documentation index, see llms.txt. This page is also available as Markdown.

ElectronJS

This guide shows how to integrate 9PROXY SDK (Node-API addon / Native) into an Electron application with a secure, layered architecture. It uses the SDK’s internal WebSocket channel and synchronous/asynchronous APIs to manage proxies and ports.

Architecture Overview

Goal: integrate 9PROXY SDK into Electron using safe separation of concerns:

  • Main Process (Node): load the SDK addon, start the main loop (runAsync), configure the SDK, open the internal WebSocket channel, and expose APIs to the renderer via IPC.

  • Preload (Bridge with contextIsolation: true): create a safe window.sdk bridge that forwards calls over IPC.

  • Renderer (UI/FE): call window.sdk.* methods and listen to SDK events (forwarded via IPC, or connect directly if needed).

Preparation

Install electron and essential tooling:electron, electron-builder

Install packages

// install

# Install Electron + builder
npm i --save electron electron-builder

# (Optional) Official tutorial
# https://www.electronjs.org/docs/latest/tutorial/tutorial-first-app

Place native SDK libraries

Create a folder (e.g. ninesdklibs/) that you will pass to sdk.initialize(''). Copy all native libraries into it:

This directory must be packaged with your app and remain unpacked at runtime (see electron-builder config later).

Alternative: manual vendoring

If you prefer to vendor the module inside your repo:

1

Create two folders: libs/ and ninesdklibs/.

2

Copy the nineproxysdk module into libs/nineproxysdk.

Point your app’s package.json dependency to that local path:

3

Copy the native libraries into ninesdklibs/:

You’ll still call sdk.initialize('ninesdklibs') using this folder name.

electron-builder Configuration (Reference)

Configure electron-builder so the native libs are unpacked from the ASAR and available at runtime.

NOTE

  • asar: true keeps your app bundled; asarUnpack ensures native binaries (.node, .dll, .so, .dylib) are extracted and loadable.

  • Make sure the folder name you pass to sdk.initialize('') matches the on-disk path you ship (e.g. ninesdklibs).

Main Process: SDK Integration & IPC

Importing modules

Set the storage path for SDK data

Set the API Key

Configure port range and IP format

Set up a WS channel for SDK events

Restore previous session data

Set up IPC methods to be called from the renderer process

Final result of main.js

Preload: bridge an toàn

Từ các hàm được đăng ký sử dụng thông qua ipc của electron tại preload ta định nghĩa các hàm này thành js function để đơn giản hoá + an toàn trong việc truy vấn

Renderer (UI): sử dụng bridge & lắng nghe event

Trên giao diện sử dụng 'DOMContentLoaded' để lắng nghe các event mà sdk giử lên thông qua icp

Security & Packaging

  • Enable hardening: contextIsolation: true, nodeIntegration: false.

  • Before exit: call stopCommunicate() and shutdown() to cleanly stop SDK tasks.

Integration Checklist

  • Configure asarUnpack for addon.node and all native libraries.

  • Use Preload + IPC; do not expose Node directly in the Renderer.

  • Hide tokens/secrets; proxy SDK API via your backend when possible.

  • Manage SDK lifecycle: start runAsync(), open WS, restoreData(), and on quit call stopCommunicate() + shutdown().

Last updated

Was this helpful?