diff --git a/web.py b/web.py index 2c75827..2c9b53d 100644 --- a/web.py +++ b/web.py @@ -155,91 +155,6 @@ class ReticulumWebChat: return websocket_response - # handle websocket clients for initiating a call - # todo: remove - @routes.get("/call/initiate/{destination_hash}") - async def ws(request): - - # get path params - destination_hash = request.match_info.get("destination_hash", "") - - # convert destination hash to bytes - destination_hash = bytes.fromhex(destination_hash) - - # prepare websocket response - websocket_response = web.WebSocketResponse() - await websocket_response.prepare(request) - - # wait until we have a path to the destination - if not RNS.Transport.has_path(destination_hash): - print("waiting for path to server") - RNS.Transport.request_path(destination_hash) - while not RNS.Transport.has_path(destination_hash): - await asyncio.sleep(0.1) - - # connect to server - print("establishing link with server") - server_identity = RNS.Identity.recall(destination_hash) - server_destination = RNS.Destination( - server_identity, - RNS.Destination.OUT, - RNS.Destination.SINGLE, - "call", - "audio" - ) - - # todo implement - def link_established(link): - print("link established") - - # todo implement - def link_closed(link): - if link.teardown_reason == RNS.Link.TIMEOUT: - print("The link timed out, exiting now") - elif link.teardown_reason == RNS.Link.DESTINATION_CLOSED: - print("The link was closed by the server, exiting now") - else: - print("Link closed") - - # todo implement - def client_packet_received(message, packet): - - # send audio received from call receiver to call initiator websocket - asyncio.run(websocket_response.send_bytes(message)) - - # create link - link = RNS.Link(server_destination) - - # register link state callbacks - link.set_packet_callback(client_packet_received) - link.set_link_established_callback(link_established) - link.set_link_closed_callback(link_closed) - - # handle websocket messages until disconnected - async for msg in websocket_response: - msg: WSMessage = msg - if msg.type == WSMsgType.BINARY: - try: - - # drop audio packet if it is too big to send - if len(msg.data) > RNS.Link.MDU: - print("dropping packet " + str(len(msg.data)) + " bytes exceeds the link packet MDU of " + str(RNS.Link.MDU) + " bytes") - continue - - # send codec2 audio received from call initiator on websocket, to call receiver over reticulum link - print("sending bytes to call receiver: {}".format(len(msg.data))) - RNS.Packet(link, msg.data).send() - - except Exception as e: - # ignore errors while handling message - print("failed to process client message") - print(e) - elif msg.type == WSMsgType.ERROR: - # ignore errors while handling message - print('ws connection error %s' % websocket_response.exception()) - - return websocket_response - # get config @routes.get("/api/v1/config") async def index(request):