Commits

Jeffrey Gelens committed 1648fe4

Remove disconnect en unsubcribed clients from pool.

  • Participants
  • Parent commits c802063

Comments (0)

Files changed (1)

File geventwebsocket/protocols/wamp.py

 import types
 
 from .base import BaseProtocol
+from ..exceptions import WebSocketError
 
 
 def export_rpc(arg=None):
         # TODO: implement prefix matching
 
     def subscribe(self, uri, client):
-        print "subcsription to ", uri
-        print "of client ", client
         if uri in self.channels:
             self.channels[uri].append(client)
 
         # TODO: exclude & eligible
 
         msg = [WampProtocol.MSG_EVENT, uri, event]
-        print msg
 
         for client in self.channels[uri]:
-            client.ws.send(serialize(msg))
+            try:
+                client.ws.send(serialize(msg))
+            except WebSocketError:
+                # Seems someone didn't unsubscribe before disconnecting
+                self.channels[uri].remove(client)
 
 
 class WampProtocol(BaseProtocol):
         uri = self.prefixes.resolve(curie_or_uri)
 
         if action == self.MSG_SUBSCRIBE and len(data) == 2:
-            # resolve prefixe
             self.server.channels.subscribe(data[1], self.handler.active_client)
 
         elif action == self.MSG_UNSUBSCRIBE and len(data) == 2:
-            # resolve prefixes
             self.server.channels.unsubscribe(
                 data[1], self.handler.active_client)
 
             exclude = data[3] if len(data) >= 4 else None
             eligible = data[4] if len(data) >= 5 else None
 
-            print "data", data
-            print "payload", payload
-            print "exclude", exclude
-            print "eligible", eligible
             self.server.channels.publish(uri, payload, exclude, eligible)
 
     def on_open(self):
         if not isinstance(data, list):
             raise Exception('incoming data is no list')
 
-        print "RX", data
-
         if data[0] == self.MSG_PREFIX and len(data) == 3:
             prefix, uri = data[1:3]
             self.prefixes.add(prefix, uri)
         else:
             raise Exception("Unknown call")
 
-
     def on_close(self):
         self.app.on_close()