mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-05 18:09:23 +08:00
add code (#223)
This commit is contained in:
@@ -8,6 +8,7 @@ import logging
|
||||
import tempfile
|
||||
import traceback
|
||||
from contextvars import ContextVar
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Callable, Literal, Protocol, TypedDict, cast
|
||||
|
||||
import av
|
||||
@@ -61,6 +62,22 @@ current_channel: ContextVar[DataChannel | None] = ContextVar(
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
class Context:
|
||||
webrtc_id: str
|
||||
|
||||
|
||||
current_context: ContextVar[Context | None] = ContextVar(
|
||||
"current_context", default=None
|
||||
)
|
||||
|
||||
|
||||
def get_current_context() -> Context:
|
||||
if not (ctx := current_context.get()):
|
||||
raise RuntimeError("No context found")
|
||||
return ctx
|
||||
|
||||
|
||||
def _send_log(message: str, type: str) -> None:
|
||||
async def _send(channel: DataChannel) -> None:
|
||||
channel.send(
|
||||
|
||||
Reference in New Issue
Block a user