How mayamatakeshi/sip-lab works
Purpose and public entry points
sip-lab is a Linux Node.js native module for functional/integration testing of SIP systems, including RTP/media operations. JavaScript consumers load the package through index.js or index_napi.js; the native addon boundary is implemented by src/addon.cpp (legacy) and the Rust N-API implementation in rust/src/napi_addon.rs.
Binding and runtime boundary
Node scripts issue SIP/test actions and receive asynchronous events through a N-API/native binding rather than a web service. The package has two native implementation tracks: C/C++ PJPROJECT-facing sources under src/, and a Rust crate that exposes N-API and FFI adapters under rust/src/. Build metadata includes binding.napi.gyp, rust/Cargo.toml, and rust/build.rs.
SIP core and call control
The central SIP lifecycle layer creates and manages SIP endpoints, dialogs, registrations, requests, and call/media negotiation on PJPROJECT. Native orchestration resides in src/sip.cpp and src/sip.hpp; the Rust-side core/FFI split is rust/src/sip_core.rs and rust/src/sip_ffi.rs. SIP traffic can use standard transports plus the repository’s WebSocket transport extension in src/pjsip/src/pjsip/sip_transport_ws.c.
Event delivery and identity management
Native SIP/media callbacks are normalized into event payloads for JavaScript, with stable identifiers used to correlate calls, streams, and operations. Both implementation tracks contain this architectural pair: src/event_templates.cpp / src/idmanager.cpp and rust/src/event_templates.rs / rust/src/id_manager.rs. This is the key asynchronous boundary between PJPROJECT callback threads and Node-facing test logic.
Media graph and signal-processing extensions
The project extends PJMEDIA with custom ports and chain-link components used to compose test media paths. src/pjmedia/src/chainlink/ provides wiring, WAV I/O, tone generation, DTMF detection, fax, and cross-correlation stages; src/pjmedia/include/chainlink/chainlink.h defines the extension surface. Custom PJMEDIA ports add BFSK/DTMF detection, fax, Flite TTS, PocketSphinx recognition, and WebSocket speech integration under src/pjmedia/src/pjmedia/.
External protocols and services
The native stack depends on PJPROJECT for SIP/SDP/RTP/media processing and system codec/TLS/media libraries supplied on Debian/Ubuntu. It supports SIP over WebSocket, TLS/SRTP-oriented scenarios, and optional speech processing. src/pjmedia/src/pjmedia/ws_speech_port.cpp connects media to an external WebSocket speech service; samples_extra/ demonstrates use with the separately deployed ws_speech_server and, indirectly, Google speech credentials/services.
Execution model and packaging
Consumers execute Node test scripts that drive the module, e.g. SIP calls, registration, reinvites, codecs, fax, and media assertions represented by samples/. The native server/bootstrap area is src/server.cpp, with logging in src/log.cpp. Distribution targets Debian/Ubuntu-compatible prebuilt native binaries, produced through gen_prebuilds.sh and containerized build environments in docker-images/debian11/ and docker-images/jammy/.
Main entry points: addon.cpp N-API bindings · event_templates.cpp Event normalization · napi_addon.rs Rust N-API addon · index.js Package entry points
Components 19
Node package
- Node test scripts · SIP, registration, codec, fax, and media test scenarios.
- Package entry points
index.js - N-API bindings · Delivers commands and asynchronous native events to Node.
src/addon.cpp - Rust N-API addon
rust/src/napi_addon.rs
Native SIP runtime
- SIP lifecycle orchestration · Manages endpoints, dialogs, registrations, requests, calls, and negotiation.
src/sip.cpp - Rust SIP core & FFI
rust/src/sip_core.rs - PJPROJECT · Provides SIP, SDP, RTP, and base media processing.
- SIP WebSocket transport
src/pjsip/src/pjsip/sip_transport_ws.c - Event normalization · Converts SIP and media callbacks into Node-facing event payloads.
src/event_templates.cpp - Stable ID manager · Correlates calls, streams, and operations across asynchronous events.
src/idmanager.cpp - Native bootstrap & logging
src/server.cpp
PJMEDIA extensions
- Chainlink media graph · Composes test media paths with WAV, tones, DTMF, fax, and correlation stages.
- Chainlink extension API
src/pjmedia/include/chainlink/chainlink.h - Custom media ports · Adds BFSK/DTMF, fax, TTS, and speech recognition ports.
- WebSocket speech port
src/pjmedia/src/pjmedia/ws_speech_port.cpp
Build & distribution
- Native build metadata
binding.napi.gyp - Prebuilt binary pipeline · Produces Debian/Ubuntu-compatible native binaries.
gen_prebuilds.sh - Ubuntu build containers
Other components
- External speech service · Optional WebSocket speech server and Google-backed speech integration.
Connections 22
- Node test scripts → Package entry points: loads
- Package entry points → N-API bindings: invokes
- Package entry points → Rust N-API addon: loads alternate addon
- N-API bindings → SIP lifecycle orchestration: issues SIP actions
- Rust N-API addon → Rust SIP core & FFI: calls
- SIP lifecycle orchestration → PJPROJECT: controls
- Rust SIP core & FFI → PJPROJECT: FFI access
- PJPROJECT → SIP WebSocket transport: extends with
- PJPROJECT → Event normalization: emits callbacks
- Event normalization → Stable ID manager: correlates with
- Event normalization → N-API bindings: asynchronous events
- Event normalization → Rust N-API addon: asynchronous events
- Native bootstrap & logging → SIP lifecycle orchestration: initializes
- PJPROJECT → Chainlink media graph: hosts media paths
- Chainlink extension API → Chainlink media graph: defines extension surface
- Chainlink media graph → Custom media ports: connects stages
- Custom media ports → WebSocket speech port: includes
- WebSocket speech port → External speech service: WebSocket audio
- Native build metadata → N-API bindings: builds legacy addon
- Native build metadata → Rust N-API addon: builds Rust addon
- Ubuntu build containers → Prebuilt binary pipeline: provide build environment
- Prebuilt binary pipeline → N-API bindings: packages binaries