peerjs-python icon indicating copy to clipboard operation
peerjs-python copied to clipboard

Binary DataChannel message handling broken

Open rmsy opened this issue 3 years ago • 2 comments

Hello 👋 Thank you for this awesome library! I started working with it yesterday and I noticed that, unless I'm missing something, DataChannel message handling appears to be broken for binary-serialized messages. Every time I receive a binary DataChannel message, I receive the below exception:

2021-01-06 08:49:41 WARNING ~/Development/proj/venv/lib/python3.9/site-packages/peerjs/dataconnection.py._handleDataMessage(171): Unpacking data...
2021-01-06 08:49:41 ERROR /usr/local/Cellar/[email protected]/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py.default_exception_handler(1738): Exception in callback AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...te 'unpack'")>) at ~/Development/proj/venv/lib/python3.9/site-packages/pyee/_asyncio.py:55
handle: <Handle AsyncIOEventEmitter._emit_run.<locals>._callback(<Task finishe...te 'unpack'")>) at ~/Development/proj/venv/lib/python3.9/site-packages/pyee/_asyncio.py:55>
Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.1_4/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "~/Development/proj/venv/lib/python3.9/site-packages/pyee/_asyncio.py", line 62, in _callback
    self.emit('error', exc)
  File "~/Development/proj/venv/lib/python3.9/site-packages/pyee/_base.py", line 116, in emit
    self._emit_handle_potential_error(event, args[0] if args else None)
  File "~/Development/proj/venv/lib/python3.9/site-packages/pyee/_base.py", line 86, in _emit_handle_potential_error
    raise error
  File "~/Development/proj/venv/lib/python3.9/site-packages/peerjs/dataconnection.py", line 142, in on_datachannel_message
    await self._handleDataMessage(msg)
  File "~/Development/proj/venv/lib/python3.9/site-packages/peerjs/dataconnection.py", line 172, in _handleDataMessage
    deserializedData = util.unpack(data)
AttributeError: 'Util' object has no attribute 'unpack'

This is occurring in the DataConnection class, when the _handleDataMessage function attempts to call util.unpack(): https://github.com/ambianic/peerjs-python/blob/9db9e0a7278dc95d518a904330835da75e93d179/src/peerjs/dataconnection.py#L170-L172

However, the assignment of util.unpack() appears to have been removed in #17 when the msgpack dependency was removed, in order to fix a bug of some sort.

Am I missing something here, or does this functionality not work right now?

Thank you for your time!

rmsy avatar Jan 06 '21 15:01 rmsy

Hi @rmsy . You can turn off packing/unpacking and pass raw messages.

Unfortunately I did not see a simple way to use a standard chunking library on both python and peerjs sides. PeerJS uses a forked version of a standard packing protocol, which I didn't put time to port to Python. Didn't seem right to reinvent the wheel. I made the case with the peerjs team to use a standard lib, but they already have a legacy user base to support, so it's not a trivial switch.

ivelin avatar Jan 06 '21 21:01 ivelin

Sounds good, thank you for the quick response! I did end up switching to raw JSON serialization, and then it started working well.

rmsy avatar Jan 06 '21 21:01 rmsy