Skip to main content
August 26, 2009
Answered

Start streaming only when people are watching?

  • August 26, 2009
  • 2 replies
  • 2965 views

I've got a page laid out that houses a nightly live webstream of music at a venue. Every night (except Sunday) the stream turns on from 8pm-2am Eastern Standard Time. Some nights, I notice there is nobody watching the stream, yet the stream plays everyday no matter what. In the interest of saving bandwidth per month, I'm trying to figure out how to only stream if somebody is watching.

So basically the camera would be recording locally, and when someone connects to the website something tells the server to start broadcasting. If the person leaves, the server stops broadcasting. Has anyone ever tried doing this? I'm using Influxis for my media streaming and they've assured me I can execute server side scripts.

Right now i'm using FLME 3 to do the streaming up to the server.

I'd appreciate any help, or a point in the right direction

-Matt

    This topic has been closed for replies.
    Correct answer

    Hey Matt,

    After some server-side tinkering we were able to create a sort of solution. You see FMLE features reduency which allows it to automatically reconnect to the Flash Media Server, defined in the FMS URL field, if disconnected. So we came up with is, on the onDisconnect event for any client, we check the number of clients connected. If the number of clients connected is equal to one, we then check if the client left is a FMLE client. If it is a FMLE client we disconnect the FMLE user.

    When FMLE tries to reconnect it won't be allowed to unless there is a viewer present. Once a viewer is present the FMLE will be allowed to connect and broadcast.

    application.onConnect = function(p_client)
    {
    if( (p_client.agent).indexOf("FMLE") == 0 && application.clients.length < 1 )  {
      trace("***********onReject**************")
      application.rejectConnection(p_client);
    }else {
      trace("***********onConnect**************")
      application.acceptConnection(p_client);
    }
    }
    application.onDisconnect = function(p_client)
    {
    if(application.clients.length == 1){
      for (i = 0; i < application.clients.length; i++){
       if( (application.clients.agent.agent).indexOf("FMLE") == 0 )  {
        trace("***********onDisconnect**************")
        application.disconnect(application.clients.agent);
       }
      }
    }
    }

    Hope this helps.

    Thanks,

    Influxis Support

    2 replies

    Correct answer
    September 1, 2009

    Hey Matt,

    After some server-side tinkering we were able to create a sort of solution. You see FMLE features reduency which allows it to automatically reconnect to the Flash Media Server, defined in the FMS URL field, if disconnected. So we came up with is, on the onDisconnect event for any client, we check the number of clients connected. If the number of clients connected is equal to one, we then check if the client left is a FMLE client. If it is a FMLE client we disconnect the FMLE user.

    When FMLE tries to reconnect it won't be allowed to unless there is a viewer present. Once a viewer is present the FMLE will be allowed to connect and broadcast.

    application.onConnect = function(p_client)
    {
    if( (p_client.agent).indexOf("FMLE") == 0 && application.clients.length < 1 )  {
      trace("***********onReject**************")
      application.rejectConnection(p_client);
    }else {
      trace("***********onConnect**************")
      application.acceptConnection(p_client);
    }
    }
    application.onDisconnect = function(p_client)
    {
    if(application.clients.length == 1){
      for (i = 0; i < application.clients.length; i++){
       if( (application.clients.agent.agent).indexOf("FMLE") == 0 )  {
        trace("***********onDisconnect**************")
        application.disconnect(application.clients.agent);
       }
      }
    }
    }

    Hope this helps.

    Thanks,

    Influxis Support

    September 1, 2009

    Brilliant! You guys never cease to amaze me. From the service you provide to your support in places like this, i'm almost at a loss for word. Now I know why we use you for our streaming needs. Thank you so much for looking into this!

    -Matt

    September 1, 2009

    The connection dropping idea is interesting, but what to do when FMLE crashes (which I find it does... often... for no apparent reason at all)? If the idea is to leave FMLE completely unmanned, I'd be a little uncomfortable leaving it to chance.

    August 28, 2009

    Maybe with a script like a chat...

    I'm working on a e-learning project.

    Take a look at : http://escale.net/demo

    try administrator and user in the same time (2 screens and 2 ID.)

    I use a serverside script to know when user log or quit.

    August 29, 2009

    That is interesting what you have setup there. I'm not sure if it'll work in my application. Unless you are talking about the buddy list how it updates and knows when someone is watching and not. I think I would have to have a custom broadcaster. From what influxis has told me, its possible. I need to setup some sort of on-demand live streaming. Where the streaming is happening, but not broadcasting up to the influxis server until someone calls for it.

    August 30, 2009

    Check out this link and the source code... all you need is there.

    http://www.swfflex.com/blog/1/2008/11/Flash-Video-Chat.cfm