0

I use autobahnPython + autobahnJs set up a chatting service.

Now I want to a function, when a client connect wamp, the member list of chatting room be updated automatically. How implement this function?

def onSessionOpen(self):

I think in onSessionOpen function add action, but I don't know how to do next.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user1514160
  • 143
  • 1
  • 1
  • 9

1 Answers1

1

One approach would be: have a dedicated PubSub topic per chat room. When a WAMP client subscribes to a "chat room topic", it'll be automatically added to the subscriber list for that chat room. The subscriptions are held in self.factory.subscriptions[<topic URI>]. Please note that the latter is an internal object .. not a public API. We would need to know more what else you want to do .. i.e. have an RPC to get the current subscribers on a chat room and such.

Disclaimer: I am author of WAMP, Autobahn and work for Tavendo.

oberstet
  • 21,353
  • 10
  • 64
  • 97
  • @exportSub("chattingroom") def subscribe(self, topicUriPrefix, topicUriSuffix): print "someone subscribe chattingroom" msg = '[7,"http://example.com/event/chattingroom",{"message":"memberUpdate","member":"","caller":"server"}]' self.factory.onMessage(msg, False) in this function, how to use onMessage method? – user1514160 Aug 23 '12 at 02:43
  • 1
    You should not override onMessage .. the default implementation needs to handl the WAMP messages. If you need custom handling of publication, have a look at the example here: https://github.com/tavendo/AutobahnPython/blob/master/examples/wamp/pubsub/custom/server.py – oberstet Aug 23 '12 at 12:08