From f130a60670cd28db223dc95b6b05d4ae78583f1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Wed, 9 Apr 2025 16:30:00 +0200 Subject: [PATCH 1/2] Update jupyter.py --- livekit-rtc/livekit/rtc/jupyter.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/livekit-rtc/livekit/rtc/jupyter.py b/livekit-rtc/livekit/rtc/jupyter.py index 6a62dbe3..0888755a 100644 --- a/livekit-rtc/livekit/rtc/jupyter.py +++ b/livekit-rtc/livekit/rtc/jupyter.py @@ -1,8 +1,8 @@ -# type: ignore from __future__ import annotations import atexit import contextlib +import html from IPython.core.display import HTML from IPython.display import display from importlib.resources import as_file, files @@ -11,7 +11,7 @@ atexit.register(_resource_stack.close) -def room_html(url: str, token: str) -> HTML: +def room_html(url: str, token: str, *, width: str, height: str) -> HTML: """ Generate the HTML needed to embed a LiveKit room. @@ -35,10 +35,18 @@ def room_html(url: str, token: str) -> HTML: html_text = index_path.read_text() html_text = html_text.replace(token_placeholder, token) html_text = html_text.replace(url_placeholder, url) - return HTML(html_text) + escaped_content = html.escape(html_text, quote=True) + # the extra space in the iframe_html is to avoid IPython suggesting to use IFrame instead. + # it isn't possible in our case, as we need to use srcdoc. + iframe_html = ( + f' ' + ) + return HTML(iframe_html) -def display_room(url: str, token: str) -> None: + +def display_room(url: str, token: str, *, width: str = "100%", height: str = "110px") -> None: """ Display a LiveKit room in a Jupyter notebook or Google Colab. @@ -50,4 +58,4 @@ def display_room(url: str, token: str) -> None: The rendered HTML will include the provided `url` and `token` in plain text. Avoid using sensitive tokens in public notebooks (e.g., tokens with long expiration times). """ - display(room_html(url, token)) + display(room_html(url, token, width=width, height=height)) From 4307b2c7fb2cf62e32f8acb46907df79d8ef9397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?The=CC=81o=20Monnom?= Date: Wed, 9 Apr 2025 21:31:01 +0200 Subject: [PATCH 2/2] Update check-types.yml --- .github/workflows/check-types.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-types.yml b/.github/workflows/check-types.yml index 0e6e6e04..00ce18ce 100644 --- a/.github/workflows/check-types.yml +++ b/.github/workflows/check-types.yml @@ -29,7 +29,7 @@ jobs: run: python -m pip install --upgrade mypy - name: Install packages - run: python -m pip install pytest ./livekit-api ./livekit-protocol ./livekit-rtc pydantic numpy + run: python -m pip install pytest ./livekit-api ./livekit-protocol ./livekit-rtc pydantic numpy ipython - name: Check Types run: python -m mypy --install-type --non-interactive -p 'livekit-protocol' -p 'livekit-api' -p 'livekit-rtc'