Can get stuck sometimes
Error/timeout handling of ProxyPair
and related stuff looks poor to me and I think it needs to be revisited. Namely:
-
flush
checkswebrtcIsReady()
before sending a message to the client. If it'sfalse
andr2cSchedule
has messages, it willsetTimeout
toflush()
again. This can make an infinite loop (see comment) -
peerConnOpen
checks ifthis.pc.connectionState !== 'closed'
, but state can also be'failed'
and'disconnected'
. -
channel.onerror
is not handled (I suppose a timeout would run anyway, but then it looks like things need to be renamed or something). - In
close()
we check for things likepeerConnOpen()
before doingpc.close()
, but its state could still be'new'
or'connecting'
, so it won't get closed in that case. - When creating
ProxyPair
, we create a timeout that's supposed to run if we fail to create a connection. If we succeed, then another timeout is supposed to take over. But it's not obvious and it looks very fragile, like it can be broken by an unrelated change. - If connection gets closed within
config.datachannelTimeout
(20s) after being opened, thedatachannelTimeout
callback would still get executed. - There are listeners (e.g. in
proxypair.js
) like.onopen
and.ondatachannel
that don't take into account the fact that they can be fired several times.
A suggestion for ProxyPair.close()
issues is - only call close()
in one place of the program (outside of the ProxyPair class perhaps). ProxyPair.receiveOffer
should return a Promise
that resolves when we started serving the client successfully, otherwise rejects. And the resolve value of that Promise
should be another Promise
that is fulfilled when we've finished serving the client.
Related: !54 (merged), #19
Edited by WofWca