|
1 | | -import itertools |
2 | 1 | import logging |
3 | 2 |
|
4 | 3 | import engineio |
@@ -83,7 +82,6 @@ def __init__(self, client_manager_class=None, logger=False, binary=False, |
83 | 82 |
|
84 | 83 | self.environ = {} |
85 | 84 | self.handlers = {} |
86 | | - self.callbacks = {} |
87 | 85 |
|
88 | 86 | self._binary_packet = None |
89 | 87 | self._attachment_count = 0 |
@@ -304,12 +302,8 @@ def handle_request(self, environ, start_response): |
304 | 302 | """ |
305 | 303 | return self.eio.handle_request(environ, start_response) |
306 | 304 |
|
307 | | - def _emit_internal(self, sid, event, data, namespace=None, callback=None): |
| 305 | + def _emit_internal(self, sid, event, data, namespace=None, id=None): |
308 | 306 | """Send a message to a client.""" |
309 | | - if callback is not None: |
310 | | - id = self._generate_ack_id(sid, namespace, callback) |
311 | | - else: |
312 | | - id = None |
313 | 307 | if six.PY2 and not self.binary: |
314 | 308 | binary = False # pragma: nocover |
315 | 309 | else: |
@@ -353,13 +347,9 @@ def _handle_disconnect(self, sid, namespace): |
353 | 347 | if n != '/' and self.manager.is_connected(sid, n): |
354 | 348 | self._trigger_event('disconnect', n, sid) |
355 | 349 | self.manager.disconnect(sid, n) |
356 | | - if sid in self.callbacks and n in self.callbacks[sid]: |
357 | | - del self.callbacks[sid][n] |
358 | 350 | if namespace == '/' and self.manager.is_connected(sid, namespace): |
359 | 351 | self._trigger_event('disconnect', '/', sid) |
360 | 352 | self.manager.disconnect(sid, '/') |
361 | | - if sid in self.callbacks: |
362 | | - del self.callbacks[sid] |
363 | 353 | if sid in self.environ: |
364 | 354 | del self.environ[sid] |
365 | 355 |
|
@@ -390,34 +380,13 @@ def _handle_ack(self, sid, namespace, id, data): |
390 | 380 | """Handle ACK packets from the client.""" |
391 | 381 | namespace = namespace or '/' |
392 | 382 | self.logger.info('received ack from %s [%s]', sid, namespace) |
393 | | - self._trigger_callback(sid, namespace, id, data) |
| 383 | + self.manager.trigger_callback(sid, namespace, id, data) |
394 | 384 |
|
395 | 385 | def _trigger_event(self, event, namespace, *args): |
396 | 386 | """Invoke an application event handler.""" |
397 | 387 | if namespace in self.handlers and event in self.handlers[namespace]: |
398 | 388 | return self.handlers[namespace][event](*args) |
399 | 389 |
|
400 | | - def _generate_ack_id(self, sid, namespace, callback): |
401 | | - """Generate a unique identifier for an ACK packet.""" |
402 | | - namespace = namespace or '/' |
403 | | - if sid not in self.callbacks: |
404 | | - self.callbacks[sid] = {} |
405 | | - if namespace not in self.callbacks[sid]: |
406 | | - self.callbacks[sid][namespace] = {0: itertools.count(1)} |
407 | | - id = six.next(self.callbacks[sid][namespace][0]) |
408 | | - self.callbacks[sid][namespace][id] = callback |
409 | | - return id |
410 | | - |
411 | | - def _trigger_callback(self, sid, namespace, id, data): |
412 | | - """Invoke an application callback.""" |
413 | | - namespace = namespace or '/' |
414 | | - try: |
415 | | - callback = self.callbacks[sid][namespace][id] |
416 | | - except KeyError: |
417 | | - raise ValueError('Unknown callback') |
418 | | - del self.callbacks[sid][namespace][id] |
419 | | - callback(*data) |
420 | | - |
421 | 390 | def _handle_eio_connect(self, sid, environ): |
422 | 391 | """Handle the Engine.IO connection event.""" |
423 | 392 | self.environ[sid] = environ |
|
0 commit comments