Browse Source

add support for the <http://mumble.sourceforge.net/Channel_Viewer_Protocol> draft

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
f624f84022
  1. 33
      pyweb/mumble/mmobjects.py
  2. 12
      pyweb/mumble/models.py
  3. 3
      pyweb/mumble/urls.py
  4. 30
      pyweb/mumble/views.py

33
pyweb/mumble/mmobjects.py

@ -154,10 +154,24 @@ class mmChannel( object ):
def asDict( self ):
chandata = self.channel_obj.__dict__.copy()
chandata['players'] = [ pl.asDict() for pl in self.players ]
chandata['subchans'] = [ sc.asDict() for sc in self.subchans ]
chandata['users'] = [ pl.asDict() for pl in self.players ]
chandata['channels'] = [ sc.asDict() for sc in self.subchans ]
chandata['x-connecturl'] = self.connecturl
return chandata
def asXml( self, parentnode ):
from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "channel" )
for key in self.channel_obj.__dict__:
me.set( key, unicode( getattr( self.channel_obj, key ) ) )
me.set( "x-connecturl", self.connecturl )
for sc in self.subchans:
sc.asXml(me)
for pl in self.players:
pl.asXml(me)
def asMvXml( self, parentnode ):
""" Return an XML tree for this channel suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import SubElement
@ -264,13 +278,26 @@ class mmPlayer( object ):
def asDict( self ):
pldata = self.player_obj.__dict__.copy()
pldata["x-addrstring"] = self.ipaddress
if self.mumbleuser:
if self.mumbleuser.hasTexture():
pldata['texture'] = self.mumbleuser.textureUrl
pldata['x-texture'] = self.mumbleuser.textureUrl
return pldata
def asXml( self, parentnode ):
from xml.etree.cElementTree import SubElement
me = SubElement( parentnode, "user" )
for key in self.player_obj.__dict__:
me.set( key, unicode( getattr( self.player_obj, key ) ) )
me.set("x-addrstring", self.ipaddress )
if self.mumbleuser:
if self.mumbleuser.hasTexture():
me.set( 'x-texture', self.mumbleuser.textureUrl )
def asMvXml( self, parentnode ):
""" Return an XML node for this player suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import SubElement

12
pyweb/mumble/models.py

@ -36,7 +36,7 @@ def get_ipv46_host_by_name( hostname ):
if applicable. Returns: { AF_INET: inet4address, AF_INET6: inet6address }.
For addresses that don't exist, the corresponding field will be None.
"""
addrinfo = socket.getaddrinfo( hostname, settings.MUMBLE_DEFAULT_PORT )
addrinfo = socket.getaddrinfo( hostname, settings.MUMBLE_DEFAULT_PORT, 0, socket.SOCK_DGRAM )
ret = {}
for (family, socktype, proto, canonname, sockaddr) in addrinfo:
if family not in ret:
@ -551,9 +551,17 @@ class Mumble( models.Model ):
def asDict( self ):
return { 'name': self.name,
'id': self.id,
'root': self.rootchan.asDict()
'root': self.rootchan.asDict(),
'x-connecturl': self.connecturl
}
def asXml( self ):
from xml.etree.cElementTree import Element
root = Element( "server", id=unicode(self.id), name=self.name )
root.set( 'x-connecturl', self.connecturl )
self.rootchan.asXml(root)
return root
def asMvXml( self ):
""" Return an XML tree for this server suitable for MumbleViewer-ng. """
from xml.etree.cElementTree import Element

3
pyweb/mumble/urls.py

@ -31,6 +31,9 @@ urlpatterns = patterns(
( r'mobile/(?P<server>\d+)', 'mobile_show' ),
( r'mobile/?$', 'mobile_mumbles' ),
( r'(?P<server>\d+).json', 'cvp_json' ),
( r'(?P<server>\d+).xml', 'cvp_xml' ),
( r'(?P<server>\d+)', 'show' ),
( r'$', 'mumbles' ),
)

30
pyweb/mumble/views.py

@ -378,6 +378,36 @@ def mmng_tree( request, server ):
)
def cvp_json( request, server ):
""" JSON reference implementation for the Channel Viewer Protocol.
See <http://mumble.sourceforge.net/Channel_Viewer_Protocol>
"""
srv = get_object_or_404( Mumble, id=int(server) )
if "jsonp_callback" in request.GET:
prefix = request.GET["jsonp_callback"]
else:
prefix = ""
return HttpResponse(
prefix + "(" + simplejson.dumps( srv.asDict() ) + ")",
mimetype='text/javascript'
)
def cvp_xml( request, server ):
""" XML reference implementation for the Channel Viewer Protocol.
See <http://mumble.sourceforge.net/Channel_Viewer_Protocol>
"""
from xml.etree.cElementTree import tostring as xml_to_string
srv = get_object_or_404( Mumble, id=int(server) )
return HttpResponse(
xml_to_string( srv.asXml(), encoding='utf-8' ),
mimetype='text/xml'
)
def mumbleviewer_tree_xml( request, server ):
""" Get the XML tree from the server and serialize it to the client. """
from xml.etree.cElementTree import tostring as xml_to_string

Loading…
Cancel
Save