Fork me on GitHub
Using janus.js as JavaScript module

To facilitate integration of janus.js within modular JavaScript code bases, you can instruct the build system(s) to generate a modular variants of janus.js. Generated modules may then be copied to your own JavaScript projects and seamlessly integrated with your own project's build system.

Building the modules can be done in two ways:

  1. As part of a regular build of the Janus WebRTC Server, using make, by enabling the integrated support via configure
  2. By running NPM commands manually. This may be useful if you are looking to build just the JavaScript modules without incurring the overhead of a full build of Janus.

Building modules using make

Each supported variant may be enabled by passing a corresponding –enable-javascript-*-module flag (with or without a =yes directive) to configure before invoking make to build Janus. Please note: if you do not pass any such flag, by default no modules will be built.

The following table provides a summary of available module formats and their corresponding configure options:

Module format (syntax)File nameconfigure flag to pass
ECMAScriptjanus.es.js–enable-javascript-es-module
Universal Module Definition (UMD)janus.umd.js–enable-javascript-umd-module
CommonJSjanus.cjs.js–enable-javascript-common-js-module
Immediately Invoked Function Expression (IIFE)janus.iife.js–enable-javascript-iffe-module

The –enable-all-js-modules shortcut is available, in case you want to enable and build them all.

When built and installed, these module variants may be found in the $PREFIX/share/janus/javascript folder, alongside the janus.js file itself (assuming $PREFIX the installation directory passed to configure).

Note
Building the JavaScript modules still requires NPM and may involve an install which means npm must be able to download dependencies. By default configure will attempt to auto-detect available npm on your PATH, but if you have installed NPM outside the PATH you can override this by passing the (full) path to your npm executable, e.g.:
./configure NPM=/path/to/my/custom/npm --enable-javascript-es-module=yes

Building modules manually with NPM

You can also opt to build modules by invoking npm manually. The npm subdirectory contains the necessary configuration files to get you started:

cd ./npm
npm install
npm run rollup -- --o /path/to/desired/output/file-name.js --f cjs # or es, iffe, umd, amd, ...

Using npm directly is useful if you want to build the JavaScript modules only, without building Janus itself or if you are looking for advanced customisation options or alternative formats which are not integrated in configure yet. As you may have surmised from the example command, the actual build consists mostly of invoking rollup with the correct parameters. For more information on available parameters, please refer to the rollup documentation:

  1. https://rollupjs.org/#command-line-flags
  2. https://rollupjs.org/#configuration-files