self.notification_center.post_notification("SIPSessionNewOutgoing", self, TimestampedNotificationData(streams=[stream for is_added, stream in zip([audio, chat], ["audio", "chat"]) if is_added]))
self.notification_center.post_notification("SIPSessionGotStreamUpdate", self, TimestampedNotificationData(streams=[key for key, val in dict(audio=self.has_audio, chat=self.has_chat).iteritems() if val]))
del self.session_manager.audio_transport_mapping[self.audio_transport]
self.audio_transport = None
had_audio = self.has_audio
self.has_audio = False
if had_audio:
self.notification_center.post_notification("SIPSessionGotStreamUpdate", self, TimestampedNotificationData(streams=[key for key, val in dict(audio=self.has_audio, chat=self.has_chat).iteritems() if val]))
self.notification_center.post_notification("SIPSessionGotStreamUpdate", self, TimestampedNotificationData(streams=[key for key, val in dict(audio=self.has_audio, chat=self.has_chat).iteritems() if val]))
msrp_chat.end()
def _cancel_media(self):
# This should, in principle, never throw exceptions
if self.audio_transport is not None and not self.audio_transport.is_active:
self._stop_audio()
if self.chat_transport is not None and not self.chat_transport.is_active:
self._stop_chat()
def send_dtmf(self, digit):
if self.audio_transport is None or not self.audio_transport.is_active:
raise SessionStateError("This SIP session does not have an active audio RTP stream to transmit DMTF over")
proposed_media = list(set(("chat" if media.media == "message" else media.media) for media in inv.get_offered_remote_sdp().media if media.media in ["audio", "message"] and media.port != 0))
for sdp_index, media in enumerate(proposed_remote_sdp.media):
if sdp_index == session._audio_sdp_index and session.audio_transport is not None:
if media.media != "audio":
inv.respond_to_reinvite(488, extra_headers={"Warning": '%03d %s "%s"' % (399, Engine().user_agent, 'Media at index %d changed from "%s" to "%s"' % (sdp_index, "audio", media.media))})
return
if media.port == 0:
remove_audio = True
elif sdp_index == session._chat_sdp_index and session.chat_transport is not None:
if media.media != "message":
inv.respond_to_reinvite(488, extra_headers={"Warning": '%03d %s "%s"' % (399, Engine().user_agent, 'Media at index %d changed from "%s" to "%s"' % (sdp_index, "message", media.media))})
return
if media.port == 0:
remove_chat = True
elif media.media == "audio" and session.audio_transport is None and media.port != 0:
add_audio = True
elif media.media == "message" and session.chat_transport is None and media.port != 0:
add_chat = True
if any([add_audio, add_chat]):
if any([remove_audio, remove_chat]):
inv.respond_to_reinvite(488, extra_headers={"Warning": '%03d %s "%s"' % (399, Engine().user_agent, "Both removing AND adding a media stream is currently not supported")})
return
inv.respond_to_reinvite(180)
session._change_state("PROPOSED")
self.notification_center.post_notification("SIPSessionGotStreamProposal", session, TimestampedNotificationData(streams=[stream for is_added, stream in zip([add_audio, add_chat], ["audio", "chat"]) if is_added], proposer="remote"))
self.notification_center.post_notification("SIPSessionGotStreamUpdate", session, TimestampedNotificationData(streams=[key for key, val in dict(audio=session.has_audio, chat=session.has_chat).iteritems() if val]))
self.notification_center.post_notification("SIPSessionGotStreamUpdate", session, TimestampedNotificationData(streams=[key for key, val in dict(audio=session.has_audio, chat=session.has_chat).iteritems() if val]))
self.notification_center.post_notification("SIPSessionGotStreamUpdate", session, TimestampedNotificationData(streams=[key for key, val in dict(audio=session.has_audio, chat=session.has_chat).iteritems() if val]))