Skip to content

Commit 68c570f

Browse files
committed
Update jupyter.py
1 parent 94aaf95 commit 68c570f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

livekit-rtc/livekit/rtc/jupyter.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import atexit
45
import contextlib
56
import html
@@ -36,14 +37,20 @@ def room_html(url: str, token: str, *, width: str, height: str) -> HTML:
3637
html_text = html_text.replace(token_placeholder, token)
3738
html_text = html_text.replace(url_placeholder, url)
3839

39-
escaped_content = html.escape(html_text, quote=True)
40-
# the extra space in the iframe_html is to avoid IPython suggesting to use IFrame instead.
41-
# it isn't possible in our case, as we need to use srcdoc.
42-
iframe_html = (
43-
f' <iframe width="{width}" height="{height}" frameborder="0" '
44-
f'srcdoc="{escaped_content}"></iframe>'
45-
)
46-
return HTML(iframe_html)
40+
IN_COLAB = "google.colab" in sys.modules
41+
42+
# Colab output already runs inside an iframe, so we don’t need to create an additional one.
43+
# It also injects code into this iframe to handle microphone usage, so we need to preserve it.
44+
if not IN_COLAB:
45+
escaped_content = html.escape(html_text, quote=True)
46+
# the extra space in the iframe_html is to avoid IPython suggesting to use IFrame instead.
47+
# it isn't possible in our case, as we need to use srcdoc.
48+
html_text = (
49+
f' <iframe width="{width}" height="{height}" frameborder="0" '
50+
f'srcdoc="{escaped_content}"></iframe>'
51+
)
52+
53+
return HTML(html_text)
4754

4855

4956
def display_room(url: str, token: str, *, width: str = "100%", height: str = "110px") -> None:

0 commit comments

Comments
 (0)