How stefanwerfling/node-rohc works
Project type and purpose
• This is a Node.js native‐add-on library (“node-rohc”) written in TypeScript and C++/N-API.
• Purpose: provide JavaScript/TypeScript bindings to the external ROHC (Robust Header Compression) C library so that Node apps can compress and decompress IP packets.
File structure
• Top‐level:
• package.json, binding.gyp, tsconfig.json – configuration for npm package, native build, TS build.
• src/ts – TypeScript wrapper (RohcAddon.ts) exposing a high‐level JS API.
• src/cpp – Native C++ implementation (njsrohc.cpp, rohc-napi.cpp) using N-API to bridge JS ⇄ ROHC library.
• dist – transpiled output (JS, declaration files, sourcemaps) ready for publish.
• test – a JS integration test demonstrating usage.
• Key patterns:
• Two‐layer API: TS layer delegates to compiled native module.
• Native binding built with node-gyp (binding.gyp).
• External dependency: system‐installed ROHC C library and its headers.
README for additional insights
• Describes how to install the ROHC C library, then install “node-rohc”.
• Shows usage: import {Rohc} from 'node-rohc', call compress()/decompress().
• Mentions versioning, context & packet info methods.
Main components & interactions
a. Components:
1. User Application (JS or TS code)
2. node-rohc TS API layer (Rohc class in RohcAddon.ts)
3. Compiled N-API native module (rohc-napi.node)
4. Underlying ROHC C library (librohc)
5. System environment / OS libraries (libtool, libpcap, cmocka, etc.)
b. Relationships:
• App calls Rohc methods → TS API
• TS API uses N-API calls into native .node binary
• Native code invokes functions in the ROHC C library
• ROHC library performs compress/decompress, returns buffers
• Native layer translates results back to JS buffers & metadata
c. Architectural patterns:
• Adapter/Facade: TS layer abstracts complexity of native calls.
• Native‐binding pattern: N-API code wrapping external C library.
• Build pipeline: TS → transpile → dist; C++ → node-gyp → .node binary.
d. Technologies:
• TypeScript for high‐level API
• Node-API (N-API) for native bindings
• Node-gyp / binding.gyp build system
• External ROHC C library
Putting it all together
• Layer with directory/file references:
• TS layer: src/ts/RohcAddon.ts → dist/src/ts/RohcAddon.js
• Native layer: src/cpp/rohc-napi.cpp + binding.gyp → build/Release/rohc.node
• External lib: /usr/local/lib/librohc.so