Skip to content

Commit

Permalink
change: split of ipywebrtc and is now a dependency (until MediaStream…
Browse files Browse the repository at this point in the history
… goes into ipywidgets)
  • Loading branch information
maartenbreddels committed Aug 11, 2017
1 parent 0d9fa06 commit 89bcfcd
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 683 deletions.
3 changes: 2 additions & 1 deletion ipyvolume/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from ipython_genutils.py3compat import string_types, PY3
import ipyvolume as ipv
import ipywidgets
import ipywebrtc

logger = logging.getLogger("ipyvolume")
try:
Expand Down Expand Up @@ -44,7 +45,7 @@ def encode(image):
return [encode(image) for image in flattened]

def texture_to_json(texture, widget):
if isinstance(texture, ipv.HasStream):
if isinstance(texture, ipywebrtc.HasStream):
return ipywidgets.widget_serialization['to_json'](texture, widget)
else:
return image_to_url(texture, widget)
Expand Down
80 changes: 3 additions & 77 deletions ipyvolume/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,88 +12,14 @@
from .transferfunction import *
import warnings
import ipyvolume
import ipywebrtc

logger = logging.getLogger("ipyvolume")

_last_volume_renderer = None
import ipyvolume._version
semver_range_frontend = "~" + ipyvolume._version.__version_js__

class HasStream:
pass # to indicate it has a .stream property on the JS side
@widgets.register
class MediaStream(widgets.DOMWidget, HasStream):
"""Represents a media source."""

_model_module = Unicode('ipyvolume').tag(sync=True)
_view_module = Unicode('ipyvolume').tag(sync=True)
_view_name = Unicode('MediaStreamView').tag(sync=True)
_model_name = Unicode('MediaStreamModel').tag(sync=True)
_view_module_version = Unicode(semver_range_frontend).tag(sync=True)
_model_module_version = Unicode(semver_range_frontend).tag(sync=True)

@widgets.register
class VideoStream(MediaStream):
"""Represents a media source by a video."""
_model_name = Unicode('VideoStreamModel').tag(sync=True)

url = Unicode('').tag(sync=True)
play = traitlets.Bool(True).tag(sync=True)
loop = traitlets.Bool(True).tag(sync=True)

@widgets.register
class CameraStream(MediaStream):
"""Represents a media source by a camera/webcam."""
_model_name = Unicode('CameraStreamModel').tag(sync=True)

# Specify audio constraint and video constraint as a boolean or dict.
audio = traitlets.Bool(True).tag(sync=True)
video = traitlets.Bool(True).tag(sync=True)

def close(self):
self.send({'msg': 'close'})

@widgets.register
class WebRTCPeer(MediaStream):
_model_module = Unicode('ipyvolume').tag(sync=True)
_view_module = Unicode('ipyvolume').tag(sync=True)
_view_name = Unicode('WebRTCPeerView').tag(sync=True)
_model_name = Unicode('WebRTCPeerModel').tag(sync=True)
stream_local = traitlets.Instance(object, allow_none=True).tag(sync=True, **ipywidgets.widget_serialization)
stream_remote = traitlets.Instance(object, allow_none=True).tag(sync=True, **ipywidgets.widget_serialization)
id_local = Unicode('lala').tag(sync=True)
id_remote = Unicode('lala').tag(sync=True)
connected = traitlets.Bool(False, read_only=True).tag(sync=True)
failed = traitlets.Bool(False, read_only=True).tag(sync=True)

def connect(self):
self.send({'msg': 'connect'})

def close(self):
self.send({'msg': 'close'})

class WebRTCRoom(widgets.DOMWidget):
_model_module = Unicode('ipyvolume').tag(sync=True)
#_view_module = Unicode('ipyvolume').tag(sync=True)
#_view_name = Unicode('WebRTCPeerView').tag(sync=True)
_model_name = Unicode('WebRTCRoomModel').tag(sync=True)
room = Unicode('room').tag(sync=True)
stream = traitlets.Instance(object, allow_none=True).tag(sync=True, **ipywidgets.widget_serialization)
id = Unicode(read_only=True).tag(sync=True)
nickname = Unicode('anonymous').tag(sync=True)
peers = traitlets.List(traitlets.Instance(WebRTCPeer), [], allow_none=False).tag(sync=True, **ipywidgets.widget_serialization)
streams = traitlets.List(traitlets.Instance(MediaStream), [], allow_none=False).tag(sync=True, **ipywidgets.widget_serialization)

def close(self):
self.send({'msg': 'close'})

class WebRTCRoomLocal(WebRTCRoom):
_model_name = Unicode('WebRTCRoomLocalModel').tag(sync=True)

class WebRTCRoomMqtt(WebRTCRoom):
_model_name = Unicode('WebRTCRoomMqttModel').tag(sync=True)
server = Unicode('wss://iot.eclipse.org:443/ws').tag(sync=True)

@widgets.register
class Mesh(widgets.DOMWidget):
_view_name = Unicode('MeshView').tag(sync=True)
Expand All @@ -110,7 +36,7 @@ class Mesh(widgets.DOMWidget):
triangles = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization)
lines = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization)
texture = traitlets.Union([
traitlets.Instance(MediaStream),
traitlets.Instance(ipywebrtc.MediaStream),
Unicode(),
traitlets.List(Unicode, [], allow_none=True),
Image(default_value=None, allow_none=True),
Expand Down Expand Up @@ -158,7 +84,7 @@ class Scatter(widgets.DOMWidget):


@widgets.register
class Figure(MediaStream):
class Figure(ipywebrtc.MediaStream):
"""Widget class representing a volume (rendering) using three.js"""
_view_name = Unicode('FigureView').tag(sync=True)
_view_module = Unicode('ipyvolume').tag(sync=True)
Expand Down
2 changes: 1 addition & 1 deletion js/src/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
// Export widget models and views, and the npm package version number.
var _ = require('underscore')
// Export widget models and views, and the npm package version number.
module.exports = _.extend({}, require('./figure.js'), require('./tf.js'), require('./scatter.js'), require('./mesh.js'), require('./utils.js'), require('./media.js'));
module.exports = _.extend({}, require('./figure.js'), require('./tf.js'), require('./scatter.js'), require('./mesh.js'), require('./utils.js'));
module.exports['version'] = require('../package.json').version;
2 changes: 1 addition & 1 deletion js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ __webpack_public_path__ = document.querySelector('body').getAttribute('data-base

var _ = require('underscore')
// Export widget models and views, and the npm package version number.
module.exports = _.extend({}, require('./figure.js'), require('./tf.js'), require('./scatter.js'), require('./mesh.js'), require('./utils.js'), require('./media.js'));
module.exports = _.extend({}, require('./figure.js'), require('./tf.js'), require('./scatter.js'), require('./mesh.js'), require('./utils.js'));
module.exports['version'] = require('../package.json').version;
module.exports.mqtt = require('mqtt')
Loading

0 comments on commit 89bcfcd

Please sign in to comment.