srs icon indicating copy to clipboard operation
srs copied to clipboard

Need current number of client in on_play/on_stop webhook body.

Open nguyencobap opened this issue 1 year ago • 3 comments

I think it's neccessary for having current number of client in on_play/on_stop webhook body. I have service that start run ffmpeg to publish stream when have client start play. If there is another plays then I do not start ffmpeg anymore. When the last client stop and I stop ffmpeg publishing. So to know the first client start stream and last client stop stream I need to know current number of client.

Thank you!

nguyencobap avatar Aug 19 '24 04:08 nguyencobap

maybe you can check if the ffmpeg proccess is already started, and if is already estarted not start a new one? regards.

TagorePde avatar Aug 19 '24 14:08 TagorePde

maybe you can check if the ffmpeg proccess is already started, and if is already estarted not start a new one? regards.

Your solution is ok with playing flow but stopping flow is not working. How can I know the last client stops stream so I can kill ffmpeg process without know number of client?

nguyencobap avatar Aug 19 '24 16:08 nguyencobap

using this?: http://ip:1985/api/v1/clients/?count=100 or this: http://ip:1985/api/v1/streams/?count=100 maybe?

TagorePde avatar Aug 19 '24 19:08 TagorePde

Implemented in v7.0.107

This feature has been implemented. The clients field is now available in:

  1. Webhooks (on_play/on_stop): Shows the current number of clients for the stream

    {
      "action": "on_play",
      "clients": 3,
      ...
    }
    
  2. HTTP API (/api/v1/streams): Added total field for total stream count

    {
      "total": 10,
      "streams": [...]
    }
    
  3. HTTP API (/api/v1/clients): Added total field for total client count

    {
      "total": 25,
      "clients": [...]
    }
    

This allows you to detect the first client (when clients becomes 1) to start FFmpeg, and the last client (when clients becomes 1) to stop FFmpeg.

winlinvip avatar Oct 26 '25 20:10 winlinvip