Constructs a new Player instance, optionally with a custom connector
This doesn't start the playback, you must call Player.start method
By default if no connector is indicated it uses a WSController (WebSocket IController)
excepting if Connect.Params.endPoint is prefixed with a http:// protocol in such case it uses
instead a HTTPConnector (HTTP IConnector). To force a HTTPConnector build explicitly
with HTTPConnector as Connector argument.
Optional Connector: (new (connectParams) => IConnector)Connector class to use for signaling, or nothing to let's Player.start method determines it automatically.
// Default build
const player = new Player();
player.start({
endPoint: address, // if address is prefixed by `http://` it uses a HTTPConnector (HTTP-WHIP), otherwise it uses a WSController (WebSocket)
streamName: 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'
});
// Force connector selection whatever the address used in endPoint
const player = new Player(isWHIP ? HTTPConnector : WSController);
player.start({
endPoint: address, // optional protocol prefix has no incidence on connector selection
streamName: 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'
})
Private Optional ConnectorConnector class to use for signaling, or nothing to let's Player.start method determines it automatically.
Private Optional _audioPrivate Optional _audioPrivate Optional _connectorPrivate Optional _controllerPrivate _dataPrivate Optional _metadataPrivate Optional _playingPrivate Optional _streamPrivate Optional _streamPrivate Optional _streamPrivate Optional _streamPrivate Optional _videoPrivate Optional _videoStart a log
a Log object with the levels of log to call
Index of the audio track, can be undefined if player is not playing
Sets the current audio track to the index provided, it can be set before calling Player.start
to select the initial audio track, or set after Player.start to fix track and disable MBR
While playing you can set it to undefined to activate MBR when session is controllable
Returns the IConnector instance, or undefined if stream is not starting.
Returns the IController instance when starting with a connector with controllable ability, or undefined if stream is not starting or stream is not controllable.
The list of tracks currently receiving
Set the data track ids to receive
Last playing information, such as current position and playback buffer bounds See PlayingInfos
Returns true when player is running (between a Player.start and a Player.stop)
Playable media stream as specified by MediaStream
Stream name, for example as+bc3f535f-37f3-458b-8171-b4c5e77a6137
State of the stream as indicated by the server
Index of the video track, can be undefined if player is not playing
Sets the current video track to the index provided, it can be set before calling Player.start
to select the initial video track, or set after Player.start to fix track and disable MBR
While playing you can set it to undefined to activate MBR when session is controllable
Private _initPrivate _newPrivate _updateReturns connection info, such as round trip time, requests sent and received, bytes sent and received, and bitrates NOTE: This call is resource-intensive for the CPU.
A promise for a ConnectionInfos
Event subscription
Name of event without the on prefix (ex: log to onLog event declared)
Subscriber Function
Optional options: { Optional signal?: AbortSignalOptional AbortSignal to stop this or multiple subscriptions in same time
Event subscription only one time, once time fired it's automatically unsubscribe
Name of event without the on prefix (ex: log to onLog event declared)
Subscriber Function
Optional options: { Optional signal?: AbortSignalOptional AbortSignal to stop this or multiple subscriptions in same time
Starts playing the stream The connector is determined automatically from Connect.Params.endPoint if not forced in the constructor.
Instead to use a Connect.Params you can prefer use a already built StreamMetadata instance to the same end-point, it allows to discover tracks in amount and initialize track selection to start playback.
The multiBitrate option can take three different types of value:
{}undefined to disable MBR managementIn addition you can disable MBR while playing by set audio or video track to an explicit value (Player.videoTrack and Player.audioTrack).
Connection parameters or a StreamMetadata object already connected to the same end-point Note that if you pass a StreamMetadata object its life-time management is fully delegated to the Player
Multi-bitrate implementation or MBRParams to configure the default implementation
// Default start with MBR activated
player.start({
endPoint: address,
streamName: 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'
});
// Start with selected initial track, in using a StreamMetadata object preinitialized
const streamMetadata = new StreamMetadata({
endPoint: address,
streamName: 'as+bc3f535f-37f3-458b-8171-b4c5e77a6137'
});
streamMetadata.onMetadata = metadata => {
// start to play with higher bitrate selection (audios and videos are sorted by descending BPS)
player.audioTrack = metadata.audios[0].idx;
player.videoTrack = metadata.videos[0].idx;
// give the streamMetadata channel to reuse instead of opening a new again
player.start(streamMetadata);
// Now MBR select automatically the best tracks regarding network congestion
...
// Fix audioTrack to the high rendition (disable MBR for audio track)
player.audioTrack = 1;
...
// Reactivate MBR for audio
player.audioTrack = undefined;
}
Stops playing the stream
Optional error: PlayerErrorerror description on an improper stop
Event fired when metadata is present in the stream
Event fired every second to report information while content plays
Event fired when stream state is changing
Event fired when streaming stops
Optional error: PlayerErrorerror description on an improper stop
Generated using TypeDoc
Use Player to start playing a WebRTC stream. You can use a controllable version using a
WSControlleras connector, or change it to use aHTTPConnector(HTTP WHEP). By default it uses aWSControllerexcepting if on Player.start you use a Connect.Params.endPoint prefixed with ahttp://protocol. With a controllable connector you can change track during the playback, what is not possible with a HTTP(WHEP) connector.In addition then a player with a controllable connector uses a MultiBitrate algorithm to switch track automatically regarding network congestion. You can disable it and fix manually a track by selecting it after a start call. At last it's possible to indicate which are tracks to play in first by setting audio and video tracks before start call. In this case it can be usefull to get metadata information about the stream before to play it, see Player.start to achieve it.
Example