示例#1
0
 def incoming_session(self, session):
     log.info('New incoming session from %s' % session.remote_identity.uri)
     audio_streams = [
         stream for stream in session.proposed_streams
         if stream.type == 'audio'
     ]
     chat_streams = [
         stream for stream in session.proposed_streams
         if stream.type == 'chat'
     ]
     if not audio_streams and not chat_streams:
         session.reject(488)
         return
     self.pending_sessions.append(session)
     NotificationCenter().add_observer(self, sender=session)
     if audio_streams:
         session.send_ring_indication()
     if chat_streams:
         for stream in chat_streams:
             # Disable chatroom capabilities other than nickname
             stream.chatroom_capabilities = ['nickname']
     streams = [
         streams[0] for streams in (audio_streams, chat_streams) if streams
     ]
     reactor.callLater(4 if audio_streams else 0, self.accept_session,
                       session, streams)
示例#2
0
 def _NH_ChatStreamGotMessage(self, notification):
     stream = notification.sender
     message = notification.data.message
     if message.content_type not in ('text/html', 'text/plain'):
         log.info(u'Unsupported content type: %s, ignoring message' %
                  message.content_type)
         stream.msrp_session.send_report(notification.data.chunk, 413,
                                         'Unwanted message')
         return
     stream.msrp_session.send_report(notification.data.chunk, 200, 'OK')
     # Send MSRP chat message to other participants
     session = stream.session
     self.incoming_message_queue.send((session, 'msrp_message', message))
     # Send MSRP chat message to IRC chat room
     if message.content_type == 'text/html':
         content = html2text(message.content)
     elif message.content_type == 'text/plain':
         content = message.content
     else:
         log.warning('unexpected message type: %s' % message.content_type)
         return
     sender = message.sender
     irc_message = '%s: %s' % (format_identity(sender), content)
     if self.irc_protocol is not None:
         self.irc_protocol.send_message(irc_message.encode('utf-8'))
     else:
         self.pending_messages.append(irc_message)
示例#3
0
 def _NH_RTPStreamDidTimeout(self, notification):
     stream = notification.sender
     if stream.type != 'audio':
         return
     session = stream.session
     log.info(u'Audio stream for session %s timed out' %
              format_identity(session.remote_identity))
     if session.streams == [stream]:
         session.end()
示例#4
0
 def _NH_SIPSessionDidChangeHoldState(self, notification):
     session = notification.sender
     if notification.data.originator == 'remote':
         if notification.data.on_hold:
             log.info(u'%s has put the audio session on hold' %
                      format_identity(session.remote_identity))
         else:
             log.info(u'%s has taken the audio session out of hold' %
                      format_identity(session.remote_identity))
         self.get_conference_info()
示例#5
0
 def _NH_SIPSessionDidEnd(self, notification):
     session = notification.sender
     log.info('Session from %s ended' % session.remote_identity.uri)
     NotificationCenter().remove_observer(self, sender=session)
     room = IRCRoom.get_room(session.request_uri)
     if session in room.sessions:
         # We could get this notifiction even if we didn't get SIPSessionDidStart
         room.remove_session(session)
     if room.empty:
         room.stop()
         try:
             self.rooms.remove(room)
         except KeyError:
             pass
示例#6
0
 def remove_session(self, session):
     notification_center = NotificationCenter()
     try:
         chat_stream = next(stream for stream in session.streams or []
                            if stream.type == 'chat')
     except StopIteration:
         pass
     else:
         notification_center.remove_observer(self, sender=chat_stream)
     try:
         audio_stream = next(stream for stream in session.streams or []
                             if stream.type == 'audio')
     except StopIteration:
         pass
     else:
         notification_center.remove_observer(self, sender=audio_stream)
         try:
             self.audio_conference.remove(audio_stream)
         except ValueError:
             # User may hangup before getting bridged into the conference
             pass
         if len(self.audio_conference.streams) == 0:
             self.audio_conference.hold()
     notification_center.remove_observer(self, sender=session)
     self.sessions.remove(session)
     self.get_conference_info()
     log.info(u'%s left conference %s after %s' %
              (format_identity(session.remote_identity), self.uri,
               format_session_duration(session)))
     if not self.sessions:
         log.info(u'Last participant left conference %s' % self.uri)
     if str(session.remote_identity.uri) not in set(
             str(s.remote_identity.uri) for s in self.sessions
             if s is not session):
         self.dispatch_server_message(
             '%s has left the room after %s' %
             (format_identity(session.remote_identity),
              format_session_duration(session)))
