Ejemplo n.º 1
0
    def __init__(self, session, media, transport=None):
        if transport is None:
            transport = JingleTransportICEUDP(None)
        JingleContent.__init__(self, session, transport)
        self.media = media
        self._dtmf_running = False
        self.farstream_media = {
            'audio': Farstream.MediaType.AUDIO,
            'video': Farstream.MediaType.VIDEO
        }[media]

        self.pipeline = None
        self.src_bin = None
        self.stream_failed_once = False

        self.candidates_ready = False  # True when local candidates are prepared

        # TODO
        self.conference = None
        self.funnel = None
        self.p2psession = None
        self.p2pstream = None

        self.callbacks['session-initiate'] += [self.__on_remote_codecs]
        self.callbacks['content-add'] += [self.__on_remote_codecs]
        self.callbacks['description-info'] += [self.__on_remote_codecs]
        self.callbacks['content-accept'] += [self.__on_remote_codecs]
        self.callbacks['session-accept'] += [self.__on_remote_codecs]
        self.callbacks['session-terminate'] += [self.__stop]
        self.callbacks['session-terminate-sent'] += [self.__stop]
Ejemplo n.º 2
0
 def __init__(self, session, transport=None, file_props=None,
 use_security=False):
     JingleContent.__init__(self, session, transport)
     log.info("transport value: %s" % transport)
     # events we might be interested in
     self.callbacks['session-initiate'] += [self.__on_session_initiate]
     self.callbacks['session-initiate-sent'] += [
         self.__on_session_initiate_sent]
     self.callbacks['content-add'] += [self.__on_session_initiate]
     self.callbacks['session-accept'] += [self.__on_session_accept]
     self.callbacks['session-terminate'] += [self.__on_session_terminate]
     self.callbacks['session-info'] += [self.__on_session_info]
     self.callbacks['transport-accept'] += [self.__on_transport_accept]
     self.callbacks['transport-replace'] += [self.__on_transport_replace]
     self.callbacks['session-accept-sent'] += [self.__transport_setup]
     # fallback transport method
     self.callbacks['transport-reject'] += [self.__on_transport_reject]
     self.callbacks['transport-info'] += [self.__on_transport_info]
     self.callbacks['iq-result'] += [self.__on_iq_result]
     self.use_security = use_security
     self.x509_fingerprint = None
     self.file_props = file_props
     self.weinitiate = self.session.weinitiate
     self.werequest = self.session.werequest
     if self.file_props is not None:
         if self.session.werequest:
             self.file_props.sender = self.session.peerjid
             self.file_props.receiver = self.session.ourjid
         else:
             self.file_props.sender = self.session.ourjid
             self.file_props.receiver = self.session.peerjid
         self.file_props.session_type = 'jingle'
         self.file_props.sid = session.sid
         self.file_props.transfered_size = []
         self.file_props.transport_sid = self.transport.sid
     log.info("FT request: %s" % file_props)
     if transport is None:
         self.transport = JingleTransportSocks5()
     self.transport.set_connection(session.connection)
     self.transport.set_file_props(self.file_props)
     self.transport.set_our_jid(session.ourjid)
     log.info('ourjid: %s' % session.ourjid)
     self.session = session
     self.media = 'file'
     self.nominated_cand = {}
     if gajim.contacts.is_gc_contact(session.connection.name,
     session.peerjid):
         roomjid = session.peerjid.split('/')[0]
         dstaddr = hashlib.sha1(('%s%s%s' % (self.file_props.sid,
             session.ourjid, roomjid)).encode('utf-8')).hexdigest()
         self.file_props.dstaddr = dstaddr
     self.state = STATE_NOT_STARTED
     self.states = {STATE_INITIALIZED   : StateInitialized(self),
                    STATE_CAND_SENT     : StateCandSent(self),
                    STATE_CAND_RECEIVED : StateCandReceived(self),
                    STATE_TRANSFERING   : StateTransfering(self),
                STATE_TRANSPORT_REPLACE : StateTransportReplace(self),
           STATE_CAND_SENT_AND_RECEIVED : StateCandSentAndRecv(self)
     }
