Dateien nach „slixmpp/plugins/xep_0294“ hochladen
This commit is contained in:
parent
0461024bbe
commit
3e0890bdbf
11
slixmpp/plugins/xep_0294/__init__.py
Normal file
11
slixmpp/plugins/xep_0294/__init__.py
Normal file
@ -0,0 +1,11 @@
|
||||
# slixmpp: The Slick XMPP Library
|
||||
# Copyright (C) 2020 Emmanuel Gil Peyrot
|
||||
# This file is part of slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
|
||||
from slixmpp.plugins.base import register_plugin
|
||||
|
||||
from slixmpp.plugins.xep_0294.stanza import HdrExt, Parameter, ExtMapAllowMixed
|
||||
from slixmpp.plugins.xep_0294.hdrext import XEP_0294
|
||||
|
||||
register_plugin(XEP_0294)
|
66
slixmpp/plugins/xep_0294/hdrext.py
Normal file
66
slixmpp/plugins/xep_0294/hdrext.py
Normal file
@ -0,0 +1,66 @@
|
||||
# Copyright (C) 2020 Emmanuel Gil Peyrot
|
||||
# This file is part of slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
|
||||
import logging
|
||||
|
||||
from typing import Iterable, Tuple, Optional
|
||||
|
||||
from slixmpp import JID, Iq
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from slixmpp.xmlstream.handler import Callback
|
||||
from slixmpp.xmlstream.matcher import StanzaPath
|
||||
from slixmpp.plugins.xep_0166 import Jingle, Content
|
||||
from slixmpp.plugins.xep_0167 import Description
|
||||
from slixmpp.plugins.xep_0294 import stanza, HdrExt, Parameter, ExtMapAllowMixed
|
||||
|
||||
import re
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class XEP_0294(BasePlugin):
|
||||
|
||||
name = 'xep_0294'
|
||||
description = 'XEP-0294: Jingle RTP Header Extensions Negotiation'
|
||||
dependencies = set(['xep_0166','xep_0167'])
|
||||
stanza = stanza
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(Iq,Jingle)
|
||||
register_stanza_plugin(Jingle,Content,True)
|
||||
register_stanza_plugin(Content,Description)
|
||||
register_stanza_plugin(Description,ExtMapAllowMixed)
|
||||
register_stanza_plugin(Description,HdrExt,True)
|
||||
register_stanza_plugin(HdrExt,Parameter,True)
|
||||
|
||||
def make_extmapallowmixed(self, sdp):
|
||||
m = re.finditer('^a=extmap-allow-mixed\r$',sdp,re.M)
|
||||
if m:
|
||||
return ExtMapAllowMixed()
|
||||
return None
|
||||
|
||||
def make_hdrexts(self, sdp):
|
||||
general = 'both'
|
||||
m = re.search('a=(sendrecv|send|recv)$',sdp,re.M)
|
||||
if m:
|
||||
if m.group(1) == 'send':
|
||||
general = 'responder'
|
||||
elif m.group(1) == 'recv':
|
||||
general = 'initiator'
|
||||
iter = re.finditer('a=extmap:([^ /]+)(/[^ ]+)? +([^\r\n]+)\r$',sdp,re.M)
|
||||
if iter:
|
||||
hdrexts = []
|
||||
for m in iter:
|
||||
switcher = {'/recvonly':'initiator', '/sendonly':'responder'}
|
||||
hdrext = HdrExt()
|
||||
hdrext['id'] = m.group(1)
|
||||
if m.group(2):
|
||||
hdrext['senders'] = switcher.get(m.group(2),general)
|
||||
elif general!='both':
|
||||
hdrext['senders'] = general
|
||||
hdrext['uri'] = m.group(3)
|
||||
hdrexts.append(hdrext)
|
||||
return hdrexts
|
||||
return None
|
46
slixmpp/plugins/xep_0294/stanza.py
Normal file
46
slixmpp/plugins/xep_0294/stanza.py
Normal file
@ -0,0 +1,46 @@
|
||||
# slixmpp: The Slick XMPP Library
|
||||
# Copyright (C) 2020 Emmanuel Gil Peyrot
|
||||
# This file is part of slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
|
||||
from typing import Iterable, List, Tuple, Optional
|
||||
from slixmpp.xmlstream import ElementBase, ET
|
||||
|
||||
class HdrExt(ElementBase):
|
||||
name = 'rtp-hdrext'
|
||||
namespace = 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
|
||||
plugin_attrib = 'hdrext'
|
||||
interfaces = {'id','uri','senders'}
|
||||
plugin_multi_attrib = 'hdrexts'
|
||||
|
||||
def getSDP(self):
|
||||
switcher = {'initiator':'/recvonly', 'responder':'/sendonly'}
|
||||
ret = "\r\na=extmap:%s%s %s" % (self['id'],switcher.get(self['senders'],''),self['uri'])
|
||||
if self.get_plugin(name='parameters',check=True):
|
||||
tmp = ''
|
||||
for parameter in self['parameters']:
|
||||
tmp += ','+parameter.getSDP()
|
||||
ret += ' '+tmp[1:]
|
||||
return ret
|
||||
|
||||
class Parameter(ElementBase):
|
||||
name = 'parameter'
|
||||
namespace = 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
|
||||
plugin_attrib = 'parameter'
|
||||
interfaces = {'name','value'}
|
||||
plugin_multi_attrib = 'parameters'
|
||||
|
||||
def getSDP(self):
|
||||
parameter = self['name']
|
||||
if self['value']:
|
||||
parameter += ":"+self['value']
|
||||
return parameter
|
||||
|
||||
class ExtMapAllowMixed(ElementBase):
|
||||
name = 'extmap-allow-mixed'
|
||||
namespace = 'urn:xmpp:jingle:apps:rtp:rtp-hdrext:0'
|
||||
plugin_attrib = 'extmap-allow-mixed'
|
||||
interfaces = {}
|
||||
|
||||
def getSDP(self):
|
||||
return '\r\na=extmap-allow-mixed'
|
Loading…
x
Reference in New Issue
Block a user