2 Replies Latest reply: Jul 24, 2013 4:42 PM by screensaverboy RSS

    How to remotely check if publishing point is active using javascript or php?

    screensaverboy Community Member

      Hi,

      I need to check if a publishing point is active (in terms of live video data is available/being streamed) in order to display that status on a web page. It would be nice if this could be queried using javascript or php.

       

      Any thoughts?

       

      Many thanks in advance!

        • 1. Re: How to remotely check if publishing point is active using javascript or php?
          ospn2012 Community Member

          screensaverboy wrote:

           

          Hi,

          I need to check if a publishing point is active (in terms of live video data is available/being streamed) in order to display that status on a web page. It would be nice if this could be queried using javascript or php.

           

          Any thoughts?

           

          Many thanks in advance!

           

          There's several ways to do this.  I modified the server side main.asc to generate a .html or .php file inside a custom virtual directory within the application root >> (application/livepkgr/status/) and use the variable "streamObject.name" to create the filename.html or filename.php when the application is being published to. Then main.asc deletes the file when it is not.  You then can symlink the /application/likepkgr/status/ directory to the /webroot/ directory to then be able to query from the client to see if the URL exists or doesn't exist. I'll provide the samples below.

           

          Append this to  /application/livepkgr/Application.xml and create the directory status/

           

          <FileObject>

              <VirtualDirectory>status/</VirtualDirectory>

          </FileObject>

           

           

          Apped this to /livepkgr/main.asc (You do not need the parent application.onPublish or application.onUnpublish functions, representaion only)

          application.onPublish = function (clientObj, streamObj) { // not needed representation only

           

          var streamStatus = new File("status/" + streamObj.name + ".html"); // you can create whatever filename you want here

           

               if (!streamStatus.exists) {

                  streamStatus.open("text", "append");

                  streamStatus.write("Stream name is: " + streamObj.name + " and live event is: " + s.liveEvent); // or write what you wish to the file

                  trace("Created Stream Status File : status/" + streamObj.name + ".html") // writes to the admin console log output

              }

           

          } // not needed representation only

           

           

           

          application.onUnpublish = function (clientObj, streamObj) { // not needed representation only

           

          var streamStatus = new File("status/" + streamObj.name + ".html"); { // you can delete whatever file name you created

                  streamStatus.remove();

                  trace("Deleted Stream Status File : status/" + streamObj.name + ".html"); // writes to the admin console log output

              }

           

          } // not needed representation only

           

           

          Some command line stuff (linux)

           

          # mkdir /opt/adbe/fms/applications/livepkgr/status

          # chmod 777 /opt/adbe/fms/applications/livepkgr/status

          # cd /opt/adbe/fms/webroot

          # ln -s /opt/adbe/fms/applications/livepkgr/status livepkgrstatus

          # chown -R fms:fms /opt/adbe/fms/applications/livepkgr/status livepkgrstatus

           

          flashplayer.html Client Side HTML w/ javascript (This is the .html you would load in an <iframe> on the page serving up the video.  ie.  flashplayer.html)

           

          <!doctype html>

          <html>

          <head>

          <meta charset="utf-8">

          <script type='text/javascript' src='//code.jquery.com/jquery-1.10.2.js'></script>

          <script type="text/javascript">

          function isUrlExists(url) {

              setTimeout(isUrlExists, 30000);

              url = 'http://yourfmsdomain/livepkgrstatus/livestream1.html';

                    var liveState = document.getElementById('livePlayer').src;

                    var offlineState = document.getElementById('livePlayer').src;

                    var isLive;

              var isOffline;

              $.getJSON("http://query.yahooapis.com/v1/public/yql?" +

                  "q=select%20*%20from%20html%20where%20url%3D%22" + encodeURIComponent(url) +

                  "%22&format=json'&callback=?",

           

           

              function (data) {

                  if (data.results[0]) {

                      isLive = 'LIVE';

                      // alert('Status file exsits! State of stream is: ' + isLive + ' & State of player is: ' + liveState);

                  } else {

                      isOffline = 'OFFLINE';

                      // alert('Status file does not exist! State of stream is: ' + isOffline + ' & State of player is: ' + offlineState);

                  }

           

                  if (isLive !== undefined && liveState == 'http://www.yourwebserver.com/channel/flashplayerlive.html') {

                      // alert('no live state change');

                  } else {

                      if (isLive === undefined) {

                          // alert('state change remove live player');

                                                  // code here to phsycially remove element or object

                              } else {

                          // alert('state change refresh live player');

                                                  go('http://www.yourwebserver.com/channel/flashplayerlive.html');

           

                                        }

                              }

           

                              if (isOffline !== undefined && offlineState == 'http://www.yourwebserver.com/channel/flashplayeroffline.html') {

                      // alert('no offline state change');

                  } else {

                      if (isOffline === undefined) {

                          // alert('state change remove offline player');

                                                  // code here to physically remove element or object

                                        } else {

                          // alert('state change refresh offline player');

                                                  go('http://www.yourwebserver.com/channel/flashplayeroffline.html');

           

           

                     }

                  }

                    });

           

          }

           

           

          function go(loc){

              document.getElementById('livePlayer').src = loc;

                    }

           

           

          $(function () {

              isUrlExists('http://yourfmsdomain/livepkgrstatus/livestream1.html');

          });

           

           

          </script>

           

           

          </head>

            <body>

          <iframe id="livePlayer" src="" width="100%" height="520" frameborder="0" scrolling="no"></iframe>

            </body>

          </html>

           

           

          flashplayerlive.html

           

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml">

            <head>

              <title>Strobe Media Playback</title>

              <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

                    <script type="text/javascript">  

           

                        // Create a StrobeMediaPlayback configuration

                              var parameters =

                                        {          src: "http://yourfmsserver/livestream1.f4m"  

                                           ,          autoPlay: true

                                        ,          controlBarAutoHide: true

                                        ,   javascriptCallbackFunction: "onJavaScriptBridgeCreated"

                                        };

           

                              // Embed the player SWF:    

                              swfobject.embedSWF

                                        ( "http://yourfmsserver/swfs/StrobeMediaPlayback.swf"

                                        , "live"

                                        , 912

                                        , 513

                                        , "10.1.0"

                                        , {}

                                        , parameters

                                        , { allowFullScreen: "true"}

                                        , { name: "strobeMediaPlayback" }

                                        );

           

           

              </script>  

            </head>

            <body>

                    <div id="live"></div>

            </body>

          </html>

           

           

          flashplayeroffline.html

           

           

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

          <html xmlns="http://www.w3.org/1999/xhtml">

            <head>

              <title>Strobe Media Playback</title>

              <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>

                    <script type="text/javascript">  

           

                        // Create a StrobeMediaPlayback configuration

                              var parameters =

                                        {          src: "http://yourfmsserver/yourofflineplaylist.f4m"  

                                           ,          autoPlay: true

                                        ,          controlBarAutoHide: true

                                        ,          loop: true

                                        ,   javascriptCallbackFunction: "onJavaScriptBridgeCreated"

                                        };

           

                              // Embed the player SWF:    

                              swfobject.embedSWF

                                        ( "http://yourfmsserver/swfs/StrobeMediaPlayback.swf"

                                        , "live"

                                        , 912

                                        , 513

                                        , "10.1.0"

                                        , {}

                                        , parameters

                                        , { allowFullScreen: "true"}

                                        , { name: "strobeMediaPlayback" }

                                        );

           

           

              </script>  

            </head>

            <body>

                    <div id="live"></div>

            </body>

          </html>

           

           

          I hope you can understand this. It took me several weeks to build this. You're Welcome!

           

          NOTE: You will have to move StrobeMediaPlayback.swf from your samples directory to your webroot to call it from your client. This is needed. Also check your crossdomain.xml and appropriate domain is added.

           

          Zach @ OSPN

          • 2. Re: How to remotely check if publishing point is active using javascript or php?
            screensaverboy Community Member

            Dear Zach,

             

            many thanks for sharing your solution with me!

             

            While I still need to try this out it looks like the "main.asc" part does exactly what I need! Having that "streamStatus"-file will make it easy to remotely check if the stream is available. :-)

             

            Thanks again!