- Issues and new features
- Reading the current code
- Creating a branch
- Code style
- Starting the demo page
- Creating a commit
- The test suite
- Documentation
- Opening a pull request
If you detect a problem with the RxPlayer, or if you desire a new feature, please first open an issue on the github's repository. We'll try to acknowledge it as soon as possible.
If that issue is not already worked on, we will usually accept pull requests. Those have to follow the conventions defined below.
Even if we hope the current code is straightforward, readable and commented enough we can still admit that going blind into the codebase can be hard at first (as it would be for any non-small codebase).
We thus encourage you to rely on the architecture documentation
(note: this page is updated with each new version. For any older version, it can
also be found in the doc/architecture/
directory, in the markdown format).
A good place to start would be the file organization of the project .
The code of the RxPlayer being heavily modularized, you should not need to read the whole documentation to be ready, only the parts you want to update (hopefully!).
We follow a strict convention for branch names. They are usually under this
form: type/alias_for_the_fix
.
This strictness mostly helps us to quickly rememorate what each PR or merged branch is/was about.
The type should be one of the following:
fix
: For bug fixesfeat
: For new features to the RxPlayerdoc
: For documentation updatesdemo
: For demo improvements/fixestests
: For tests improvements/fixescode
: For refactoring code which brings no fix or no new featuretools
: For improvements related to the RxPlayer's toolsmisc
: For unclassifiable other improvements
The alias
should be descriptive enough to understand roughly what is the
impacted code.
Examples:
fix/dash-minimum_position
fix/webm-duration_calculation
fix/ttml-background_color
feat/dash-utc_timing
code/manifest_as_event_emitter
tests/eme-attach_media_keys
tools/webpack-4
doc/public_api_typos
The code style in src
is automatically checked by a "linter", tslint
.
It basically follows those principles:
- 2 spaces indentation
- 90 columns maximum
- optimize your code for readability
You can easily check if you followed our style rules by calling npm run lint
.
You can also check the style of the demo page (in the demo
directory) by
calling npm run lint:demo
, or the style of the test files (in the tests
directory) by calling npm run lint:tests
.
We try to be as strict as possible with types:
-
the
any
type should be avoided -
the
as
keyword should also be avoided as much as possible. -
the
is
keyword is fine in some situations, but simpler solutions should be preferred.
This is to be sure we can detect as much as possible type errors automatically with TypeScript.
Also, created TypeScript's type
and interface
should all be named beginning
with the letter I, for easier identification purposes.
Some native functions, methods or classes should never be used to ensure compatibility with every browsers. To work around those, we usually rely on "ponyfills" which are JavaScript re-implementations.
This concerns the following static methods:
Object.assign
: usesrc/utils/object_assign.ts
insteadObject.values
: usesrc/utils/object_values.ts
instead
The following methods:
Array.prototype.includes
: usesrc/utils/array_includes.ts
insteadArray.prototype.find
: usesrc/utils/array_find.ts
insteadArray.prototype.findIndex
: usesrc/utils/array_find_index.ts
insteadString.prototype.startsWith
: usesrc/utils/starts_with.ts
insteadString.prototype.substr
: useString.prototype.substring
insteadNodeList.prototype.forEach
: use a regular for loop instead
The following class:
Promise
: usesrc/utils/promise.ts
instead
You might want to quickly test your code modification(s) on a real use case.
For those types of need, we developped two demo pages:
-
the full demo page, which is also the one used to showcase the player.
This demo has a user-friendly interface and allow the most frequent API interactions.
It also exposes both the RxPlayer class through
window.RxPlayer
and the rxPlayer instance throughwindow.rxPlayer
- both in the global scope. You can thus open a debugger/inspector in your favorite browser to exploit directly the player's API. -
the standalone demo page, which is just a
<video />
tag linked to a RxPlayer instance.In this demo too,
window.RxPlayer
andwindow.rxPlayer
link to the RxPlayer class and the rxPlayer instance respectively.
To use the full demo page, you can build it and run a local HTTP server on the port 8000 by running the following npm script.
npm run start
To use the standalone demo page, you can build it and run a local HTTP server on the port 8001 by running the following npm script.
npm run standalone
Both will detect when the RxPlayer's files (or even the demo files) are updated and perform a new build when that's the case. In that way, the server will always serve the last local version of the code.
You might want to serve the demo via HTTPS. This is for example needed to be able to play encrypted contents in Chrome.
Thankfully, we have an npm script which generates a local self-signed
certificate with the help of openssl
:
npm run certificate
You can then run the same demo script defined previously. The full demo will now serve HTTPS through the port 8443 and the standalone demo through the port 8444. Both still serve HTTP on the same ports than before.
Note that such self-signed certificates are usually (rightfully) considered suspicious by web browsers. As such, you might first encounter a warning screen when going to one of the demo pages in HTTPS. In most browsers, you can however safely ignore that warning.
Every commits in a PR should pass our quick checks (linter, typescript check
and unit tests). To check if that's the case, you can run locally the check
script by calling npm run check
.
In any case, the type checking and linting of the src
directory is
automatically done before each commit thanks to a git hook.
Those checks give us some guarantees that every merged commit in the master
branch is stable enough.
This gives us more confidence on our code and also allows more advanced debugging if we detect a regression by the usage of tools such as git-bisect.
We have a naming convention for commits, roughly under the form:
namespace: what the commit does
.
Adding a paragraph (by setting multiple -m
options to git-commit for
example) to explain why you did those modifications is preferred.
The namespace
here describe here the area of the code the commit modifies.
It usually is one of the following:
abr
api
bif
buffers
compat
dash
eme
errors
fetchers
init
isobmff
manifest
matroska
sami
scripts
smooth
source-buffers
srt
subtitles
tests
ttml
utils
webvtt
But it could be any other values you feel to be consistent with that convention.
This namespace helps us quickly evaluate the area of the code a commit impact, to easily evaluate where testing need to be done and to better detect a problematic commit if a regression is detected.
Unit tests test function implementations. Mostly to check if they give a sane output for every input given.
Writing unit tests for new code is encouraged.
Unit tests are written in a __tests__ directory, itself created in the same directory that the code it tests.
They are written with the help of the Jest library and are named the following
way: filename_containing_the_function_tested.test.ts
.
To understand how to create a new test file, you can take inspiration from the current unit tests.
What we call integration tests are tests testing the entire API of the RxPlayer.
New integration tests are not required when a new code is added. Just make sure
that all those tests pass before doing a pull request by running:
npm run test:integration
.
It you want to improve our integration tests, you are welcome to do so.
Those are wrote in tests/integration
with the help of the Mocha, Chai and
Sinon libraries.
We also use a homemade library and server to serve media contents to our tests. If you want to know how it works, we invite you to rely on the already created tests and to read the corresponding files.
Memory tests replicate simple scenarios and try to detect memory leaks.
You can also help us improving our memory tests. Those are written in
test/memory
. The testing stack used is Mocha, Chai and Sinon.
The documentation is written in the doc
directory, at the root of the project.
The content of doc/generated
contains an HTML version of the Markdown files
written in the other directories. It is automatically generated from those by
calling the doc
script through npm run doc
.
Before doing a Pull Request, please ensure that all integration tests pass by
calling npm run test:integration
.
Then, please call npm run test:memory
, which tests for memory leaks.
Pull requests for bug fixes, new tests or documentation should be done on the
master
branch.
Pull requests for new features and breaking changes will have to be performed
on the next
branch.
If you don't know on which branch to do a pull request, please open it on
master
, we will know how to redirect it to the right one.