Skip to content

Instantly share code, notes, and snippets.

@saghul
Created May 21, 2015 08:44
Show Gist options
  • Save saghul/f8789cb48261f6603f25 to your computer and use it in GitHub Desktop.
Save saghul/f8789cb48261f6603f25 to your computer and use it in GitHub Desktop.
# wait for end
while True:
peer_a_read = asyncio.async(peerA.read())
peer_a_read.other_peer = peerB
peer_b_read = asyncio.async(peerB.read())
peer_b_read.other_peer = peerA
done, pending = yield from asyncio.wait([peer_a_read, peer_b_read], return_when=asyncio.FIRST_COMPLETED)
for task in pending:
task.cancel()
for task in done:
data = task.result()
if not data:
break
# all we can get at this point is trickled ICE candidates
candidate = parse(data)
if candidate is None or candidate.candidate is None:
log.warning('Invalid candidate received!')
break
task.other_peer.write(json.dumps(candidate.to_struct()))
else:
continue
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment