coding standards
This commit is contained in:
parent
af44ee0840
commit
11c7de6c34
1 changed files with 94 additions and 79 deletions
|
@ -90,7 +90,8 @@ class JingleSession(object):
|
|||
self.contents = {} # negotiated contents
|
||||
self.connection = con # connection to use
|
||||
# our full jid
|
||||
self.ourjid=gajim.get_jid_from_account(self.connection.name)+'/'+con.server_resource
|
||||
self.ourjid = gajim.get_jid_from_account(self.connection.name) + '/' + \
|
||||
con.server_resource
|
||||
self.peerjid = jid # jid we connect to
|
||||
# jid we use as the initiator
|
||||
self.initiator = weinitiate and self.ourjid or self.peerjid
|
||||
|
@ -118,10 +119,13 @@ class JingleSession(object):
|
|||
'content-remove': [self.__defaultCB, self.__contentRemoveCB],
|
||||
'description-info': [self.__defaultCB], #TODO
|
||||
'security-info': [self.__defaultCB], #TODO
|
||||
'session-accept': [self.__sessionAcceptCB, self.__contentAcceptCB, self.__broadcastCB, self.__defaultCB],
|
||||
'session-accept': [self.__sessionAcceptCB, self.__contentAcceptCB,
|
||||
self.__broadcastCB, self.__defaultCB],
|
||||
'session-info': [self.__sessionInfoCB, self.__broadcastCB],
|
||||
'session-initiate': [self.__sessionInitiateCB, self.__broadcastCB, self.__defaultCB],
|
||||
'session-terminate': [self.__sessionTerminateCB, self.__broadcastAllCB, self.__defaultCB],
|
||||
'session-initiate': [self.__sessionInitiateCB, self.__broadcastCB,
|
||||
self.__defaultCB],
|
||||
'session-terminate': [self.__sessionTerminateCB, self.__broadcastAllCB,
|
||||
self.__defaultCB],
|
||||
'transport-info': [self.__broadcastCB, self.__defaultCB],
|
||||
'transport-replace': [self.__broadcastCB, self.__transportReplaceCB], #TODO
|
||||
'transport-accept': [self.__defaultCB], #TODO
|
||||
|
@ -132,12 +136,14 @@ class JingleSession(object):
|
|||
|
||||
''' Interaction with user '''
|
||||
def approveSession(self):
|
||||
''' Called when user accepts session in UI (when we aren't the initiator).'''
|
||||
''' Called when user accepts session in UI (when we aren't the initiator).
|
||||
'''
|
||||
self.accepted = True
|
||||
self.acceptSession()
|
||||
|
||||
def declineSession(self):
|
||||
''' Called when user declines session in UI (when we aren't the initiator)'''
|
||||
''' Called when user declines session in UI (when we aren't the initiator)
|
||||
'''
|
||||
reason = xmpp.Node('reason')
|
||||
reason.addChild('decline')
|
||||
self.__sessionTerminate(reason)
|
||||
|
@ -154,9 +160,11 @@ class JingleSession(object):
|
|||
if self.state == JingleStates.pending:
|
||||
raise WrongState
|
||||
|
||||
if (creator=='we' and self.weinitiate) or (creator=='peer' and not self.weinitiate):
|
||||
if (creator == 'we' and self.weinitiate) or (creator == 'peer' and \
|
||||
not self.weinitiate):
|
||||
creator = 'initiator'
|
||||
elif (creator=='peer' and self.weinitiate) or (creator=='we' and not self.weinitiate):
|
||||
elif (creator == 'peer' and self.weinitiate) or (creator == 'we' and \
|
||||
not self.weinitiate):
|
||||
creator = 'responder'
|
||||
content.creator = creator
|
||||
content.name = name
|
||||
|
@ -357,7 +365,8 @@ class JingleSession(object):
|
|||
self.state = JingleStates.pending
|
||||
|
||||
# Send event about starting a session
|
||||
self.connection.dispatch('JINGLE_INCOMING', (self.initiator, self.sid, contents))
|
||||
self.connection.dispatch('JINGLE_INCOMING', (self.initiator, self.sid,
|
||||
contents))
|
||||
|
||||
def __broadcastCB(self, stanza, jingle, error, action):
|
||||
''' Broadcast the stanza contents to proper content handlers. '''
|
||||
|
@ -578,7 +587,8 @@ class JingleContent(object):
|
|||
''' Add our things to session-initiate stanza. '''
|
||||
self._fillContent(content)
|
||||
|
||||
if self.candidates and self.candidates[0].username and self.candidates[0].password:
|
||||
if self.candidates and self.candidates[0].username and \
|
||||
self.candidates[0].password:
|
||||
attrs = {'ufrag': self.candidates[0].username,
|
||||
'pwd': self.candidates[0].password}
|
||||
else:
|
||||
|
@ -586,7 +596,6 @@ class JingleContent(object):
|
|||
content.addChild(xmpp.NS_JINGLE_ICE_UDP + ' transport', attrs=attrs,
|
||||
payload=self.iterCandidates())
|
||||
|
||||
|
||||
class JingleRTPContent(JingleContent):
|
||||
def __init__(self, session, media, node=None):
|
||||
JingleContent.__init__(self, session, node)
|
||||
|
@ -613,8 +622,8 @@ class JingleRTPContent(JingleContent):
|
|||
self.funnel = None
|
||||
|
||||
def _fillContent(self, content):
|
||||
content.addChild(xmpp.NS_JINGLE_RTP+' description', attrs={'media': self.media},
|
||||
payload=self.iterCodecs())
|
||||
content.addChild(xmpp.NS_JINGLE_RTP + ' description',
|
||||
attrs={'media': self.media}, payload=self.iterCodecs())
|
||||
|
||||
def _on_gst_message(self, bus, message):
|
||||
if message.type == gst.MESSAGE_ELEMENT:
|
||||
|
@ -631,7 +640,8 @@ class JingleRTPContent(JingleContent):
|
|||
elif name == 'farsight-new-local-candidate':
|
||||
candidate = message.structure['candidate']
|
||||
self.candidates.append(candidate)
|
||||
if self.session.candidates_ready: #FIXME: Is this case even possible?
|
||||
if self.session.candidates_ready:
|
||||
#FIXME: Is this case even possible?
|
||||
self.send_candidate(candidate)
|
||||
elif name == 'farsight-component-state-changed':
|
||||
state = message.structure['state']
|
||||
|
@ -641,7 +651,8 @@ class JingleRTPContent(JingleContent):
|
|||
#TODO: farsight.DIRECTION_BOTH only if senders='both'
|
||||
self.p2pstream.set_property('direction', farsight.DIRECTION_BOTH)
|
||||
#if not self.session.weinitiate: #FIXME: one more FIXME...
|
||||
# self.session.sendContentAccept(self.__content((xmpp.Node('description', payload=self.iterCodecs()),)))
|
||||
# self.session.sendContentAccept(self.__content((xmpp.Node(
|
||||
# 'description', payload=self.iterCodecs()),)))
|
||||
elif name == 'farsight-error':
|
||||
print 'Farsight error #%d!' % message.structure['error-no']
|
||||
print 'Message: %s' % message.structure['error-msg']
|
||||
|
@ -661,12 +672,14 @@ class JingleRTPContent(JingleContent):
|
|||
c.channels = int(codec['channels'])
|
||||
else:
|
||||
c.channels = 1
|
||||
c.optional_params = [(str(p['name']), str(p['value'])) for p in codec.iterTags('parameter')]
|
||||
c.optional_params = [(str(p['name']), str(p['value'])) for p in \
|
||||
codec.iterTags('parameter')]
|
||||
codecs.append(c)
|
||||
if len(codecs) == 0: return
|
||||
|
||||
#FIXME: Handle this case:
|
||||
# glib.GError: There was no intersection between the remote codecs and the local ones
|
||||
# glib.GError: There was no intersection between the remote codecs and
|
||||
# the local ones
|
||||
self.p2pstream.set_remote_codecs(codecs)
|
||||
self.got_codecs = True
|
||||
|
||||
|
@ -721,8 +734,8 @@ class JingleVoIP(JingleRTPContent):
|
|||
farsight.MEDIA_TYPE_AUDIO, 16000)]
|
||||
self.p2psession.set_codec_preferences(codecs)
|
||||
|
||||
self.p2pstream = self.p2psession.new_stream(participant, farsight.DIRECTION_NONE,
|
||||
'nice', params)
|
||||
self.p2pstream = self.p2psession.new_stream(participant,
|
||||
farsight.DIRECTION_NONE, 'nice', params)
|
||||
|
||||
# the local parts
|
||||
# TODO: use gconfaudiosink?
|
||||
|
@ -754,7 +767,8 @@ class JingleVoIP(JingleRTPContent):
|
|||
self.funnel.link(sink)
|
||||
pad.link(self.funnel.get_pad('sink%d'))
|
||||
|
||||
self.mic_volume.get_pad('src').link(self.p2psession.get_property('sink-pad'))
|
||||
self.mic_volume.get_pad('src').link(self.p2psession.get_property(
|
||||
'sink-pad'))
|
||||
self.p2pstream.connect('src-pad-added', src_pad_added)
|
||||
|
||||
# The following is needed for farsight to process ICE requests:
|
||||
|
@ -819,6 +833,7 @@ class ConnectionJingle(object):
|
|||
self.addJingle(jingle)
|
||||
jingle.addContent('voice', JingleVoIP(jingle))
|
||||
jingle.startSession()
|
||||
|
||||
def getJingleSession(self, jid, sid):
|
||||
try:
|
||||
return self.__sessions[(jid, sid)]
|
||||
|
|
Loading…
Add table
Reference in a new issue