Skip to content

Commit

Permalink
Merge branch 'main' of github.com:zauberzeug/nicegui
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Aug 22, 2024
2 parents bd2e0da + 06afeae commit f038b81
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions nicegui/air.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from __future__ import annotations

import asyncio
import gzip
import json
import re
from dataclasses import dataclass
from typing import Any, AsyncIterator, Dict, Optional
from typing import TYPE_CHECKING, Any, AsyncIterator, Dict, Optional
from uuid import uuid4

import httpx
import socketio
import socketio.exceptions

Expand All @@ -16,6 +17,9 @@
from .elements.timer import Timer as timer
from .logging import log

if TYPE_CHECKING:
import httpx

RELAY_HOST = 'https://on-air.nicegui.io/'


Expand All @@ -28,6 +32,8 @@ class Stream:
class Air:

def __init__(self, token: str) -> None:
import httpx # pylint: disable=import-outside-toplevel

self.token = token
self.relay = socketio.AsyncClient()
self.client = httpx.AsyncClient(app=core.app)
Expand Down Expand Up @@ -140,10 +146,11 @@ def _handle_event(data: Dict[str, Any]) -> None:
if client_id not in Client.instances:
return
client = Client.instances[client_id]
if data['msg']['args'] and data['msg']['args'][0].startswith('{"socket_id":'):
args = json.loads(data['msg']['args'][0])
args['socket_id'] = client_id # HACK: translate socket_id of ui.scene's init event
data['msg']['args'][0] = json.dumps(args)
args = data['msg']['args']
if args and isinstance(args[0], str) and args[0].startswith('{"socket_id":'):
arg0 = json.loads(args[0])
arg0['socket_id'] = client_id # HACK: translate socket_id of ui.scene's init event
args[0] = json.dumps(arg0)
client.handle_event(data['msg'])

@self.relay.on('javascript_response')
Expand Down

0 comments on commit f038b81

Please sign in to comment.