Skip to main content
Known Participant
Jan 12, 2012 1:59 PM UTC
Question

How to get the number of viewers live stream?

Subj.

I want to know how many viewers watch stream at the moment. How to find this out?

    This topic is closed to new replies. Start a new post to keep the conversation going.

    5 replies

    Lokki7Author
    Known Participant
    Jan 14, 2012 5:07 PM UTC

    that's how I did it

    var nc_admin = new NetConnection;
    
    
    function timer1(){
        nc_admin.call("getLiveStreams", new onGetLiveStreams(), "live");
    }
     
    setInterval(timer1, 5000); 
    
    function onGetLiveStreams() {
        this.onResult = function(ans) {
         for (i = 0; i < ans.data.length; i++){ 
             nc_admin.call("getLiveStreamStats", new onGetLiveStreamStats(), "live" , ans.data);
         }
        }
    
    }
    
    function onGetLiveStreamStats(){
        this.onResult = function(info) {
         if(info.data.publisher && info.data.subscribers) {
             var so = SharedObject.get(info.data.publisher.name, false); 
             so.setProperty('viewers', info.data.subscribers.length);
         } 
        }
    }
    
    application.onAppStart = function(){
    
        trace("Starting...");    
        nc_admin.connect("rtmp://localhost:1111/admin", "fmsroot", "ljvedjls"); 
        
    }
    
    
    Translate
    Participant
    Jun 26, 2012 1:45 PM UTC

    Hi, anyone can write a working example?
    - server-Side
    - client side
    The example above I have not worked.

    Translate
    Lokki7Author
    Known Participant
    Jan 12, 2012 2:57 PM UTC

    Can I call getLiveStreamStats() on server side? Without NetConnection to localhost!

    Translate
    Participant
    Jan 12, 2012 2:36 PM UTC

    If you have access to you FMS Admin Console you can simply look how much clients are connected to your application(s).

    If you need the current number of viewers on your client side you can store the connections into a shared object within your application.

    Translate
    Lokki7Author
    Known Participant
    Jan 12, 2012 2:41 PM UTC

    FMS Admin Console shows all clients of the application. But there may be more than one stream.

    I need to know clients per stream

    Translate