WidgetStream¶
A WidgetStream creates a MediaStream out of any widget.
[1]:
from ipywebrtc import WidgetStream, VideoStream
Example with pythreejs: streaming of a webgl canvas¶
[2]:
from pythreejs import Mesh, SphereGeometry, MeshLambertMaterial, PerspectiveCamera, DirectionalLight, Scene, AmbientLight, Renderer, OrbitControls
ball = Mesh(
geometry=SphereGeometry(radius=1),
material=MeshLambertMaterial(color='red'),
position=[2, 1, 0]
)
c = PerspectiveCamera(
position=[0, 5, 5], up=[0, 1, 0],
children=[DirectionalLight(color='white', position=[3, 5, 1], intensity=0.5)]
)
scene = Scene(children=[ball, c, AmbientLight(color='#777777')])
renderer = Renderer(
camera=c,
scene=scene,
controls=[OrbitControls(controlling=c)]
)
renderer
[3]:
# the webgl_stream will be updated after the scene has changed (so drag the above ball around if nothing happens)
webgl_stream = WidgetStream(widget=renderer)
webgl_stream
[4]:
# You can limit the fps
webgl_stream2 = WidgetStream(widget=renderer, max_fps=5)
webgl_stream2
Example with ipywidgets: streaming of a slider widget¶
[5]:
from ipywidgets import FloatSlider
slider = FloatSlider(
value=7.5,
step=0.1,
description='Test:',
disabled=False,
continuous_update=False,
orientation='horizontal',
readout=True,
readout_format='.1f',
)
slider
[6]:
widget_stream = WidgetStream(widget=slider, max_fps=1)
widget_stream
[ ]:
# Close the stream
widget_stream.close()
Example with ipyleaflet: streaming of a map widget¶
[7]:
from ipyleaflet import Map
m = Map(center=(46, 14), zoom=5)
m
[8]:
map_stream = WidgetStream(widget=m, max_fps=1)
map_stream
[ ]:
map_stream.close()
[ ]: