Rewritten contentAddCB in order to ask the user about new contents
This commit is contained in:
parent
011f4fe142
commit
193f2613a9
|
@ -384,22 +384,20 @@ class JingleSession(object):
|
||||||
#TODO: Needs to be rewritten
|
#TODO: Needs to be rewritten
|
||||||
if self.state == JingleStates.ended:
|
if self.state == JingleStates.ended:
|
||||||
raise OutOfOrder
|
raise OutOfOrder
|
||||||
for element in jingle.iterTags('content'):
|
|
||||||
# checking what kind of session this will be
|
parse_result = self.__parse_contents(jingle)
|
||||||
desc_ns = element.getTag('description').getNamespace()
|
contents = parse_result[2]
|
||||||
media = element.getTag('description')['media']
|
rejected_contents = parse_result[3]
|
||||||
tran_ns = element.getTag('transport').getNamespace()
|
|
||||||
if desc_ns == xmpp.NS_JINGLE_RTP and media in ('audio', 'video') \
|
for name, creator in rejected_contents:
|
||||||
and tran_ns == xmpp.NS_JINGLE_ICE_UDP:
|
#TODO:
|
||||||
if media == 'audio':
|
content = JingleContent()
|
||||||
self.add_content(element['name'], JingleVoIP(self), 'peer')
|
self.add_content(name, content, creator)
|
||||||
else:
|
self.__content_reject(content)
|
||||||
self.add_content(element['name'], JingleVideo(self), 'peer')
|
self.contents[(content.creator, content.name)].destroy()
|
||||||
else:
|
|
||||||
content = JingleContent()
|
self.connection.dispatch('JINGLE_INCOMING', (self.initiator, self.sid,
|
||||||
self.add_content(element['name'], content, 'peer')
|
contents))
|
||||||
self.__content_reject(content)
|
|
||||||
self.contents[(content.creator, content.name)].destroy()
|
|
||||||
|
|
||||||
def __sessionInitiateCB(self, stanza, jingle, error, action):
|
def __sessionInitiateCB(self, stanza, jingle, error, action):
|
||||||
''' We got a jingle session request from other entity,
|
''' We got a jingle session request from other entity,
|
||||||
|
@ -419,24 +417,7 @@ class JingleSession(object):
|
||||||
# error.
|
# error.
|
||||||
|
|
||||||
# Lets check what kind of jingle session does the peer want
|
# Lets check what kind of jingle session does the peer want
|
||||||
contents = []
|
contents_ok, transports_ok, contents, pouet = self.__parse_contents(jingle)
|
||||||
contents_ok = False
|
|
||||||
transports_ok = False
|
|
||||||
for element in jingle.iterTags('content'):
|
|
||||||
# checking what kind of session this will be
|
|
||||||
desc_ns = element.getTag('description').getNamespace()
|
|
||||||
media = element.getTag('description')['media']
|
|
||||||
tran_ns = element.getTag('transport').getNamespace()
|
|
||||||
if desc_ns == xmpp.NS_JINGLE_RTP and media in ('audio', 'video'):
|
|
||||||
contents_ok = True
|
|
||||||
if tran_ns == xmpp.NS_JINGLE_ICE_UDP:
|
|
||||||
# we've got voip content
|
|
||||||
if media == 'audio':
|
|
||||||
self.add_content(element['name'], JingleVoIP(self), 'peer')
|
|
||||||
else:
|
|
||||||
self.add_content(element['name'], JingleVideo(self), 'peer')
|
|
||||||
contents.append((media,))
|
|
||||||
transports_ok = True
|
|
||||||
|
|
||||||
# If there's no content we understand...
|
# If there's no content we understand...
|
||||||
if not contents_ok:
|
if not contents_ok:
|
||||||
|
@ -485,15 +466,34 @@ class JingleSession(object):
|
||||||
for content in self.contents.itervalues():
|
for content in self.contents.itervalues():
|
||||||
content.stanzaCB(stanza, None, error, action)
|
content.stanzaCB(stanza, None, error, action)
|
||||||
|
|
||||||
def __send_error(self, stanza, error, jingle_error=None, text=None):
|
''' Internal methods. '''
|
||||||
err = xmpp.Error(stanza, error)
|
def __parse_contents(self, jingle):
|
||||||
err.setNamespace(xmpp.NS_STANZAS)
|
#TODO: WIP
|
||||||
if jingle_error:
|
contents = []
|
||||||
err.setTag(jingle_error, namespace=xmpp.NS_JINGLE_ERRORS)
|
contents_rejected = []
|
||||||
if text:
|
contents_ok = False
|
||||||
err.setTagData('text', text)
|
transports_ok = False
|
||||||
self.connection.connection.send(err)
|
|
||||||
self.__dispatch_error(error, jingle_error, text)
|
for element in jingle.iterTags('content'):
|
||||||
|
desc = element.getTag('description')
|
||||||
|
desc_ns = desc.getNamespace()
|
||||||
|
tran_ns = element.getTag('transport').getNamespace()
|
||||||
|
if desc_ns == xmpp.NS_JINGLE_RTP and desc['media'] in ('audio', 'video'):
|
||||||
|
contents_ok = True
|
||||||
|
#TODO: Everything here should be moved somewhere else
|
||||||
|
if tran_ns == xmpp.NS_JINGLE_ICE_UDP:
|
||||||
|
if desc['media'] == 'audio':
|
||||||
|
self.add_content(element['name'], JingleVoIP(self), 'peer')
|
||||||
|
else:
|
||||||
|
self.add_content(element['name'], JingleVideo(self), 'peer')
|
||||||
|
contents.append((desc['media'],))
|
||||||
|
transports_ok = True
|
||||||
|
else:
|
||||||
|
contents_rejected.append((element['name'], 'peer'))
|
||||||
|
else:
|
||||||
|
contents_rejected.append((element['name'], 'peer'))
|
||||||
|
|
||||||
|
return (contents_ok, transports_ok, contents, contents_rejected)
|
||||||
|
|
||||||
def __dispatch_error(self, error, jingle_error=None, text=None):
|
def __dispatch_error(self, error, jingle_error=None, text=None):
|
||||||
if jingle_error:
|
if jingle_error:
|
||||||
|
@ -533,6 +533,16 @@ class JingleSession(object):
|
||||||
jingle = stanza.addChild('jingle', attrs=attrs, namespace=xmpp.NS_JINGLE)
|
jingle = stanza.addChild('jingle', attrs=attrs, namespace=xmpp.NS_JINGLE)
|
||||||
return stanza, jingle
|
return stanza, jingle
|
||||||
|
|
||||||
|
def __send_error(self, stanza, error, jingle_error=None, text=None):
|
||||||
|
err = xmpp.Error(stanza, error)
|
||||||
|
err.setNamespace(xmpp.NS_STANZAS)
|
||||||
|
if jingle_error:
|
||||||
|
err.setTag(jingle_error, namespace=xmpp.NS_JINGLE_ERRORS)
|
||||||
|
if text:
|
||||||
|
err.setTagData('text', text)
|
||||||
|
self.connection.connection.send(err)
|
||||||
|
self.__dispatch_error(error, jingle_error, text)
|
||||||
|
|
||||||
def __append_content(self, jingle, content):
|
def __append_content(self, jingle, content):
|
||||||
''' Append <content/> element to <jingle/> element,
|
''' Append <content/> element to <jingle/> element,
|
||||||
with (full=True) or without (full=False) <content/>
|
with (full=True) or without (full=False) <content/>
|
||||||
|
|
Loading…
Reference in New Issue