Ant-Media-Server icon indicating copy to clipboard operation
Ant-Media-Server copied to clipboard

Using React Player Results in Incorrect HLS Viewer Count

Open lastpeony opened this issue 1 year ago • 1 comments

When playing HLS, it keeps reconnecting internally. So this viewers count is not correct. It shows 5+ for one viewer only. React Player image

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

lastpeony avatar Oct 20 '23 08:10 lastpeony

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
        }
      }
    }
  }}
/>

geneukum avatar May 14 '24 21:05 geneukum

Many thanks @geneukum for the solution.

burak-58 avatar May 20 '24 09:05 burak-58

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

mekya avatar Jun 24 '24 10:06 mekya