Re-implement optional re-connect.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 26 May 2021 19:59:34 +0000 (21:59 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 26 May 2021 19:59:34 +0000 (21:59 +0200)
lagarde.py

index 8ef74071c4b0ecd1d1e45b129001c353212049b6..15ba5159961a5477e8bac56a0067a3224faa936e 100755 (executable)
@@ -276,12 +276,6 @@ class WebRTCClient:
             self.pipe.set_state(Gst.State.NULL)
 
 
-async def run_repeated(task):
-    while True:
-        await task()
-        await asyncio.sleep(0.1)
-
-
 async def run(laplace_uri: str, rtmp_uri: str):
     try:
         events = Events()
@@ -301,6 +295,12 @@ async def run(laplace_uri: str, rtmp_uri: str):
         print(e)
 
 
+async def run_repeated(laplace_uri: str, rtmp_uri: str, sleep_time: float):
+    while True:
+        await run(laplace_uri, rtmp_uri)
+        await asyncio.sleep(sleep_time)
+
+
 def main():
     logging.basicConfig(level=logging.DEBUG, format='%(asctime)-15s %(message)s')
     default_source = 'wss://localhost:1234/ws_connect?id=cug'
@@ -310,10 +310,15 @@ def main():
                         help=f'Laplace signalling websocket URI, default: {default_source}')
     parser.add_argument('-d', '--destination', default=default_dest,
                         help=f'RTMP server URI, default: {default_dest}')
+    parser.add_argument('-r', '--retry', action='store_true', help=f'Retry forever if room not found or closed')
     args = parser.parse_args()
 
     Gst.init(None)
-    asyncio.run(run(args.source, args.destination))
+    if args.retry:
+        job = run_repeated(args.source, args.destination, 2.)
+    else:
+        job = run(args.source, args.destination)
+    asyncio.run(job)
 
 
 if __name__ == '__main__':