Is there anyway to know if stream started to publish - Auto Play

Discussion in 'Web Call Server 5' started by Azhar Ali, Aug 13, 2019 at 4:46 PM.

  1. Azhar Ali

    Azhar Ali Member

    Hi,
    We would like to autoplay the stream for the viewers when broadcaster starts to broadcast. In our case, the publisher creates an event and we generate a unique Id for the streamName and users subscribe to the event with the same Id.
    What we would like to do is, if the subscriber is already on the page and publisher starts streaming, we want to autoplay the stream for them. I do know that chrome will stop the autoplay but it's ok for it to be started as muted.
    Is there any callback that we can use in the API to know if the stream has started?
  2. Max

    Max Administrator Staff Member

    Good day.
    You can use Stream.available() method, please look at Two Way Streaming code example on GitHub. This method returns a promise that is resolved if stream with name specified is available to play, or is rejected if not:
    Code:
    function availableStream(){
        var session = Flashphoner.getSessions()[0];
        var streamName = $('#playStream').val();
        session.createStream({
            name: streamName,
            display: remoteVideo
        }).available().then(function(stream){
            $("#availableStatus").text("AVAILABLE").attr("class", "text-success");
        }, function(stream){
            $("#availableStatus").text("UNAVAILABLE").attr("class", "text-danger");
        });
    }
    
  3. Azhar Ali

    Azhar Ali Member

    Hi Max,

    Thank you for the suggestion. I have found that method but to use that you have to put the available function inside a setInterval and call that regularly to keep checking. I was just wondering if there was anything on the session to return the callback e.g. StreaminStarted event. Similar to how roomAPI works when a connected user starts streaming, all other users are notified in the event.

    If not, then I will do the above as you mentioned.

    Thank you for your valuable input as always.

    Regards
    Azhar
  4. Max

    Max Administrator Staff Member

    Good day.
    No, there's no such callback. RoomAPI also uses Stream.available() under the hoods. So you should use it too.

Share This Page