This document is intended for mediasoup developers.
The package.json
file in the main folder includes the following scripts:
Compiles mediasoup TypeScript code (node/src
folder) JavaScript and places it into the node/lib
directory.
Compiles mediasoup TypeScript code (node/src
folder) JavaScript, places it into the node/lib
directory an watches for changes in the TypeScript files.
Builds the mediasoup-worker
binary. It invokes invoke
below.
Creates a prebuilt of mediasoup-worker
binary in the worker/prebuild
folder.
Runs both npm run lint:node
and npm run lint:worker
.
Validates mediasoup JavaScript files using ESLint.
Validates mediasoup worker C++ files using clang-format. It invokes invoke lint
below.
Runs both npm run format:node
and npm run format:worker
.
Format TypeScript and JavaScript code using Prettier.
Rewrites mediasoup worker C++ files using clang-format. It invokes invoke format
below.
Runs both npm run flatc:node
and npm run flatc:worker
.
Compiles FlatBuffers .fbs
files in worker/fbs
to TypeScript code.
Compiles FlatBuffers .fbs
files in worker/fbs
to C++ code.
Runs both npm run test:node
and npm run test:worker
.
Runs Jest test units located at node/test
folder.
Jest command arguments can be given using --
as follows:
npm run test:node -- --testPathPattern "test-Worker.ts" --testNamePattern "createWorker"
Runs Catch2 test units located at worker/test
folder. It invokes invoke test
below.
Same as npm run test:node
but it also opens a browser window with JavaScript coverage results.
Runs linters and tests in Node and C++ code.
The only special feature in Rust case is special environment variable "KEEP_BUILD_ARTIFACTS", that when set to "1" will allow incremental recompilation of changed C++ sources during hacking on mediasoup.
It is not necessary for normal usage of mediasoup as a dependency.
mediasoup uses Python Invoke library for managing and organizing tasks in the worker
folder (mediasoup worker C++ subproject). Invoke
is basically a replacemente of make
+ Makefile
written in Python. mediasoup automatically installs Invoke
in a local custom path during the installation process (in both Node and Rust) so the user doesn't need to worry about it.
Tasks are defined in worker/tasks.py
. For development purposes, developers or contributors can install Invoke
using pip3 install invoke
and run tasks below within the worker
folder.
See all the tasks by running invoke --list
within the worker
folder.
NOTE: For some of these tasks to work, npm dependencies of worker/scripts/package.json
must be installed:
npm ci --prefix worker/scripts
Alias of invoke mediasoup-worker
task below.
Installs meson
and ninja
into a local custom path.
Cleans built objects and binaries.
Cleans built objects and other artifacts, but keeps mediasoup-worker
binary in place.
Cleans meson
and ninja
installed in local prefix with pip.
Cleans subprojects downloaded with Meson.
Cleans built objects and binaries, meson
and ninja
installed in local prefix with pip and all subprojects downloaded with Meson.
Updates the wrap file of a subproject (those in worker/subprojects
folder) with Meson. After updating it, invoke setup
must be called by passing MESON_ARGS="--reconfigure"
environment variable. Usage example:
cd worker
invoke update-wrap-file openssl
MESON_ARGS="--reconfigure" invoke setup
Builds the mediasoup-worker
binary at worker/out/Release
.
If the "MEDIASOUP_MAX_CORES" environment variable is set, the build process will use that number of CPU cores. Otherwise it will auto-detect the number of cores in the machine.
"MEDIASOUP_BUILDTYPE" environment variable controls build types, "Release" and "Debug" are presets optimized for those use cases. Other build types are possible too, but they are not presets and will require "MESON_ARGS" use to customize build configuration.
Check the meaning of useful macros in the worker/include/Logger.hpp
header file if you want to enable tracing or other debug information.
Binary is built at worker/out/MEDIASOUP_BUILDTYPE/build
.
In order to instruct the mediasoup Node.js module to use the "Debug" mediasoup-worker` binary, an environment variable must be set before running the Node.js application:
MEDIASOUP_BUILDTYPE=Debug node myapp.js
If the "MEDIASOUP_WORKER_BIN" environment variable is set (it must be an absolute file path), mediasoup will use the it as mediasoup-worker
binary and won't compile the binary:
MEDIASOUP_WORKER_BIN="/home/xxx/src/foo/mediasoup-worker" node myapp.js
Builds the libmediasoup-worker
static library at worker/out/Release
.
"MEDIASOUP_MAX_CORES"` and "MEDIASOUP_BUILDTYPE" environment variables from above still apply for static library build.
Builds a Xcode project for the mediasoup worker subproject.
Validates mediasoup worker C++ files using clang-format and rules in worker/.clang-format
.
Rewrites mediasoup worker C++ files using clang-format.
Builds and runs the mediasoup-worker-test
binary at worker/out/Release
(or at worker/out/Debug
if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug"), which uses Catch2 to run test units located at worker/test
folder.
Run test with Address Sanitizer with -fsanitize=address
.
Run test with Address Sanitizer with -fsanitize=undefined
.
Run test with Address Sanitizer with -fsanitize=thread
.
Runs clang-tidy and performs C++ code checks following worker/.clang-tidy
rules.
Requirements:
invoke clean
andinvoke mediasoup-worker
must have been called first.- clang-tools-extra is required.
- In OSX install it with
brew install llvm
. - In linux the package name is
clang-tools-extra
.
- In OSX install it with
Environment variables:
- "MEDIASOUP_TIDY_CHECKS": Comma separated list of checks. Overrides the checks defined in
worker/.clang-tidy
file. - "MEDIASOUP_TIDY_FILES": Space separated source files to process, including their path. All
.cpp
files will be processes by default. - "MEDIASOUP_CLANG_TIDY_DIR": Path to directory containing clang tools (
run-clang-tidy
,clang-tidy
,clang-apply-replacements
).
Usage example in macOS:
MEDIASOUP_CLANG_TIDY_DIR=/usr/local/opt/llvm/bin invoke tidy
Builds the mediasoup-worker-fuzzer
binary (which uses libFuzzer) at worker/out/Release
(or at worker/out/Debug/
if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug").
Requirements:
- Linux with fuzzer capable clang++.
- "CC" environment variable must point to
clang
. - "CXX" environment variable must point to
clang++
.
Read the Fuzzer documentation for detailed information.
Runs all fuzzer cases.
Builds a Linux Ubuntu Docker image with fuzzer capable clang++ and all dependencies to run mediasoup.
NOTE: Before running this command, a specific version of Linux clang must be downloaded. To get it, run:
cd worker
scripts/get-dep.sh clang-fuzzer
Runs a container of the Ubuntu Docker image created with invoke docker
. It automatically executes a bash
session in the /mediasoup
directory, which is a Docker volume that points to the mediasoup root folder.
NOTE: To install and run mediasoup in the container, previous installation (if any) must be properly cleaned by entering the worker
directory and running invoke clean-all
.
Builds a Linux Alpine Docker image with all dependencies to run mediasoup.
Runs a container of the Alpine Docker image created with invoke docker-alpine
. It automatically executes an ash
session in the /mediasoup
directory, which is a Docker volume that points to the mediasoup root folder.
NOTE: To install and run mediasoup in the container, previous installation (if any) must be properly cleaned by entering the worker
directory and running invoke clean-all
.
The worker
folder contains a Makefile
file for the mediasoup worker C++ subproject. It acts as a proxy to the Invoke
tasks defined in tasks.py
. The Makefile
file exists to help developers or contributors that prefer keep using make
commands.
All tasks defined in tasks.py
(see above) are available in Makefile
. There is only one exception:
- The
update-wrap-file
needs a "SUBPROJECT" environment variable indicating the subproject to update. Usage example:cd worker make update-wrap-file SUBPROJECT=openssl