API docs

Note that ipywebrtc.webrtc is imported in the ipywebrtc namespace, to you can access ipywebrtc.CameraStream instead of ipywebrtc.webrtc.CameraStream.

ipywebrtc

ipywebrtc.chat(room=None, stream=None, **kwargs)[source]

Quick setup for a chatroom.

Parameters:
  • room (str) – Roomname, if not given, a random sequence is generated and printed.
  • stream (MediaStream) – The media stream to share, if not given a CameraStream will be created.
Return type:

WebRTCRoom

ipywebrtc.webrtc

class ipywebrtc.webrtc.MediaStream(**kwargs)[source]

Bases: ipywidgets.widgets.domwidget.DOMWidget

Represents a media source.

See https://developer.mozilla.org/nl/docs/Web/API/MediaStream for details In practice this can a stream coming from an HTMLVideoElement, HTMLCanvasElement (could be a WebGL canvas) or a camera/webcam/microphone using getUserMedia.

The currently supported MediaStream (subclasses) are:
A MediaStream can be used with:
class ipywebrtc.webrtc.VideoStream(**kwargs)[source]

Bases: ipywebrtc.webrtc.MediaStream

Represent a stream of a video element

classmethod from_download(url, **kwargs)[source]

Create a VideoStream from a url by downloading Parameters ———- url: str

The url of the file that will be downloadeded and its bytes assigned to the value trait of the video trait.
**kwargs:
Extra keyword arguments for VideoStream

Returns an VideoStream with the value set from the content of a url.

classmethod from_file(filename, **kwargs)[source]

Create a VideoStream from a local file.

filename: str
The location of a file to read into the value from disk.
**kwargs:
Extra keyword arguments for VideoStream

Returns an VideoStream.

classmethod from_url(url, **kwargs)[source]

Create a VideoStream from a url. This will create a VideoStream from a Video using its url

url: str
The url of the file that will be used for the .video trait.
**kwargs:
Extra keyword arguments for VideoStream

Returns an VideoStream.

playing

Plays the videostream or pauses it.

video

An ipywidgets.Video instance that will be the source of the media stream.

class ipywebrtc.webrtc.CameraStream(**kwargs)[source]

Bases: ipywebrtc.webrtc.MediaStream

Represents a media source by a camera/webcam/microphone using getUserMedia. See https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia for more detail. The constraints trait can be set to specify constraints for the camera or microphone, which is described in the documentation of getUserMedia, such as in the link above, Two convenience methods are avaiable to easily get access to the ‘front’ and ‘back’ camera, when present

>>> CameraStream.facing_user(audio=False)
>>> CameraStream.facing_environment(audio=False)
constraints

Constraints for the camera, see https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia for details.

classmethod facing_environment(audio=True, **kwargs)[source]

Convenience method to get the camera facing the environment (often the back)

audio: bool
Capture audio or not
kwargs:
Extra keyword arguments passed to the CameraStream
classmethod facing_user(audio=True, **kwargs)[source]

Convenience method to get the camera facing the user (often front)

audio: bool
Capture audio or not
kwargs:
Extra keyword arguments passed to the CameraStream
class ipywebrtc.webrtc.WidgetStream(**kwargs)[source]

Bases: ipywebrtc.webrtc.MediaStream

Represents a widget media source.

max_fps

(int, default None) The maximum amount of frames per second to capture, or only on new data when the valeus is None.

widget

An instance of ipywidgets.DOMWidget that will be the source of the MediaStream.

class ipywebrtc.webrtc.ImageStream(**kwargs)[source]

Bases: ipywebrtc.webrtc.MediaStream

Represent a media stream by a static image

classmethod from_download(url, **kwargs)[source]

Create a ImageStream from a url by downloading Parameters ———- url: str

The url of the file that will be downloadeded and its bytes assigned to the value trait of the video trait.
**kwargs:
Extra keyword arguments for ImageStream

Returns an ImageStream with the value set from the content of a url.

classmethod from_file(filename, **kwargs)[source]

Create a ImageStream from a local file.

filename: str
The location of a file to read into the value from disk.
**kwargs:
Extra keyword arguments for ImageStream

Returns an ImageStream.

classmethod from_url(url, **kwargs)[source]

Create a ImageStream from a url. This will create a ImageStream from an Image using its url

url: str
The url of the file that will be used for the .image trait.
**kwargs:
Extra keyword arguments for ImageStream

Returns an ImageStream.

image

An ipywidgets.Image instance that will be the source of the media stream.

class ipywebrtc.webrtc.VideoRecorder(**kwargs)[source]

Bases: ipywebrtc.webrtc.Recorder

Creates a recorder which allows to record a MediaStream widget, play the record in the Notebook, and download it or turn it into a Video widget.

save(filename=None)[source]

Save the video to a file, if no filename is given it is based on the filename trait and the format.

>>> recorder = VideoRecorder(filename='test', format='mp4')
>>> ...
>>> recorder.save()  # will save to test.mp4
>>> recorder.save('foo')  # will save to foo.mp4
>>> recorder.save('foo.dat')  # will save to foo.dat
video

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

class ipywebrtc.webrtc.ImageRecorder(**kwargs)[source]

Bases: ipywebrtc.webrtc.Recorder

Creates a recorder which allows to grab an Image from a MediaStream widget.

format

The format of the image.

image

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

save(filename=None)[source]

Save the image to a file, if no filename is given it is based on the filename trait and the format.

>>> recorder = ImageRecorder(filename='test', format='png')
>>> ...
>>> recorder.save()  # will save to test.png
>>> recorder.save('foo')  # will save to foo.png
>>> recorder.save('foo.dat')  # will save to foo.dat
class ipywebrtc.webrtc.AudioRecorder(**kwargs)[source]

Bases: ipywebrtc.webrtc.Recorder

Creates a recorder which allows to record the Audio of a MediaStream widget, play the record in the Notebook, and download it or turn it into an Audio widget.

audio

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

save(filename=None)[source]

Save the audio to a file, if no filename is given it is based on the filename trait and the format.

>>> recorder = AudioRecorder(filename='test', format='mp3')
>>> ...
>>> recorder.save()  # will save to test.mp3
>>> recorder.save('foo')  # will save to foo.mp3
>>> recorder.save('foo.dat')  # will save to foo.dat
class ipywebrtc.webrtc.WebRTCPeer(**kwargs)[source]

Bases: ipywidgets.widgets.domwidget.DOMWidget

A peer-to-peer webrtc connection

connect()[source]
connected

A boolean (True, False) trait.

failed

A boolean (True, False) trait.

id_local

A trait for unicode strings.

id_remote

A trait for unicode strings.

stream_local

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

stream_remote

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

class ipywebrtc.webrtc.WebRTCRoom(**kwargs)[source]

Bases: ipywidgets.widgets.domwidget.DOMWidget

A ‘chatroom’, which consists of a list of :WebRTCPeer connections

nickname

A trait for unicode strings.

peers

An instance of a Python list.

room

A trait for unicode strings.

room_id

A trait for unicode strings.

stream

A trait whose value must be an instance of a specified class.

The value can also be an instance of a subclass of the specified class.

Subclasses can declare default classes by overriding the klass attribute

streams

An instance of a Python list.

class ipywebrtc.webrtc.WebRTCRoomLocal(**kwargs)[source]

Bases: ipywebrtc.webrtc.WebRTCRoom

class ipywebrtc.webrtc.WebRTCRoomMqtt(**kwargs)[source]

Bases: ipywebrtc.webrtc.WebRTCRoom

Use a mqtt server to connect to other peers

server

A trait for unicode strings.