Skip to main content
Kristian Wright
Known Participant
September 7, 2010
Question

Dynamic stream switching from Server (not client) side

  • September 7, 2010
  • 1 reply
  • 1175 views

Hi.

I understand how clients use bandwidth detection etc to dynamically switch streams via client calls with ns.play2( ... ), but I was wondering if it's possible to only ever use 1 initial ns.play( ... ) call on the client side, but let FMS server side logic that I write dictate which client sees what content.

For example, I have 3 clients connected to my FMS server, all watching a live stream.  I then decide I want clientA to see 'recordedMovieA.flv', clientB to continue seeing the live stream, and clientC to watch 'recordedMovieB.flv'.

Can this be done on the FMS side without having to call the clients directly and tell them to ns.play( ... ) what I want that particular client to specifically view each time I want them to change?  Perhaps through the server side Stream object or something similar?

I've been reading and reading, and trying to find a solution, but maybe I'm missing something...

Thanks for your help,

K.

    This topic has been closed for replies.

    1 reply

    Adobe Employee
    September 8, 2010

    First of all you cant detect bandwidth of a particular client on the server side and also you cant push data to a particular client but you can publish it to all clients connected to it. So I dont think it is possible to switch streams on the server side based on client bandwidth. Basically you cant restrict which data will flow to which clients unless there is some authorisation check.

    Regards,

    Amit

    Kristian Wright
    Known Participant
    September 8, 2010

    Thanks for the reply Amit.

    I think I should rephrase my question however...

    I'm not trying to detect bandwith at all - this was just to explain that I understand how different clients can view different content from client side requests.

    My issue is that I would like to show differen clients different movies altogether (not movies recorded at different bandwidths, but different content all together) based on logic I have programmed on the server side.  I have the logic there on the server side, and I know when I want to show clients different movies, but the issue I'm having is the 'how'.

    I know I can use the server side

    client.call("changeStream", null, "newMovieName");

    to call a function on the client, which does the following:

    function changeStream(newMovie)
    {

         ns.play(newMovie);

    }

    and directs them to play the content I send in the params (be it a live stream or a recording), but I would like to avoid this method.

    What I'm looking for is a way to have the client initially subscribe to a live stream (say, a football match) using an initial  ns.play(liveStreamName) on the client side, but then the client never again have to deal with what to play once connected.  The server side logic I have already dictates that certain clients will need to change what each client sees (so after 1 minute one client might get commercialA for beer, another client will get commercialB for shampoo, but a 3rd client will continue to see the live game), but I don't want to use the method described above.

    So what I'm looking for is a way on the server side to tell the client what to play.  I thought the server side Stream class might be the way to go, but from what I've read, maybe not.  Livedocs state the following:

    "A server-side call to Stream.play() is similar to a client-side call to NetStream.publish(); it controls the source of data coming into a stream. When you call Stream.play() on the server, the server becomes the publisher. Because the server has higher priority than the client, the client is forced to unpublish from the stream if the server calls a play()method on the same stream."

    This means that the publisher of the live football game will not be publishing anymore, which is not good for my situation.

    So surely there's a way to do this?  Does anyone have any ideas?

    Thanks in advance,

    K.

    Adobe Employee
    September 8, 2010

    I think server side playlist may help you:

    var s;

    var id1, id2, id3;

    application.onConnect = function(client)
    {
    trace("Client Connected...");
    this.acceptConnection(client);

    s = Stream.get("serverplaylist");
    s.setBufferTime(10);
    s.onMetaData = function (mystr){
      trace("application.onMetaData  " + mystr);
    }
    s.onMyData = function (mystr){
      trace("application.myFunction " + mystr);
    }


    id1 = setInterval(p1, 5000);
    }

    function p1(){
    clearInterval(id1);
    trace("p1 called........");
    s.play("mp4:stream1", 0, -1);
    trace("mp4:stream1");
    id2 = setInterval(p2, 50000);
    }

    function p2(){
    clearInterval(id2);
    trace("p2 called........");
    s.play("mp4:stream2", 0, -1, false);
    trace("mp4:stream2");
    id3 = setInterval(p3, 60000);
    }

    function p3(){
    clearInterval(id3);
    trace("p3 called........");
    s.play("mp4:stream3", 0, -1, false);
    trace("mp4:stream3");
    id1 = setInterval(p1, 70000);
    }

    So here client subscribe to stream "serverplaylist" published by server after 5 seconds of connection and then it gets first stream1 for 50 secs and then stream2 for 60 secs and then stream3 for 70secs and this continues in loop.

    So here you can different logic server to insert adds after proper interval.

    Regards,

    Amit