1- # type: ignore
21from __future__ import annotations
32
43import atexit
54import contextlib
5+ import html
66from IPython .core .display import HTML
77from IPython .display import display
88from importlib .resources import as_file , files
1111atexit .register (_resource_stack .close )
1212
1313
14- def room_html (url : str , token : str ) -> HTML :
14+ def room_html (url : str , token : str , * , width : str , height : str ) -> HTML :
1515 """
1616 Generate the HTML needed to embed a LiveKit room.
1717
@@ -35,10 +35,18 @@ def room_html(url: str, token: str) -> HTML:
3535 html_text = index_path .read_text ()
3636 html_text = html_text .replace (token_placeholder , token )
3737 html_text = html_text .replace (url_placeholder , url )
38- return HTML (html_text )
3938
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 )
4047
41- def display_room (url : str , token : str ) -> None :
48+
49+ def display_room (url : str , token : str , * , width : str = "100%" , height : str = "110px" ) -> None :
4250 """
4351 Display a LiveKit room in a Jupyter notebook or Google Colab.
4452
@@ -50,4 +58,4 @@ def display_room(url: str, token: str) -> None:
5058 The rendered HTML will include the provided `url` and `token` in plain text.
5159 Avoid using sensitive tokens in public notebooks (e.g., tokens with long expiration times).
5260 """
53- display (room_html (url , token ))
61+ display (room_html (url , token , width = width , height = height ))
0 commit comments