一个典型的Jingle XMPP stanza:
<iq from='romeo@montague.lit/orchard'
id='xs51r0k4'
to='juliet@capulet.lit/balcony'
type='set'>
<jingle xmlns='urn:xmpp:jingle:1'
action='session-initiate'
initiator='romeo@montague.lit/orchard'
sid='a73sjjvkla37jfea'>
<content creator='initiator' name='voice'>
<description xmlns='urn:xmpp:jingle:apps:rtp:1' media='audio'>
<payload-type id='96' name='speex' clockrate='16000'/>
<payload-type id='97' name='speex' clockrate='8000'/>
<payload-type id='18' name='G729'/>
<payload-type id='0' name='PCMU' />
<payload-type id='103' name='L16' clockrate='16000' channels='2'/>
<payload-type id='98' name='x-ISAC' clockrate='8000'/>
</description>
<transport xmlns='urn:xmpp:jingle:transports:ice-udp:1'
pwd='asd88fgpdd777uzjYhagZg'
ufrag='8hhy'>
<candidate component='1'
foundation='1'
generation='0'
id='el0747fg11'
ip='10.0.1.1'
network='1'
port='8998'
priority='2130706431'
protocol='udp'
type='host'/>
<candidate component='1'
foundation='2'
generation='0'
id='y3s2b30v3r'
ip='192.0.2.3'
network='1'
port='45664'
priority='1694498815'
protocol='udp'
rel-addr='10.0.1.1'
rel-port='8998'
type='srflx'/>
</transport>
</content>
</jingle>
</iq>
从XEP-0166的XML Schema可以看出, <jingle>元素下的<content>元素minOccurs为0, maxOccurs为无限. 而<content>元素下的子元素未定义, 需要到别的XEP去看, minOccurs为0, maxOccurs为无限.
从XEP-0167的XML Schema可以看出, <description>元素下的<payload-type>元素minOccurs为0, maxOccurs为无限.
从XEP-0176的XML Schema可以看出, <transport>元素下的<candidate>元素minOccurs为1, maxOccurs为无限.
结合起来, 意味着<jingle>元素作为<iq>元素的子元素, 其下面可以包含任意多个<content>子元素, 而<content>子元素下面可以包含任意的<description>元素和<transport>元素.
所以, Libjingle在实现Jingle协议的时候, 设计了对应的数据结构来实现各种可能的情况, 导致代码看起来很晦涩, 其实对照Jingle的XML Schema来看, 就很容易理解了.
本文解析了JingleXMPPStanza的典型结构,包括<iq>元素下的<jingle>子元素及其子元素<content>、<description>、<payload-type>和<transport>的使用方式,并讨论了Libjingle实现时的设计考虑。
306

被折叠的 条评论
为什么被折叠?



