Commit 9e8103e9 authored by Saul Ibarra's avatar Saul Ibarra

Added active and proposed properties to StreamContainer

parent dd4ddd93
...@@ -212,7 +212,14 @@ class StreamSet(object): ...@@ -212,7 +212,14 @@ class StreamSet(object):
return self._stream_map.get(key, default) return self._stream_map.get(key, default)
class StreamContainer(object): class StreamMap(dict):
def __init__(self):
super(StreamMap, self).__init__()
self.active_map = {}
self.proposed_map = {}
class StreamContainerView(object):
def __init__(self, session, stream_map): def __init__(self, session, stream_map):
self._session = session self._session = session
self._stream_map = stream_map self._stream_map = stream_map
...@@ -241,22 +248,35 @@ class StreamContainer(object): ...@@ -241,22 +248,35 @@ class StreamContainer(object):
def get(self, key, default=None): def get(self, key, default=None):
return self._stream_map.get(key, default) return self._stream_map.get(key, default)
class StreamContainer(StreamContainerView):
@property
def active(self):
return StreamContainerView(self._session, self._stream_map.active_map)
@property
def proposed(self):
return StreamContainerView(self._session, self._stream_map.proposed_map)
def add(self, stream): def add(self, stream):
notification_center = NotificationCenter() assert stream not in self
old_stream = self._stream_map.get(stream.type, None)
if old_stream is not None:
notification_center.remove_observer(self._session, sender=old_stream)
stream.blink_session = self._session stream.blink_session = self._session
self._stream_map[stream.type] = stream self._stream_map[stream.type] = self._stream_map.proposed_map[stream.type] = stream
notification_center = NotificationCenter()
notification_center.add_observer(self._session, sender=stream) notification_center.add_observer(self._session, sender=stream)
def remove(self, stream): def remove(self, stream):
# is it a good choice to silently ignore removing a stream that is not in the container? -Dan assert stream in self
if stream in self:
self._stream_map.pop(stream.type) self._stream_map.pop(stream.type)
self._stream_map.active_map.pop(stream.type, None)
self._stream_map.proposed_map.pop(stream.type, None)
notification_center = NotificationCenter() notification_center = NotificationCenter()
notification_center.remove_observer(self._session, sender=stream) notification_center.remove_observer(self._session, sender=stream)
def set_active(self, stream):
assert stream in self
self._stream_map.active_map[stream.type] = self._stream_map.proposed_map.pop(stream.type)
def extend(self, iterable): def extend(self, iterable):
for item in iterable: for item in iterable:
self.add(item) self.add(item)
...@@ -276,7 +296,7 @@ class defaultweakobjectmap(weakobjectmap): ...@@ -276,7 +296,7 @@ class defaultweakobjectmap(weakobjectmap):
class StreamListDescriptor(object): class StreamListDescriptor(object):
def __init__(self): def __init__(self):
self.values = defaultweakobjectmap(dict) self.values = defaultweakobjectmap(StreamMap)
def __get__(self, obj, objtype): def __get__(self, obj, objtype):
if obj is None: if obj is None:
...@@ -802,6 +822,8 @@ class BlinkSession(QObject): ...@@ -802,6 +822,8 @@ class BlinkSession(QObject):
def _NH_SIPSessionDidStart(self, notification): def _NH_SIPSessionDidStart(self, notification):
for stream in set(self.streams).difference(notification.data.streams): for stream in set(self.streams).difference(notification.data.streams):
self.streams.remove(stream) self.streams.remove(stream)
for stream in self.streams:
self.streams.set_active(stream)
if self.state not in ('ending', 'ended', 'deleted'): if self.state not in ('ending', 'ended', 'deleted'):
self.state = 'connected' self.state = 'connected'
self.timer.start() self.timer.start()
...@@ -841,6 +863,7 @@ class BlinkSession(QObject): ...@@ -841,6 +863,7 @@ class BlinkSession(QObject):
self.state = 'connected' self.state = 'connected'
for stream in proposed_streams: for stream in proposed_streams:
if stream in accepted_streams: if stream in accepted_streams:
self.streams.set_active(stream)
notification.center.post_notification('BlinkSessionDidAddStream', sender=self, data=NotificationData(stream=stream)) notification.center.post_notification('BlinkSessionDidAddStream', sender=self, data=NotificationData(stream=stream))
else: else:
self.streams.remove(stream) self.streams.remove(stream)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment