Skip to main content
Inspiring
January 17, 2007
Answered

How do I force an unsubscribe?

  • January 17, 2007
  • 4 replies
  • 548 views
Hi,

If multiple users are subscribed to the same live stream, is it possible for the FMS server to force one user to unsubscribe from the stream, or otherwise prevent him from viewing, without affecting any of the other subscribers?

My server needs to cut off a subscriber when his access expires, and for security reasons I can't trust the client to unsubscribe when instructed to, so the server must force an unsubscribe somehow. I can't figure out how to do this for one subscriber without unsubscribing everyone watching that stream.

Any and all replies are much appreciated.


Thanks in advance,
Barry
    This topic is closed to new replies. Start a new post to keep the conversation going.
    Correct answer Brentley_11
    You could do something like this:

    (Serverside Code)
    quote:

    application.onAppStart = function(){
    intervalIDList = new Array();
    subscribeTime = 5000; //5 seconds
    }

    //when client connects create an interval
    application.onConnect = function(theClient){
    application.acceptConnection(theClient);
    intervalID = setInterval(disconnectClient,subscribeTime,intervalIDList.length,theClient);
    intervalIDList.push(intervalID)

    }

    //When Subscribe Time runs out disconnect client.
    function disconnectClient(intervalIndex,theClient){
    application.disconnect(theClient);
    clearInterval(intervalIDList[intervalIndex]);
    }


    I tested it and it does work.

    4 replies

    Barry_FAuthor
    Inspiring
    January 18, 2007
    Thank you!

    application.disconnect() is the method I was looking for! I swear I tore the docs apart before I posted this thread but somehow I missed it.


    Barry
    Inspiring
    January 17, 2007
    I don't know if this is the best way to do it, but you could set a server side interval for every subscriber who connects and then every time the interval runs, it could check if the client should unsubscribe. If they should, clear the interval and call a function on that client that stops the stream.
    Barry_FAuthor
    Inspiring
    January 17, 2007
    Thanks for your reply but unfortunately that won't work. For security reasons I can't trust the client to unsubscribe when told to (this is a pay-per-view situation and surfers will hack their own client that ignores the request, to get free service... I've see it before).

    What I need is a method that I can use on the server to FORCE a client to unsubscribe or disconnect. Even application.rejectConnection() does not work at a later time if the client has already been accepted. And there seems to be no way to use Stream.close() or NetConnection.close() to disconnect one subscriber. :(

    If a client has been accepted with application.acceptConnection(), is there any way to reject it at a later time with application.rejectConnection()? I tried it but it does not seem to work.


    Thanks,
    Barry
    Brentley_11Correct answer
    Inspiring
    January 18, 2007
    You could do something like this:

    (Serverside Code)
    quote:

    application.onAppStart = function(){
    intervalIDList = new Array();
    subscribeTime = 5000; //5 seconds
    }

    //when client connects create an interval
    application.onConnect = function(theClient){
    application.acceptConnection(theClient);
    intervalID = setInterval(disconnectClient,subscribeTime,intervalIDList.length,theClient);
    intervalIDList.push(intervalID)

    }

    //When Subscribe Time runs out disconnect client.
    function disconnectClient(intervalIndex,theClient){
    application.disconnect(theClient);
    clearInterval(intervalIDList[intervalIndex]);
    }


    I tested it and it does work.