Repository navigation
feat: add node native module "sero-node" and pipeline jobs #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b304e7d
feat: add node native module "sero-node" and pipeline jobs
LeoLTM 58a9a41
feat: bump package version
LeoLTM e1f65db
feat: update CI configuration to only use newer GCC and Clang versions
LeoLTM f715996
Potential fix for code scanning alert no. 5: Workflow does not contai…
mad201802 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # dependencies (bun install) | ||
| node_modules | ||
|
|
||
| # output | ||
| out | ||
| build | ||
| dist | ||
| *.tgz | ||
| index.js | ||
|
|
||
| # code coverage | ||
| coverage | ||
| *.lcov | ||
|
|
||
| # logs | ||
| logs | ||
| _.log | ||
| report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
|
||
| # dotenv environment variable files | ||
| .env | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
| .env.local | ||
|
|
||
| # caches | ||
| .eslintcache | ||
| .cache | ||
| *.tsbuildinfo | ||
|
|
||
| # IntelliJ based IDEs | ||
| .idea | ||
|
|
||
| # Finder (MacOS) folder config | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| # sero-node | ||
|
|
||
| Node.js native bindings for the [sero](../sero) C++17 header-only protocol library. Exposes the full `sero::Runtime` API — service discovery, request/response, event pub/sub, HMAC authentication, and diagnostics — over an embedded POSIX UDP transport (unicast + multicast). | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Node.js ≥ 18 (or Bun) | ||
| - `node-gyp` build toolchain (Python 3, C++17 compiler) | ||
| - The `sero` library checked out at `../sero` (sibling directory) | ||
|
|
||
| ## Install & build | ||
|
|
||
| ```bash | ||
| bun install # or npm install | ||
| bun run build # or npm run build | ||
| ``` | ||
|
|
||
| For Electron: | ||
|
|
||
| ```bash | ||
| bun run electron-rebuild | ||
| ``` | ||
|
|
||
| ## Quick start | ||
|
|
||
| ```ts | ||
| import { SeroRuntime, ReturnCode, DtcSeverity } from "./index"; | ||
|
|
||
| // ── Create a runtime (binds UDP on port 30491) ────────────── | ||
| const rt = new SeroRuntime({ port: 30491, clientId: 0x7701 }); | ||
|
|
||
| // ── Provider: register & offer a service ──────────────────── | ||
| rt.registerService(0x1000, { | ||
| onRequest(methodId, payload) { | ||
| if (methodId === 0x0001) { | ||
| return { returnCode: ReturnCode.E_OK, response: Buffer.from("pong") }; | ||
| } | ||
| return { returnCode: ReturnCode.E_UNKNOWN_METHOD }; | ||
| }, | ||
| }); | ||
| rt.offerService(0x1000, 30); | ||
|
|
||
| // ── Consumer: discover & call a remote service ────────────── | ||
| rt.onServiceFound((serviceId, address) => { | ||
| console.log(`Found 0x${serviceId.toString(16)} at ${address.ip}:${address.port}`); | ||
| }); | ||
| rt.findService(0x0001); // e.g. ZC_LIGHTS_ID from ESP32 | ||
|
|
||
| // Send a request (returns a Promise resolved during a future process() call) | ||
| const result = await rt.request(0x0001, 0x0002, Buffer.from([0x01]), 2000); | ||
| console.log("Response:", result.returnCode, result.payload); | ||
|
|
||
| // ── Event subscription (consumer) ─────────────────────────── | ||
| rt.subscribeEvent(0x1000, 0x8001, (sid, eid, payload) => { | ||
| console.log("Event:", sid, eid, payload); | ||
| }); | ||
|
|
||
| // ── Event notification (provider) ─────────────────────────── | ||
| rt.registerEvent(0x1000, 0x8001); | ||
| rt.notifyEvent(0x1000, 0x8001, Buffer.from([0x42])); | ||
|
|
||
| // ── Drive the protocol at ~100 Hz ─────────────────────────── | ||
| setInterval(() => rt.process(), 10); | ||
|
|
||
| // ── Cleanup ───────────────────────────────────────────────── | ||
| // rt.destroy(); | ||
| ``` | ||
|
|
||
| ## API overview | ||
|
|
||
| ### `new SeroRuntime(options)` | ||
|
|
||
| | Option | Type | Default | Description | | ||
| | ---------- | -------- | ----------- | ------------------------------------ | | ||
| | `bindIp` | `string` | `"0.0.0.0"` | IPv4 address to bind | | ||
| | `port` | `number` | — | UDP port for unicast traffic | | ||
| | `clientId` | `number` | — | Unique client identifier (uint16) | | ||
|
|
||
| ### Lifecycle | ||
|
|
||
| | Method | Description | | ||
| | --------------- | ---------------------------------------------- | | ||
| | `process()` | Drive one protocol cycle (poll, dispatch, SD) | | ||
| | `destroy()` | Release all resources | | ||
|
|
||
| ### Provider | ||
|
|
||
| | Method | Description | | ||
| | --------------------------------------------------- | -------------------------------------------- | | ||
| | `registerService(id, handler, opts?)` | Register a service implementation | | ||
| | `unregisterService(id)` | Unregister a service | | ||
| | `offerService(id, ttl?)` | Announce via Service Discovery | | ||
| | `stopOffer(id)` | Stop announcing | | ||
| | `registerEvent(serviceId, eventId)` | Register a producible event | | ||
| | `notifyEvent(serviceId, eventId, payload)` | Push notification to subscribers | | ||
|
|
||
| ### Consumer | ||
|
|
||
| | Method | Description | | ||
| | ---------------------------------------------------------------------- | ------------------------------------- | | ||
| | `findService(id, major?)` | Search via SD | | ||
| | `request(serviceId, methodId, payload?, timeout?) → Promise` | Send request, await response | | ||
| | `requestTo(addr, serviceId, methodId, payload?, timeout?) → Promise` | Request to explicit address | | ||
| | `fireAndForget(serviceId, methodId, payload?)` | One-way request | | ||
| | `subscribeEvent(serviceId, eventId, handler, ttl?)` | Subscribe to remote event | | ||
| | `unsubscribeEvent(serviceId, eventId)` | Unsubscribe | | ||
|
|
||
| ### SD callbacks | ||
|
|
||
| | Method | Callback signature | | ||
| | ----------------------- | --------------------------------------------------------------- | | ||
| | `onServiceFound(cb)` | `(serviceId: number, address: Address) => void` | | ||
| | `onServiceLost(cb)` | `(serviceId: number) => void` | | ||
| | `onSubscriptionAck(cb)` | `(serviceId, eventId, returnCode, grantedTtl) => void` | | ||
|
|
||
| ### Security | ||
|
|
||
| | Method | Description | | ||
| | ----------------------------- | ------------------------------------ | | ||
| | `setHmacKey(peer, key)` | Set 32-byte HMAC key for a peer | | ||
|
|
||
| ### Diagnostics & DTCs | ||
|
|
||
| | Method | Description | | ||
| | ------------------------------ | ------------------------------------------ | | ||
| | `onDiagnostic(cb)` | Callback on counter increment | | ||
| | `getDiagnostics()` | Snapshot of all counters | | ||
| | `enableDiagnostics(auth?)` | Enable built-in diagnostics service | | ||
| | `reportDtc(code, severity)` | Report a trouble code | | ||
| | `clearDtc(code)` | Clear one DTC | | ||
| | `clearAllDtcs()` | Clear all DTCs | | ||
| | `getDtcs()` | Read all active DTCs | | ||
|
|
||
| ### Constants | ||
|
|
||
| Exported as frozen objects: `ReturnCode`, `DtcSeverity`, `DiagnosticCounter`, `MessageType`. | ||
|
|
||
| ## Compatibility with ESP32 devices | ||
|
|
||
| This module uses the same wire format and multicast group (`239.0.0.1:30490`) as the ESP32 PlatformIO projects (`zc_buttons`, `zc_lights`). A desktop Node.js app using sero-node can discover, call methods on, and receive events from ESP32 devices on the same network — no configuration needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "targets": [ | ||
| { | ||
| "target_name": "sero-node", | ||
| "sources": [ "src/sero-node.cpp" ], | ||
| "include_dirs": [ | ||
| "<!@(node -p \"require('node-addon-api').include\")", | ||
| "../include" | ||
| ], | ||
| "dependencies": [ | ||
| "<!(node -p \"require('node-addon-api').gyp\")" | ||
| ], | ||
| "cflags!": [ "-fno-exceptions" ], | ||
| "cflags_cc!": [ "-fno-exceptions" ], | ||
| "cflags_cc": [ "-std=c++17" ], | ||
| "xcode_settings": { | ||
| "GCC_ENABLE_CPP_EXCEPTIONS": "YES", | ||
| "CLANG_CXX_LANGUAGE_STANDARD": "c++17", | ||
| "MACOSX_DEPLOYMENT_TARGET": "10.15" | ||
| }, | ||
| "msvs_settings": { | ||
| "VCCLCompilerTool": { | ||
| "ExceptionHandling": 1, | ||
| "AdditionalOptions": ["/std:c++17"] | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.