diff options
author | Nirbheek Chauhan <nirbheek@centricular.com> | 2020-05-25 18:32:43 +0000 |
---|---|---|
committer | Matthew Waters <matthew@centricular.com> | 2020-06-18 23:34:48 +1000 |
commit | 7b96b06752c349ebb3b1e93a6476b46e698adfac (patch) | |
tree | b3e004d8662f93a211bb04f9e9a169ff87baab63 /webrtc | |
parent | b8c1bd1fa344acb6f6ca591e0687cd0cba9330a3 (diff) |
simple_server: Make the server class loop-aware
First step in making the class able to manage its own state.
Diffstat (limited to 'webrtc')
-rwxr-xr-x | webrtc/signalling/simple_server.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/webrtc/signalling/simple_server.py b/webrtc/signalling/simple_server.py index 9cf2e36..2e43786 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() |