varvideoElement=document.getElementsByTagName('video')[0];varchannel=phenix.Channels.createChannel({videoElement: videoElement,token: token,});channel.authorized.subscribe(function (authorized) {if (!authorized) {// Channel is unauthorized, skipping retry of start. Please provide a new token and invoke channel.start() }});channel.autoMuted.subscribe(function (autoMuted) {if (autoMuted) {// Show unmute button so a user-triggered action triggers channel.unmute() }});channel.autoPaused.subscribe(function (autoPaused) {if (autoPaused) {// Show play button so a user-triggered action triggers channel.play() }});
MediaStreamTrack API audio transform callback function. See Insertable Streams.
Creating an EdgeToken
To generate an EdgeToken you must have a channel ID or an alias.
Check out our EdgeAuth libraries and documentation for information on how to generate edge tokens on your backend. This is the recommended way to issue authentication tokens.
EdgeToken used to connect and authenticate to the platform and subscribe to a stream.
tokenExpiring
Observable(boolean)
Observable that returns tokenExpiring state.
videoElement
VideoElement
Video element that will show the stream.
Channel State
State
Code
Description
Developer Actions
Initializing
0
The initial state when the channel is created. The channel is being set up for operation.
Consider informing the user the stream is starting.
Offline
1
The channel is currently disconnected from the server. The channel will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
Starting
2
The channel is in the process of starting.
Consider informing the user the stream is starting.
Paused
3
The channel is paused. This can occur due to
User Action: user explicitly pauses playback using the SDK or the video player controls.(HLS/DASH).
Browser Restrictions: Browser limitations or security policies may prevent automatic playback.
Call channel.play()
Playing
4
The channel is actively playing content. This is the ideal state.
N/A
Recovering
5
The channel is attempting to recover from a temporary issue, such as a brief network interruption or a minor playback error. The channel will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
Reconnecting
6
The channel is reconnecting to the streaming server after a disconnection or due to network issues.
Consider informing the user a reconnect is in progress.
StandBy
7
The channel is waiting for a stream to become available. The channel will automatically transition to the Starting or Playing state when a stream becomes available.
Consider informing the user it's waiting for a stream.
Stopped
8
The channel has been stopped, either manually by the user or due to a system event (e.g., video element reset, token reset). If stopped manually, the user must call channel.start() to resume. If stopped due to a system event the channel will automatically attempt to reconnect.
Call channel.start() (if manually stopped)
Unauthorized
9
The provided token is invalid or expired. Obtain a new valid token and set it on the channel. The channel will automatically attempt to reconnect with the new token.
Obtain and set a new token
GeoRestricted
10
The user's location is restricted from accessing the stream. The user must change their location. No automatic reconnect is possible.
Check regions blocked/allowed against viewer's location. Consider informing user of issue in UI.
GeoBlocked
11
The user's location is explicitly blocked from accessing the stream. The user must change their location. No automatic reconnect is possible.
Check regions blocked/allowed against viewer's location. Consider informing user of issue in UI.
UnsupportedFeature
12
The requested feature is not supported by the current browser or configuration. Check browser compatibility and configuration settings. No automatic reconnect is possible.
Review and correct configuration. Consider informing the user an error occurred.
ConfigurationError
13
The channel configuration is invalid. Review and correct the configuration settings. No automatic reconnect is possible.
Review and correct configuration. Consider informing the user an error occurred.
TransientConfigurationError
14
The channel is attempting to recover from a temporary configuration issue. The channel will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
ConnectionError
15
The channel has encountered a connection error, such as a server timeout or network disruption. The channel will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
ClientStartError
16
The client failed to start the stream due to issues such as misconfigured parameters. The channel will automatically attempt to reconnect.
Review console logs for more details. Consider informing the user a reconnect is in progress.
Error
17
A general error has occurred. Check error logs for more details. Consult the SDK documentation for further assistance. The channel will automatically attempt to reconnect.
Check error logs and consult Phenix team. Consider informing the user an error occurred.
letpublisher;navigator.mediaDevices.getUserMedia({video: true,audio: true}) .then(mediaStream=> {publisher=phenix.Publishers.createPublisher({mediaStream,token });publisherStateObservable=publisher.state.subscribe(function(state) {// Subscribe to publisher state to observe }); });
Options to publish to use when publishing to the channel
Create Publisher Options
Name
Type
Default Value
Description
mediaStream (required)
MediaStream
A stream of media content.
token (required)
String
PublishToken used to connect and authenticate to the platform and publish a stream.
name (optional)
String
randomly-generated value
The name of the stream.
Creating a PublishToken
To generate a PublishToken you must have a channel ID or an alias.
Check out our EdgeAuth libraries and documentation for information on how to generate edge tokens on your backend.
This is the recommended way to issue authentication tokens.
PublishToken used to connect and authenticate to the platform and publish a stream.
tokenExpiring
Observable(boolean)
Observable that returns tokenExpiring state.
mediaStream
Observable(MediaStream)
A stream of media content.
Publisher State
State
Code
Description
Developer Actions
Initializing
0
The initial state when the publisher is created. The publisher is setting up for operation.
Consider informing the user the stream is starting.
Offline
1
The publisher is disconnected from the server. The publisher will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
Starting
2
The publisher is in the process of starting.
Consider informing the user the stream is starting.
Publishing
3
The publisher is actively publishing content. This is the ideal state.
N/A
Recovering
4
The publisher is attempting to recover from a temporary issue, such as a brief network interruption or a minor playback error. The publisher will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
Reconnecting
5
The publisher is reconnecting to the streaming server after a disconnection or due to network issues.
Consider informing the user a reconnect is in progress.
Stopped
6
The publisher has been stopped, typically due to user action (e.g., calling the stop() method) or critical conditions requiring a full restart.
Call start() (if manually stopped)
Unauthorized
7
The provided token is invalid or expired. Obtain a new valid token and set it on the publisher. The publisher will automatically attempt to reconnect with the new token.
Obtain and set a new token
GeoRestricted
8
The user's location is restricted from publishing the stream. The user must change their location. No automatic reconnect is possible.
Check regions blocked/allowed against publisher's location. Consider informing user of issue in UI.
GeoBlocked
9
The user's location is explicitly blocked from publishing the stream. The user must change their location. No automatic reconnect is possible.
Check regions blocked/allowed against publisher's location. Consider informing user of issue in UI.
UnsupportedFeature
10
The requested feature is not supported by the current browser or configuration. Check browser compatibility and configuration settings. No automatic reconnect is possible.
Review and correct configuration. Consider informing the user an error occurred.
NotFound
11
The requested channel for the publisher was not found. The publisher will automatically attempt to reconnect.
Check the channel configured in the token and verify the channel availability
ConfigurationError
12
The publisher configuration is invalid. Review and correct the configuration settings. No automatic reconnect is possible.
Review and correct configuration
TransientConfigurationError
13
The publisher is attempting to recover from a temporary configuration issue. The publisher will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
ConnectionError
14
The publisher has encountered a connection error, such as a server timeout or network disruption. The publisher will automatically attempt to reconnect.
Consider informing the user a reconnect is in progress.
ClientStartError
15
The client failed to start the publishing stream due to issues such as misconfigured parameters. The publisher will automatically attempt to reconnect.
Review console logs for more details. If reconnect does not work check the validity of the provided media stream
Error
16
Publisher is not able to publish to stream due to a general failed to publish.
Check error logs and consult Phenix team. Consider informing the user an error occurred.
UNIX timestamp of the last known packet sent described by the candidate pair, not including STUN packets.
ssrc
Number
An integer which uniquely identifies the source of the RTP stream.
mediaType
String
Kind/Media type of the stream.
timestamp
Number
UNIX time stamp of when the statistics is captured.
bitrate
Number
The number of bits per second that can be transmitted.
bytesSent
Number
Bytes sent.
packetsSent
Number
Packets sent.
retransmittedBytesSent
Number
Total number of frames decoded successfully for this media source.
codec
String
Codec used to decode data.
roundTripTime
Number
Round Trip Time of the webRTC connection.
RtcPublishStatistic Video Object
Property
Type
Description
lastPacketSentTimestamp
Number
UNIX timestamp of the last known packet sent described by the candidate pair, not including STUN packets.
ssrc
Number
An integer which uniquely identifies the source of the RTP stream.
mediaType
String
Kind/Media type of the stream.
timestamp
Number
UNIX time stamp of when the statistics is captured.
bitrate
Number
The number of bits per second that can be transmitted.
bytesSent
Number
Bytes sent.
packetsSent
Number
Packets sent.
retransmittedBytesSent
Number
Total number of frames decoded successfully for this media source.
firCount
Number
The number of Full Intra Request (FIR) packets sent from the receiver to the sender.
frameHeight
Number
Frame height.
frameWidth
Number
Frame width.
framesEncoded
Number
Frames encoded.
framesSent
Number
Frames sent.
headerBytesSent
Number
Total number of RTP header and padding bytes sent for this SSRC.
hugeFramesSent
Number
The total number of huge frames sent by this RTP stream.
pliCount
Number
Total number of Picture Loss Indication (PLI) packets.
qpSum
Number
The sum of the QP values of frames decoded by this receiver.
totalEncodeTime
Number
Total number of seconds spent encoding this stream's framesEncoded frames.
totalEncodedBytesTarget
Number
This value is increased by the target frame size in bytes every time a frame has been encoded. The actual frame size may be bigger or smaller than this number.