Skip to content

Commit

Permalink
Merge pull request #1184 from zauberzeug/reconnect-to-on-air
Browse files Browse the repository at this point in the history
on air: handle reconnect requests and failures
  • Loading branch information
rodja authored Jul 17, 2023
2 parents c100482 + 24400e0 commit ec62d76
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nicegui/air.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,22 @@ async def on_move() -> None:
print('Sorry, you have reached the time limit of this NiceGUI On Air preview.', flush=True)
await self.connect()

@self.relay.on('reconnect')
async def on_reconnect(data: Dict[str, Any]) -> None:
await self.connect()

async def connect(self) -> None:
try:
if self.relay.connected:
await self.relay.disconnect()
await asyncio.sleep(1)
await self.relay.connect(
f'{RELAY_HOST}?device_token={self.token}',
socketio_path='/on_air/socket.io',
transports=['websocket', 'polling'],
)
except socketio.exceptions.ConnectionError:
await self.connect()
except Exception:
logging.exception('Could not connect to NiceGUI On Air server.')
print('Could not connect to NiceGUI On Air server.', flush=True)
Expand Down

0 comments on commit ec62d76

Please sign in to comment.