Ejemplo n.º 3
0
 def __init__(self, session, transport=None):
     if not transport:
         transport = JingleTransportSXE()
     JingleContent.__init__(self, session, transport)
     self.media = 'xhtml'
     self.negotiated = True  # there is nothing to negotiate
     self.last_rid = 0
     self.callbacks['session-accept'] += [self._sessionAcceptCB]
     self.callbacks['session-terminate'] += [self._stop]
     self.callbacks['session-terminate-sent'] += [self._stop]
     self.callbacks['edit'] = [self._EditCB]
Ejemplo n.º 4
0
 def __init__(self, session, transport=None):
     if not transport:
         transport = JingleTransportSXE()
     JingleContent.__init__(self, session, transport)
     self.media = 'xhtml'
     self.negotiated = True # there is nothing to negotiate
     self.last_rid = 0
     self.callbacks['session-accept'] += [self._sessionAcceptCB]
     self.callbacks['session-terminate'] += [self._stop]
     self.callbacks['session-terminate-sent'] += [self._stop]
     self.callbacks['edit'] = [self._EditCB]
Ejemplo n.º 5
0
    def on_negotiated(self):
        if self.accepted:
            if self.p2psession.get_property('codecs'):
                # those lines MUST be done after we get info on our codecs
                if self.transport.remote_candidates:
                    self.p2pstream.add_remote_candidates(
                        self.transport.remote_candidates)
                    self.transport.remote_candidates = []
                    # TODO: Farstream.StreamDirection.BOTH only if senders='both'
#                    self.p2pstream.set_property('direction',
#                        Farstream.StreamDirection.BOTH)
        JingleContent.on_negotiated(self)
Ejemplo n.º 6
0
    def on_negotiated(self):
        if self.accepted:
            if self.p2psession.get_property('codecs'):
                # those lines MUST be done after we get info on our codecs
                if self.transport.remote_candidates:
                    self.p2pstream.add_remote_candidates(
                        self.transport.remote_candidates)
                    self.transport.remote_candidates = []
                    # TODO: Farstream.StreamDirection.BOTH only if senders='both'


#                    self.p2pstream.set_property('direction',
#                        Farstream.StreamDirection.BOTH)
        JingleContent.on_negotiated(self)
Ejemplo n.º 7
0
    def __init__(self, session, media, transport=None):
        if transport is None:
            transport = JingleTransportICEUDP(None)
        JingleContent.__init__(self, session, transport)
        self.media = media
        self._dtmf_running = False
        self.farstream_media = {'audio': Farstream.MediaType.AUDIO,
            'video': Farstream.MediaType.VIDEO}[media]

        self.pipeline = None
        self.src_bin = None
        self.stream_failed_once = False

        self.candidates_ready = False # True when local candidates are prepared

        self.callbacks['session-initiate'] += [self.__on_remote_codecs]
        self.callbacks['content-add'] += [self.__on_remote_codecs]
        self.callbacks['description-info'] += [self.__on_remote_codecs]
        self.callbacks['content-accept'] += [self.__on_remote_codecs]
        self.callbacks['session-accept'] += [self.__on_remote_codecs]
        self.callbacks['session-terminate'] += [self.__stop]
        self.callbacks['session-terminate-sent'] += [self.__stop]
Ejemplo n.º 8
0
 def __on_content_add(self, stanza, jingle, error, action):
     if self.state == JingleStates.ended:
         raise OutOfOrder
     parse_result = self.__parse_contents(jingle)
     contents = parse_result[0]
     rejected_contents = parse_result[1]
     for name, creator in rejected_contents:
         # TODO
         content = JingleContent()
         self.add_content(name, content, creator)
         self.__content_reject(content)
         self.contents[(content.creator, content.name)].destroy()
     gajim.nec.push_incoming_event(JingleRequestReceivedEvent(None,
         conn=self.connection, jingle_session=self, contents=contents))
Ejemplo n.º 9
0
 def destroy(self):
     JingleContent.destroy(self)
     self.p2pstream.disconnect_by_func(self._on_src_pad_added)
     self.pipeline.get_bus().disconnect_by_func(self._on_gst_message)
Ejemplo n.º 10
0
 def add_remote_candidates(self, candidates):
     JingleContent.add_remote_candidates(self, candidates)
     # FIXME: connectivity should not be etablished yet
     # Instead, it should be etablished after session-accept!
     if self.sent:
         self.p2pstream.add_remote_candidates(candidates)
