.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/20_stream/viz_widget.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_20_stream_viz_widget.py: ======================================================== Streaming FURY with WebRTC/MJPEG using the Widget Object ======================================================== The Widget Object simplifies the process of streaming your data visualization with WebRTC or MJPEG. Encoding. Other users can view and interact with your data visualization in real-time using a web-browser. By default, the widget will open a local server on port 8000. With the encoding parameter you can choose between mjpeg or webrtc. WebRTC is a more robust option and can be used to perform a live streaming with a low-latency connection. However, to use webRTC you need to install the aiortc library. .. code-block:: bash pip install aiortc In addition, if you don't have ffmpeg installed, you need to install it. Linux `apt install libavdevice-dev libavfilter-dev libopus-dev libvpx-dev pkg-config` OS X `brew install ffmpeg opus libvpx pkg-config` Notes ----- For this example your python version should be 3.8 or greater .. GENERATED FROM PYTHON SOURCE LINES 38-57 .. code-block:: Python import asyncio import platform import time import numpy as np import fury interactive = False window_size = (720, 500) N = 4 centers = np.random.normal(size=(N, 3)) colors = np.random.uniform(0.1, 1.0, size=(N, 3)) actors = fury.actor.sphere(centers, opacity=0.5, radii=0.4, colors=colors) scene = fury.window.Scene() scene.add(actors) showm = fury.window.ShowManager(scene=scene, size=(window_size[0], window_size[1])) .. GENERATED FROM PYTHON SOURCE LINES 58-59 Create a stream widget .. GENERATED FROM PYTHON SOURCE LINES 59-68 .. code-block:: Python widget = fury.stream.Widget(showm, port=8000) # if you want to use webRTC, you can pass the argument to choose this encoding # which is a more robust option. # `widget = Widget(showm, port=8000, encoding='webrtc')` time_sleep = 1000 if interactive else 1 .. GENERATED FROM PYTHON SOURCE LINES 69-72 If you want to use the widget in a Windows environment without the WSL you need to use the asyncio version of the widget. .. GENERATED FROM PYTHON SOURCE LINES 72-89 .. code-block:: Python if platform.system() == "Windows": async def main(): widget.start() await asyncio.sleep(time_sleep) widget.stop() loop = asyncio.get_event_loop() loop.run_until_complete(main()) else: # Running the widget in a normal Python environment in Linux or MacOS # we can use the normal version of the widget. widget.start() time.sleep(time_sleep) widget.stop() fury.window.record(scene=showm.scene, size=window_size, out_path="viz_widget.png") .. _sphx_glr_download_auto_examples_20_stream_viz_widget.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_widget.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_widget.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_widget.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_