import asyncio, json, os import aioice async def main(): transport=os.environ.get('IKAR_TEST_TURN_TRANSPORT','tcp') address=os.environ.get('IKAR_TEST_TURN_ADDRESS',os.environ['TURN_EXTERNAL_IP']) options={'components':1,'turn_server':(address,3478),'turn_transport':transport,'turn_username':os.environ['TURN_USERNAME'],'turn_password':os.environ['TURN_PASSWORD'],'transport_policy':aioice.TransportPolicy.RELAY} a=aioice.Connection(ice_controlling=True,**options) b=aioice.Connection(ice_controlling=False,**options) try: await asyncio.wait_for(asyncio.gather(a.gather_candidates(),b.gather_candidates()),20) assert a.local_candidates and b.local_candidates assert all(c.type=='relay' for c in a.local_candidates+b.local_candidates) a.remote_username,b.remote_username=b.local_username,a.local_username a.remote_password,b.remote_password=b.local_password,a.local_password for c in b.local_candidates: await a.add_remote_candidate(c) for c in a.local_candidates: await b.add_remote_candidate(c) await a.add_remote_candidate(None); await b.add_remote_candidate(None) await asyncio.wait_for(asyncio.gather(a.connect(),b.connect()),20) await a.send(b'IKAR public TURN') assert await asyncio.wait_for(b.recv(),5)==b'IKAR public TURN' await b.send(b'IKAR public TURN reply') assert await asyncio.wait_for(a.recv(),5)==b'IKAR public TURN reply' print(json.dumps({'passed':True,'transport':transport.upper(),'publicAddress':os.environ['TURN_EXTERNAL_IP'],'candidateTypes':['relay'],'bidirectionalData':True,'relayPorts':[c.port for c in a.local_candidates+b.local_candidates]})) finally: await a.close(); await b.close() asyncio.run(main())