From 7b96b06752c349ebb3b1e93a6476b46e698adfac Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 25 May 2020 18:32:43 +0000 Subject: [PATCH] simple_server: Make the server class loop-aware First step in making the class able to manage its own state. --- webrtc/signalling/simple_server.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/webrtc/signalling/simple_server.py b/webrtc/signalling/simple_server.py index 9cf2e36ece..2e43786ed6 100755 --- a/webrtc/signalling/simple_server.py +++ b/webrtc/signalling/simple_server.py @@ -20,7 +20,7 @@ import concurrent class WebRTCSimpleServer(object): - def __init__(self, options): + def __init__(self, loop, options): ############### Global data ############### # Format: {uid: (Peer WebSocketServerProtocol, @@ -35,6 +35,11 @@ class WebRTCSimpleServer(object): # Room dict with a set of peers in each room self.rooms = dict() + # Event loop + self.loop = loop + # Websocket Server Instance + self.server = None + # Options self.addr = options.addr self.port = options.port @@ -266,7 +271,8 @@ class WebRTCSimpleServer(object): logger.setLevel(logging.INFO) logger.addHandler(logging.StreamHandler()) - return wsd + # Run the server + self.server = self.loop.run_until_complete(wsd) def main(): parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter) @@ -282,11 +288,12 @@ def main(): loop = asyncio.get_event_loop() - r = WebRTCSimpleServer(options) + r = WebRTCSimpleServer(loop, options) - loop.run_until_complete (r.run()) - loop.run_forever () - print ("Goodbye!") + print('Starting server...') + r.run() + loop.run_forever() + print("Goodbye!") if __name__ == "__main__": main()