aiortc Error while trying to addTrack from other peer

80 Views Asked by At

I am trying to connect a browser peer (client) to a server peer (python). When the first peer trying to connect into the server the connection is well both sides. When another client trying to connect into server i am trying to use addTrack from the first peer. Doesn't work.

Code snippet:

                #audio from other clients to new client
                for track in self.clients_audio_track:
                    pc.addTrack(track)
                
                #video from other clients to new client
                for track in self.clients_video_track:
                    pc.addTrack(track)

                @pc.on("track")
                async def on_track(track):  
                    if track.kind == "audio":
                        self.clients_audio_track.append(track)
                        #audio from client (server use)
                        self.micTracks.append(ClientTrack(track))
                        self.blackHoles.append(MediaBlackhole())
                        self.blackHoles[self.current_active_calls-1].addTrack(self.micTracks[self.current_active_calls-1])
                        await self.blackHoles[self.current_active_calls-1].start()
                    else:
                        self.clients_video_track.append(track)
                        #video from client (server use)
                        self.clientWebCameraTracks.append(ClientWebCamera(track,self.to_emitter,self.current_active_calls))
                        self.video_blackHole_clients.append(MediaBlackhole())
                        self.video_blackHole_clients[self.current_active_calls-1].addTrack(self.clientWebCameraTracks[self.current_active_calls-1])
                        await self.video_blackHole_clients[self.current_active_calls-1].start()

The error is:

Error handling request
Traceback (most recent call last):
  File "C:\Python\Lib\site-packages\aiohttp\web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\aiohttp\web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\cpapp\OneDrive\Υπολογιστής\ip_calls\all\server_video.py", line 502, in offer
    await pc.setLocalDescription(answer)
  File "C:\Python\Lib\site-packages\aiortc\rtcpeerconnection.py", line 788, in setLocalDescription
    t._currentDirection = and_direction(t.direction, t._offerDirection)
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python\Lib\site-packages\aiortc\rtcpeerconnection.py", line 259, in and_direction
    return sdp.DIRECTIONS[sdp.DIRECTIONS.index(a) & sdp.DIRECTIONS.index(b)]
                                                    ^^^^^^^^^^^^^^^^^^^^^^^
ValueError: None is not in list

What am I going wrong here and how can I fix it?

Edit: I modified sdp.DIRECTIONS (i add None to list), then in javascript:

pc.addEventListener('track', function(evt) {
}

is only called two times but there are four tracks. (Note: the track is send to client is not the track from server but the track from other client. Ideally, i want to send both).

0

There are 0 best solutions below