Requirements • Usage • Examples • Building locally • Logs • Documentation • Contribution • License
This library addresses common challenges faced by developers:
[!CAUTION]
By default, TURN is enabled to ensure nearly universal connectivity. However, this comes with trade-offs: relaying adds latency, and TCP/TLS can perform poorly under network congestion, causing video to slow down or freeze. You can disable TURN by specifying your own Connect.Params.iceServer in Streamer.start and Player.start methods to override the default settings.
Download and install npm from https://nodejs.org/en/download
To create a Stream, you will need a Ceeblue account on Ceeblue Cloud API or Ceeblue Dashboard. A trial account is sufficient. If you do not have one yet, you can request one on the Ceeblue website.
To use this library you'll first need to create a stream either through Ceeblue Cloud API or via the Ceeblue Dashboard. Use the Quick Start Guide for fast results.
Once the stream is created, retrieve its <endpoint>
from the API in the signallingUri
field. The value takes the following form, with an in+
prefix when the stream is transcoded, or as+
when it is not:
wss://<hostname>/webrtc/in+12423351-d0a2-4f0f-98a0-015b73f934f2
[!IMPORTANT]
By default, we use
wss
(WebSocket over TLS) for signaling, as it enables advanced features such as adaptive bitrate (ABR). However, you can usehttps
for WHIP and WHEP if you don’t need these additional features or require compatibility with other systems.
You will also need the WebRTC <endpoint>
for playback, which is provided from API in the uri
field. The value takes the following form, with an out+
prefix when the stream is transcoded, or as+
when it is not:
wss://<hostname>/webrtc/out+12423351-d0a2-4f0f-98a0-015b73f934f2
[!NOTE]
From Ceeblue Dashboard you can create an output
WebRTC endpoint
by clicking on the Viewer's eye 👁 button.
Add the library as a dependency to your project using:
npm install @ceeblue/webrtc-client
Then import the library into your project with:
import * as WebRTC from '@ceeblue/webrtc-client';
[!TIP]
If your project uses TypeScript, it is recommended to set
"target": "ES6"
in your configuration to align with our usage of ES6 features and ensures that your build will succeed.
Set"moduleResolution": "Node"
in tsconfig.json to ensure TypeScript resolves imports correctly for Node.js.{
"compilerOptions": {
"target": "ES6",
"moduleResolution": "Node"
}
}If you require a backwards-compatible UMD version, we recommend building it locally.
To publish a stream use the Streamer class with the <endpoint>
you saved while creating the stream. A complete example is available in streamer.html under Examples.
import { Streamer } from '@ceeblue/webrtc-client';
const streamer = new Streamer();
streamer.onStart = stream => {
console.log('start streaming');
}
streamer.onStop = _ => {
console.log('stop streaming');
}
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true });
streamer.start(stream, {
endPoint: 'wss://<hostname>/webrtc/in+12423351-d0a2-4f0f-98a0-015b73f934f2'
});
[!NOTE]
For complete details on the connection parameters, see the Connect.Params type in web-utils project.
To play the stream use the Player class with the WebRTC <endpoint>
you saved while creating the stream. A complete example is available in player.html under Examples.
import { Player } from '@ceeblue/webrtc-client';
const player = new Player();
player.onStart = stream => {
videoElement.srcObject = stream;
console.log('start playing');
}
player.onStop = _ => {
console.log('stop playing');
}
player.start({
endPoint: 'wss://<hostname>/webrtc/out+12423351-d0a2-4f0f-98a0-015b73f934f2'
});
[!NOTE]
For complete details on the connection parameters, see the Connect.Params type in web-utils project.
To help you get started, we provide the following examples:
[!TIP]
To serve the examples locally, run a static http-server in the project directory:
npx http-server . -p 8081
Open the streamer in your browser, with the WebRTC <endpoint>
you saved while creating the stream.
http://localhost:8081/examples/streamer.html?endPoint=<endPoint>
Click on Start streaming. The live stream from your webcam will start.
If your browser requests permission to access your camera, make sure to grant it.
Open a separate browser window and go to the player URL below, using the same WebRTC <endpoint>
.
http://localhost:8081/examples/player.html?endPoint=<endPoint>
Click Play to start watching the live stream.
webrtc-client
folder and run npm install
to install packages dependencies.npm run build
. The output will be the following files placed in the /dist/ folder:git clone https://github.com/CeeblueTV/webrtc-client.git
cd webrtc-client
npm install
npm run build
[!NOTE]
Each JavaScript file is accompanied by a minified
min.js
version and a.map
source map file
[!TIP]
By default, the project format is ES module.
However, you can build the project for the supported module systems (CommonJS or IIFE) using the following commands:npm run build:cjs
npm run build:iifeThe default target is ES6.
If you want to manually test other targets (even though they are not officially supported), you can experiment with:npm run build -- --target esnext
npm run build:cjs -- --target esnextRun the watch command to automatically rebuild the bundles whenever changes are made:
npm run watch
If you prefer to watch and build for a specific target, use one of the following commands:
npm run watch:cjs
npm run watch:iife
WebRTC uses the Log Engine of web-utils project.
There are four log levels:
LogLevel.ERROR
- Unrecoverable errorLogLevel.WARN
- Error which doesn't interrupt the current operationLogLevel.INFO
- Informational messages at a frequency acceptable in productionLogLevel.DEBUG
- High-frequency messages intended for debuggingBy default, only LogLevel.ERROR
is enabled. To change the level, use the following approach:
import { utils } from '@ceeblue/webrtc-client';
const { log, LogLevel } = utils;
log.level = LogLevel.INFO; // displays errors, warns and infos
To disable all logging, use this approach:
import { utils } from '@ceeblue/webrtc-client';
const { log, } = utils;
log.level = false; // suppresses all log output, the opposite `true` value displays all the logs
[!IMPORTANT]
Beyond basic filtering, the Log Engine of the web-utils project also provides advanced features such as subscription, interception, redirection, and log redefinition.
You can find the latest built-in API documentation here:
https://ceebluetv.github.io/webrtc-client/
To build the documentation locally, run:
npm run build:docs
This generates documentation files, which you can view by opening ./docs/index.html
.
[!TIP]
To serve the documentation locally, run a static http-server in the
./docs/
directory:npx http-server . -p 8081
You can then access the documentation at http://localhost:8081/.
All contributions are welcome. Please see our contribution guide for details.
By contributing code to this project, you agree to license your contribution under the GNU Affero General Public License.
Generated using TypeDoc