Ant-Media-Server
Ant-Media-Server copied to clipboard
Using React Player Results in Incorrect HLS Viewer Count
When playing HLS, it keeps reconnecting internally. So this viewers count is not correct.
It shows 5+ for one viewer only.
React Player
possible solution: Investigate react player code and configuration, modify it to work as hls.js so viewer count will be normal. document it accordingly because its a widely used player. should be able to fix without changes on server side
I just ran into this today when trying to use that same react player in my application.
Admittedly I'm a brand new user of AMS, but my understanding is that it is using cookies to uniquely identify each user watching the live stream. In my particular case, since the AMS instance is running on a different origin server than my app, I needed to set the withCredentials
property in order to allow the browser to include that cookie in the XHR request.
Here's an example of what that looks like with ReactPlayer
:
<ReactPlayer
url={url}
config={{
file: {
hlsOptions: {
xhrSetup: function(xhr) {
xhr.withCredentials = true // send cookies
}
}
}
}}
/>
Many thanks @geneukum for the solution.
Thank you @geneukum.
I've also sent a connection request to you on LinkedIn. Keep in touch.
Btw, I'm closing this issue and please feel free to re-open if you think differently
Cheers Oz