From bdc21e72820e148941bbecb36200d51ca340748d Mon Sep 17 00:00:00 2001
From: David Baker
Date: Tue, 2 Dec 2014 14:10:24 +0000
Subject: convert to spaces before I start a holy war
---
contrib/jitsimeetbridge/jitsimeetbridge.py | 410 ++++++++++++++---------------
1 file changed, 205 insertions(+), 205 deletions(-)
(limited to 'contrib')
diff --git a/contrib/jitsimeetbridge/jitsimeetbridge.py b/contrib/jitsimeetbridge/jitsimeetbridge.py
index dbc6f6ffa5..15f8e1c48b 100644
--- a/contrib/jitsimeetbridge/jitsimeetbridge.py
+++ b/contrib/jitsimeetbridge/jitsimeetbridge.py
@@ -39,43 +39,43 @@ ROOMDOMAIN="meet.jit.si"
#ROOMDOMAIN="conference.jitsi.vuc.me"
class TrivialMatrixClient:
- def __init__(self, access_token):
- self.token = None
- self.access_token = access_token
-
- def getEvent(self):
- while True:
- url = MATRIXBASE+'events?access_token='+self.access_token+"&timeout=60000"
- if self.token:
- url += "&from="+self.token
- req = grequests.get(url)
- resps = grequests.map([req])
- obj = json.loads(resps[0].content)
- print "incoming from matrix",obj
- if 'end' not in obj:
- continue
- self.token = obj['end']
- if len(obj['chunk']):
- return obj['chunk'][0]
-
- def joinRoom(self, roomId):
- url = MATRIXBASE+'rooms/'+roomId+'/join?access_token='+self.access_token
- print url
- headers={ 'Content-Type': 'application/json' }
- req = grequests.post(url, headers=headers, data='{}')
- resps = grequests.map([req])
- obj = json.loads(resps[0].content)
- print "response: ",obj
-
- def sendEvent(self, roomId, evType, event):
- url = MATRIXBASE+'rooms/'+roomId+'/send/'+evType+'?access_token='+self.access_token
- print url
- print json.dumps(event)
- headers={ 'Content-Type': 'application/json' }
- req = grequests.post(url, headers=headers, data=json.dumps(event))
- resps = grequests.map([req])
- obj = json.loads(resps[0].content)
- print "response: ",obj
+ def __init__(self, access_token):
+ self.token = None
+ self.access_token = access_token
+
+ def getEvent(self):
+ while True:
+ url = MATRIXBASE+'events?access_token='+self.access_token+"&timeout=60000"
+ if self.token:
+ url += "&from="+self.token
+ req = grequests.get(url)
+ resps = grequests.map([req])
+ obj = json.loads(resps[0].content)
+ print "incoming from matrix",obj
+ if 'end' not in obj:
+ continue
+ self.token = obj['end']
+ if len(obj['chunk']):
+ return obj['chunk'][0]
+
+ def joinRoom(self, roomId):
+ url = MATRIXBASE+'rooms/'+roomId+'/join?access_token='+self.access_token
+ print url
+ headers={ 'Content-Type': 'application/json' }
+ req = grequests.post(url, headers=headers, data='{}')
+ resps = grequests.map([req])
+ obj = json.loads(resps[0].content)
+ print "response: ",obj
+
+ def sendEvent(self, roomId, evType, event):
+ url = MATRIXBASE+'rooms/'+roomId+'/send/'+evType+'?access_token='+self.access_token
+ print url
+ print json.dumps(event)
+ headers={ 'Content-Type': 'application/json' }
+ req = grequests.post(url, headers=headers, data=json.dumps(event))
+ resps = grequests.map([req])
+ obj = json.loads(resps[0].content)
+ print "response: ",obj
@@ -83,178 +83,178 @@ xmppClients = {}
def matrixLoop():
- while True:
- ev = matrixCli.getEvent()
- print ev
- if ev['type'] == 'm.room.member':
- print 'membership event'
- if ev['membership'] == 'invite' and ev['state_key'] == MYUSERNAME:
- roomId = ev['room_id']
- print "joining room %s" % (roomId)
- matrixCli.joinRoom(roomId)
- elif ev['type'] == 'm.room.message':
- if ev['room_id'] in xmppClients:
- print "already have a bridge for that user, ignoring"
- continue
- print "got message, connecting"
- xmppClients[ev['room_id']] = TrivialXmppClient(ev['room_id'], ev['user_id'])
- gevent.spawn(xmppClients[ev['room_id']].xmppLoop)
- elif ev['type'] == 'm.call.invite':
- print "Incoming call"
- #sdp = ev['content']['offer']['sdp']
- #print "sdp: %s" % (sdp)
- #xmppClients[ev['room_id']] = TrivialXmppClient(ev['room_id'], ev['user_id'])
- #gevent.spawn(xmppClients[ev['room_id']].xmppLoop)
- elif ev['type'] == 'm.call.answer':
- print "Call answered"
- sdp = ev['content']['answer']['sdp']
- if ev['room_id'] not in xmppClients:
- print "We didn't have a call for that room"
- continue
- # should probably check call ID too
- xmppCli = xmppClients[ev['room_id']]
- xmppCli.sendAnswer(sdp)
- elif ev['type'] == 'm.call.hangup':
- if ev['room_id'] in xmppClients:
- xmppClients[ev['room_id']].stop()
- del xmppClients[ev['room_id']]
-
+ while True:
+ ev = matrixCli.getEvent()
+ print ev
+ if ev['type'] == 'm.room.member':
+ print 'membership event'
+ if ev['membership'] == 'invite' and ev['state_key'] == MYUSERNAME:
+ roomId = ev['room_id']
+ print "joining room %s" % (roomId)
+ matrixCli.joinRoom(roomId)
+ elif ev['type'] == 'm.room.message':
+ if ev['room_id'] in xmppClients:
+ print "already have a bridge for that user, ignoring"
+ continue
+ print "got message, connecting"
+ xmppClients[ev['room_id']] = TrivialXmppClient(ev['room_id'], ev['user_id'])
+ gevent.spawn(xmppClients[ev['room_id']].xmppLoop)
+ elif ev['type'] == 'm.call.invite':
+ print "Incoming call"
+ #sdp = ev['content']['offer']['sdp']
+ #print "sdp: %s" % (sdp)
+ #xmppClients[ev['room_id']] = TrivialXmppClient(ev['room_id'], ev['user_id'])
+ #gevent.spawn(xmppClients[ev['room_id']].xmppLoop)
+ elif ev['type'] == 'm.call.answer':
+ print "Call answered"
+ sdp = ev['content']['answer']['sdp']
+ if ev['room_id'] not in xmppClients:
+ print "We didn't have a call for that room"
+ continue
+ # should probably check call ID too
+ xmppCli = xmppClients[ev['room_id']]
+ xmppCli.sendAnswer(sdp)
+ elif ev['type'] == 'm.call.hangup':
+ if ev['room_id'] in xmppClients:
+ xmppClients[ev['room_id']].stop()
+ del xmppClients[ev['room_id']]
+
class TrivialXmppClient:
- def __init__(self, matrixRoom, userId):
- self.rid = 0
- self.matrixRoom = matrixRoom
- self.userId = userId
- self.running = True
-
- def stop(self):
- self.running = False
-
- def nextRid(self):
- self.rid += 1
- return '%d' % (self.rid)
-
- def sendIq(self, xml):
- fullXml = "%s" % (self.nextRid(), self.sid, xml)
- #print "\t>>>%s" % (fullXml)
- return self.xmppPoke(fullXml)
-
- def xmppPoke(self, xml):
- headers = {'Content-Type': 'application/xml'}
- req = grequests.post(HTTPBIND, verify=False, headers=headers, data=xml)
- resps = grequests.map([req])
- obj = BeautifulSoup(resps[0].content)
- return obj
-
- def sendAnswer(self, answer):
- print "sdp from matrix client",answer
- p = subprocess.Popen(['node', 'unjingle/unjingle.js', '--sdp'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
- jingle, out_err = p.communicate(answer)
- jingle = jingle % {
- 'tojid': self.callfrom,
- 'action': 'session-accept',
- 'initiator': self.callfrom,
- 'responder': self.jid,
- 'sid': self.callsid
- }
- print "answer jingle from sdp",jingle
- res = self.sendIq(jingle)
- print "reply from answer: ",res
-
- self.ssrcs = {}
- jingleSoup = BeautifulSoup(jingle)
- for cont in jingleSoup.iq.jingle.findAll('content'):
- if cont.description:
- self.ssrcs[cont['name']] = cont.description['ssrc']
- print "my ssrcs:",self.ssrcs
-
- gevent.joinall([
- gevent.spawn(self.advertiseSsrcs)
- ])
-
- def advertiseSsrcs(self):
+ def __init__(self, matrixRoom, userId):
+ self.rid = 0
+ self.matrixRoom = matrixRoom
+ self.userId = userId
+ self.running = True
+
+ def stop(self):
+ self.running = False
+
+ def nextRid(self):
+ self.rid += 1
+ return '%d' % (self.rid)
+
+ def sendIq(self, xml):
+ fullXml = "%s" % (self.nextRid(), self.sid, xml)
+ #print "\t>>>%s" % (fullXml)
+ return self.xmppPoke(fullXml)
+
+ def xmppPoke(self, xml):
+ headers = {'Content-Type': 'application/xml'}
+ req = grequests.post(HTTPBIND, verify=False, headers=headers, data=xml)
+ resps = grequests.map([req])
+ obj = BeautifulSoup(resps[0].content)
+ return obj
+
+ def sendAnswer(self, answer):
+ print "sdp from matrix client",answer
+ p = subprocess.Popen(['node', 'unjingle/unjingle.js', '--sdp'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+ jingle, out_err = p.communicate(answer)
+ jingle = jingle % {
+ 'tojid': self.callfrom,
+ 'action': 'session-accept',
+ 'initiator': self.callfrom,
+ 'responder': self.jid,
+ 'sid': self.callsid
+ }
+ print "answer jingle from sdp",jingle
+ res = self.sendIq(jingle)
+ print "reply from answer: ",res
+
+ self.ssrcs = {}
+ jingleSoup = BeautifulSoup(jingle)
+ for cont in jingleSoup.iq.jingle.findAll('content'):
+ if cont.description:
+ self.ssrcs[cont['name']] = cont.description['ssrc']
+ print "my ssrcs:",self.ssrcs
+
+ gevent.joinall([
+ gevent.spawn(self.advertiseSsrcs)
+ ])
+
+ def advertiseSsrcs(self):
time.sleep(7)
- print "SSRC spammer started"
- while self.running:
- ssrcMsg = "%(nick)s" % { 'tojid': "%s@%s/%s" % (ROOMNAME, ROOMDOMAIN, self.shortJid), 'nick': self.userId, 'assrc': self.ssrcs['audio'], 'vssrc': self.ssrcs['video'] }
- res = self.sendIq(ssrcMsg)
- print "reply from ssrc announce: ",res
- time.sleep(10)
-
-
-
- def xmppLoop(self):
- self.matrixCallId = time.time()
- res = self.xmppPoke("" % (self.nextRid(), HOST))
-
- print res
- self.sid = res.body['sid']
- print "sid %s" % (self.sid)
-
- res = self.sendIq("")
-
- res = self.xmppPoke("