Created
May 21, 2015 08:44
-
-
Save saghul/f8789cb48261f6603f25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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