Ejemplo n.º 11
0
 def is_ready(self):
     return JingleContent.is_ready(self) and self.candidates_ready
Ejemplo n.º 12
0
 def destroy(self):
     JingleContent.destroy(self)
     self.p2pstream.disconnect_by_func(self._on_src_pad_added)
     self.pipeline.get_bus().disconnect_by_func(self._on_gst_message)
Ejemplo n.º 13
0
 def add_remote_candidates(self, candidates):
     JingleContent.add_remote_candidates(self, candidates)
     # FIXME: connectivity should not be etablished yet
     # Instead, it should be etablished after session-accept!
     if self.sent:
         self.p2pstream.add_remote_candidates(candidates)
Ejemplo n.º 14
0
 def is_ready(self):
     return (JingleContent.is_ready(self) and self.candidates_ready)
Ejemplo n.º 15
0
    def __init__(self,
                 session,
                 transport=None,
                 file_props=None,
                 use_security=False):
        JingleContent.__init__(self, session, transport)
        log.info("transport value: %s", transport)
        # events we might be interested in
        self.callbacks['session-initiate'] += [self.__on_session_initiate]
        self.callbacks['session-initiate-sent'] += [
            self.__on_session_initiate_sent
        ]
        self.callbacks['content-add'] += [self.__on_session_initiate]
        self.callbacks['session-accept'] += [self.__on_session_accept]
        self.callbacks['session-terminate'] += [self.__on_session_terminate]
        self.callbacks['session-info'] += [self.__on_session_info]
        self.callbacks['transport-accept'] += [self.__on_transport_accept]
        self.callbacks['transport-replace'] += [self.__on_transport_replace]
        self.callbacks['session-accept-sent'] += [self.__transport_setup]
        # fallback transport method
        self.callbacks['transport-reject'] += [self.__on_transport_reject]
        self.callbacks['transport-info'] += [self.__on_transport_info]
        self.callbacks['iq-result'] += [self.__on_iq_result]
        self.use_security = use_security
        self.x509_fingerprint = None
        self.file_props = file_props
        self.weinitiate = self.session.weinitiate
        self.werequest = self.session.werequest
        if self.file_props is not None:
            if self.session.werequest:
                self.file_props.sender = self.session.peerjid
                self.file_props.receiver = self.session.ourjid
            else:
                self.file_props.sender = self.session.ourjid
                self.file_props.receiver = self.session.peerjid
            self.file_props.session_type = 'jingle'
            self.file_props.sid = session.sid
            self.file_props.transfered_size = []
            self.file_props.transport_sid = self.transport.sid
        log.info("FT request: %s", file_props)
        if transport is None:
            self.transport = JingleTransportSocks5()
        self.transport.set_connection(session.connection)
        self.transport.set_file_props(self.file_props)
        self.transport.set_our_jid(session.ourjid)
        log.info('ourjid: %s', session.ourjid)
        self.session = session
        self.media = 'file'
        self.nominated_cand = {}
        if gajim.contacts.is_gc_contact(session.connection.name,
                                        session.peerjid):
            roomjid = session.peerjid.split('/')[0]
            dstaddr = hashlib.sha1(
                ('%s%s%s' % (self.file_props.sid, session.ourjid,
                             roomjid)).encode('utf-8')).hexdigest()
            self.file_props.dstaddr = dstaddr
        self.state = State.NOT_STARTED
        self.states = {
            State.INITIALIZED: StateInitialized(self),
            State.CAND_SENT: StateCandSent(self),
            State.CAND_RECEIVED: StateCandReceived(self),
            State.TRANSFERING: StateTransfering(self),
            State.TRANSPORT_REPLACE: StateTransportReplace(self),
            State.CAND_SENT_AND_RECEIVED: StateCandSentAndRecv(self)
        }

        if jingle_xtls.PYOPENSSL_PRESENT:
            cert_name = os.path.join(configpaths.gajimpaths['MY_CERT'],
                                     jingle_xtls.SELF_SIGNED_CERTIFICATE)
            if not (os.path.exists(cert_name + '.cert')
                    and os.path.exists(cert_name + '.pkey')):
                jingle_xtls.make_certs(cert_name, 'gajim')