oberstet, how to remove subscribe when a client disconnect?

#1

class MyServerProtocol(WampServerProtocol):

@exportRpc
def getSubscribers(self):
    print "call getSubscribers"

    subscriptions = []
    for key, value in enumerate(self.factory.subscriptions):
        subscriptions.append(value)
    return json.dumps(subscriptions)

def onSessionOpen(self):
    print "someone has logined"

    self.registerForPubSub("http://example.com/event/", True)

    self.registerMethodForRpc("http://example.com/event/getSubscribers",
        self,
        MyServerProtocol.getSubscribers)

def connectionLost(self, reason):
    print "someone disconnect", reason

    self.factory._unsubscribeClient(self)
    self.factory._removeSession(self)

    WampProtocol.connectionLost(self, reason)
    WebSocketServerProtocol.connectionLost(self, reason)
···

————————————————————————————
ab.connect(chat.wsuri,
function (session) {
sess = session;

        sess.prefix("event", chat.prefix);
        sess.subscribe("event:" + chat.channel, chat.subscribeSuccess); //public topic, subscribe a common topic
        sess.subscribe("event:" + chat.username, chat.subscribeSuccess);//privite topic, subscribe myself topic

        chat.stateUpdate(true);

    },

    function (code, reason) {
        sess = null;
        alert(reason);
        chat.stateUpdate(false);
    }

)

#if chat to everyone, publish to public topic
#if chat to specified client, publish to privite topic

————————————————————————————
Q1: I need a function that when a client disconnect server, update subscribers.
I add connectionLost method, but it does not work.
I print the param “reason”, I find that this function remove public and privite topic at the same time.
But I just need to remove privite topic, am i right? but, how to do this?
————————————————————————————
Q2: how to broadcasting a message to told everyone, clientX has left or clientY has logined?
I don’t know how to implement this function.

0 Likes