Commit cd650aec authored by Saul Ibarra's avatar Saul Ibarra

Add remote proposed streams early to the container

parent 5676a21b
...@@ -626,14 +626,10 @@ class BlinkSession(QObject): ...@@ -626,14 +626,10 @@ class BlinkSession(QObject):
def accept_proposal(self, streams): def accept_proposal(self, streams):
assert self.state == 'connected/received_proposal' assert self.state == 'connected/received_proposal'
duplicate_types = sorted(stream.type for stream in streams if stream.type in self.streams)
if duplicate_types:
raise RuntimeError('accepting proposal would result in duplicated streams for: %s' % ', '.join(duplicate_types))
self.sip_session.accept_proposal(streams) self.sip_session.accept_proposal(streams)
notification_center = NotificationCenter() notification_center = NotificationCenter()
for stream in streams: for stream in streams:
self.info.streams[stream.type]._reset() self.info.streams[stream.type]._reset()
self.streams.add(stream)
notification_center.post_notification('BlinkSessionWillAddStream', sender=self, data=NotificationData(stream=stream)) notification_center.post_notification('BlinkSessionWillAddStream', sender=self, data=NotificationData(stream=stream))
notification_center.post_notification('BlinkSessionInfoUpdated', sender=self, data=NotificationData(elements={'media', 'statistics'})) notification_center.post_notification('BlinkSessionInfoUpdated', sender=self, data=NotificationData(elements={'media', 'statistics'}))
...@@ -854,6 +850,8 @@ class BlinkSession(QObject): ...@@ -854,6 +850,8 @@ class BlinkSession(QObject):
if notification.data.originator == 'local': if notification.data.originator == 'local':
self.state = 'connected/sent_proposal' self.state = 'connected/sent_proposal'
else: else:
for stream in (stream for stream in notification.data.proposed_streams if stream.type not in self.streams):
self.streams.add(stream)
self.state = 'connected/received_proposal' self.state = 'connected/received_proposal'
def _NH_SIPSessionProposalAccepted(self, notification): def _NH_SIPSessionProposalAccepted(self, notification):
...@@ -867,6 +865,7 @@ class BlinkSession(QObject): ...@@ -867,6 +865,7 @@ class BlinkSession(QObject):
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)
if notification.data.originator == 'local':
notification.center.post_notification('BlinkSessionDidNotAddStream', sender=self, data=NotificationData(stream=stream)) notification.center.post_notification('BlinkSessionDidNotAddStream', sender=self, data=NotificationData(stream=stream))
if accepted_streams: if accepted_streams:
self.info.streams._update(self.streams) self.info.streams._update(self.streams)
...@@ -875,6 +874,7 @@ class BlinkSession(QObject): ...@@ -875,6 +874,7 @@ class BlinkSession(QObject):
def _NH_SIPSessionProposalRejected(self, notification): def _NH_SIPSessionProposalRejected(self, notification):
for stream in set(notification.data.proposed_streams).intersection(self.streams): for stream in set(notification.data.proposed_streams).intersection(self.streams):
self.streams.remove(stream) self.streams.remove(stream)
if notification.data.originator == 'local':
notification.center.post_notification('BlinkSessionDidNotAddStream', sender=self, data=NotificationData(stream=stream)) notification.center.post_notification('BlinkSessionDidNotAddStream', sender=self, data=NotificationData(stream=stream))
if self.state not in ('ending', 'ended', 'deleted'): if self.state not in ('ending', 'ended', 'deleted'):
self.state = 'connected' self.state = 'connected'
...@@ -4021,25 +4021,14 @@ class SessionManager(object): ...@@ -4021,25 +4021,14 @@ class SessionManager(object):
def _process_remote_proposal(self, blink_session): def _process_remote_proposal(self, blink_session):
sip_session = blink_session.sip_session sip_session = blink_session.sip_session
proposed_streams = blink_session.streams.proposed
current_stream_types = set(stream.type for stream in sip_session.streams) if not proposed_streams or proposed_streams.types == {'file-transfer'}:
stream_map = defaultdict(list) sip_session.reject_proposal(488)
# TODO: we should fetch the proposed streams from the BlinkSession -Saul
for stream in (stream for stream in sip_session.proposed_streams if stream.type not in current_stream_types):
stream_map[stream.type].append(stream)
proposed_stream_types = set(stream_map)
audio_streams = stream_map['audio']
video_streams = stream_map['video']
chat_streams = stream_map['chat']
screensharing_streams = stream_map['screen-sharing']
if not proposed_stream_types or proposed_stream_types == {'file-transfer'}:
sip_session.reject_proposal(488) # maybe add a reject_proposal on blink_session for symmetry? -Dan
return return
if proposed_stream_types == {'chat'}: if proposed_streams.types == {'chat'}:
blink_session.accept_proposal([chat_streams[0]]) blink_session.accept_proposal(list(proposed_streams))
return return
sip_session.send_ring_indication() sip_session.send_ring_indication()
...@@ -4047,10 +4036,10 @@ class SessionManager(object): ...@@ -4047,10 +4036,10 @@ class SessionManager(object):
contact = blink_session.contact contact = blink_session.contact
contact_uri = blink_session.contact_uri contact_uri = blink_session.contact_uri
audio_stream = audio_streams[0] if audio_streams else None audio_stream = proposed_streams.get('audio')
video_stream = video_streams[0] if video_streams else None video_stream = proposed_streams.get('video')
chat_stream = chat_streams[0] if chat_streams else None chat_stream = proposed_streams.get('chat')
screensharing_stream = screensharing_streams[0] if screensharing_streams else None screensharing_stream = proposed_streams.get('screen-sharing')
dialog = IncomingDialog() # The dialog is constructed without the main window as parent so that on Linux it is displayed on the current workspace rather than the one where the main window is. dialog = IncomingDialog() # The dialog is constructed without the main window as parent so that on Linux it is displayed on the current workspace rather than the one where the main window is.
incoming_request = IncomingRequest(dialog, sip_session, contact, contact_uri, proposal=True, audio_stream=audio_stream, video_stream=video_stream, chat_stream=chat_stream, screensharing_stream=screensharing_stream) incoming_request = IncomingRequest(dialog, sip_session, contact, contact_uri, proposal=True, audio_stream=audio_stream, video_stream=video_stream, chat_stream=chat_stream, screensharing_stream=screensharing_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