Skip to content

Commit fe23438

Browse files
committed
simplify
1 parent 041e4ea commit fe23438

File tree

1 file changed

+7
-43
lines changed

1 file changed

+7
-43
lines changed

livekit-rtc/livekit/rtc/jupyter.py

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import atexit
44
import sys
55
import contextlib
6-
import os
76
from IPython.core.display import HTML, JSON
87
from IPython.display import display
98
from importlib.resources import as_file, files
@@ -12,63 +11,28 @@
1211
atexit.register(_resource_stack.close)
1312

1413

15-
def room_html(url: str | None = None, token: str | None = None) -> HTML:
16-
"""
17-
Display a LiveKit room in Jupyter or Google Colab.
18-
19-
Args:
20-
url (str | None): The LiveKit room URL. If None, the function attempts
21-
to use the LIVEKIT_JUPYTER_URL environment variable in a local or
22-
Colab environment.
23-
token (str | None): The LiveKit join token. If None, the function
24-
attempts to use the LIVEKIT_JUPYTER_URL environment variable in a
25-
local or Colab environment.
26-
27-
Returns:
28-
IPython.core.display.HTML: The HTML object that embeds the LiveKit room.
29-
30-
Raises:
31-
ValueError: If both `url` and `token` are None and
32-
`LIVEKIT_JUPYTER_URL` is not set.
33-
"""
14+
def room_html(url: str, token: str) -> HTML:
3415
IN_COLAB = "google.colab" in sys.modules
3516

36-
if url is None and token is None:
37-
if IN_COLAB:
38-
from google.colab import userdata
39-
40-
LIVEKIT_JUPYTER_URL = userdata.get("LIVEKIT_JUPYTER_URL")
41-
else:
42-
LIVEKIT_JUPYTER_URL = os.environ.get("LIVEKIT_JUPYTER_URL")
43-
44-
if not LIVEKIT_JUPYTER_URL:
45-
raise ValueError("LIVEKIT_JUPYTER_URL must be set (or url/token must be provided).")
46-
4717
if IN_COLAB:
4818
from google.colab import output
4919

50-
def create_join_token():
51-
return JSON({"url": url or "", "token": token or ""})
20+
def get_join_token():
21+
return JSON({"url": url, "token": token})
5222

53-
output.register_callback("get_join_token", create_join_token)
23+
output.register_callback("get_join_token", get_join_token)
5424

55-
# Load the local HTML file that embeds the LiveKit client
5625
index_path = files("livekit.rtc.resources") / "jupyter-html" / "index.html"
5726
index_path = _resource_stack.enter_context(as_file(index_path))
58-
5927
return HTML(index_path.read_text())
6028

6129

62-
def display_room(url: str | None = None, token: str | None = None) -> None:
30+
def display_room(url: str, token: str) -> None:
6331
"""
6432
Display a LiveKit room in Jupyter or Google Colab.
6533
6634
Args:
67-
url (str | None): The LiveKit room URL. If None, the function attempts
68-
to use the LIVEKIT_JUPYTER_URL environment variable in a local or
69-
Colab environment.
70-
token (str | None): The LiveKit join token. If None, the function
71-
attempts to use the LIVEKIT_JUPYTER_URL environment variable in a
72-
local or Colab environment.
35+
url (str | None): The LiveKit room URL.
36+
token (str | None): The LiveKit join token.
7337
"""
7438
display(room_html(url, token))

0 commit comments

Comments
 (0)