示例#7
0
    def _NH_SIPSessionDidRenegotiateStreams(self, notification):
        session = notification.sender
        for stream in notification.data.added_streams:
            notification.center.add_observer(self, sender=stream)
            log.info(u'%s has added %s to %s' % (format_identity(
                session.remote_identity), stream.type, self.uri))
            self.dispatch_server_message(
                '%s has added %s' %
                (format_identity(session.remote_identity), stream.type),
                exclude=session)
            if stream.type == 'audio':
                log.info(
                    u'Audio stream using %s/%sHz, end-points: %s:%d <-> %s:%d'
                    % (stream.codec, stream.sample_rate,
                       stream.local_rtp_address, stream.local_rtp_port,
                       stream.remote_rtp_address, stream.remote_rtp_port))
                welcome_handler = WelcomeHandler(self, session)
                welcome_handler.start(welcome_prompt=False)

        for stream in notification.data.removed_streams:
            notification.center.remove_observer(self, sender=stream)
            log.info(u'%s has removed %s from %s' % (format_identity(
                session.remote_identity), stream.type, self.uri))
            self.dispatch_server_message(
                '%s has removed %s' %
                (format_identity(session.remote_identity), stream.type),
                exclude=session)
            if stream.type == 'audio':
                try:
                    self.audio_conference.remove(stream)
                except ValueError:
                    # User may hangup before getting bridged into the conference
                    pass
                if len(self.audio_conference.streams) == 0:
                    self.audio_conference.hold()
            if not session.streams:
                log.info(
                    u'%s has removed all streams from %s, session will be terminated'
                    % (format_identity(session.remote_identity), self.uri))
                session.end()
        self.get_conference_info()
示例#8
0
 def add_session(self, session):
     notification_center = NotificationCenter()
     notification_center.add_observer(self, sender=session)
     self.sessions.append(session)
     try:
         chat_stream = next(stream for stream in session.streams
                            if stream.type == 'chat')
     except StopIteration:
         pass
     else:
         notification_center.add_observer(self, sender=chat_stream)
     try:
         audio_stream = next(stream for stream in session.streams
                             if stream.type == 'audio')
     except StopIteration:
         pass
     else:
         notification_center.add_observer(self, sender=audio_stream)
         log.info(
             u'Audio stream using %s/%sHz, end-points: %s:%d <-> %s:%d' %
             (audio_stream.codec, audio_stream.sample_rate,
              audio_stream.local_rtp_address, audio_stream.local_rtp_port,
              audio_stream.remote_rtp_address,
              audio_stream.remote_rtp_port))
         welcome_handler = WelcomeHandler(self, session)
         welcome_handler.start()
     self.get_conference_info()
     if len(self.sessions) == 1:
         log.info(u'%s started conference %s %s' %
                  (format_identity(session.remote_identity), self.uri,
                   format_stream_types(session.streams)))
     else:
         log.info(u'%s joined conference %s %s' %
                  (format_identity(session.remote_identity), self.uri,
                   format_stream_types(session.streams)))
     if str(session.remote_identity.uri) not in set(
             str(s.remote_identity.uri) for s in self.sessions
             if s is not session):
         self.dispatch_server_message(
             '%s has joined the room %s' %
             (format_identity(session.remote_identity),
              format_stream_types(session.streams)),
             exclude=session)
示例#9
0
 def clientConnectionLost(self, connector, failure):
     log.info('Disconnected from IRC: %s' % failure.getErrorMessage())
     if not self.stop_requested:
         log.info('Reconnecting...')
         connector.connect()
示例#10
0
 def joined(self, channel):
     log.info('Logged into %s channel' % channel)
     NotificationCenter().post_notification(
         'IRCBotJoinedChannel', self.factory,
         NotificationData(channel=self.factory.channel))
示例#11
0
 def kickedFrom(self, channel, kicker, message):
     log.info('Got kicked from %s by %s: %s. Rejoining...' %
              (channel, kicker, message))
     self.join(self.factory.channel)
示例#12
0
 def signedOn(self):
     log.info('Logging into %s channel...' % self.factory.channel)
     self.join(self.factory.channel)
示例#13
0
 def connectionMade(self):
     irc.IRCClient.connectionMade(self)
     log.info('Connection to IRC has been established')
     NotificationCenter().post_notification('IRCBotGotConnected',
                                            self.factory,
                                            NotificationData(protocol=self))
示例#14
0
 def _NH_SIPSessionDidFail(self, notification):
     session = notification.sender
     self.pending_sessions.remove(session)
     log.info('Session from %s failed' % session.remote_identity.uri)