forked from superisaac/rushkit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestbad.py
More file actions
56 lines (46 loc) · 1.65 KB
/
testbad.py
File metadata and controls
56 lines (46 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from twisted.internet import reactor, defer
from twisted.internet.protocol import Protocol, Factory
import _pyrushkit as rushkit
class RTMPProtocol(Protocol):
def handleWriteData(self, data, *args):
self.transport.write(data)
def amf_add(self, a, b):
d = self.send('greeting', {'ans': a + b * 2})
def pp(x):
print 'got', x
d.addCallback(pp)
return a + b * 7
def send(self, method, *args):
reqid = rushkit.my_amf_call(self._proto, method, list(args))
d = defer.Deferred()
self._calls[reqid] = d
return d
def handleInvoke(self, reqid, methodname, args):
if methodname == '_result':
if reqid in self._calls:
self._calls[reqid].callback(args[0])
del self._calls[reqid]
else:
func = getattr(self, 'amf_%s' % methodname, None)
if func:
ret = func(*tuple(args))
if ret:
rushkit.amf_return(self._proto, reqid, ret)
def connectionMade(self):
print 'connection made'
self._calls = {}
self._proto = rushkit.new_RTMP_PROTO()
rushkit.init_responder(self._proto, self)
def dataReceived(self, data):
rushkit.feed_data(self._proto, data)
def connectionLost(self, reason):
if self._proto:
rushkit.delete_RTMP_PROTO(self._proto)
self._proto = None
class RTMPFactory(Factory):
protocol = RTMPProtocol
if __name__ == '__main__':
rushkit.environment_init()
factory = RTMPFactory()
reactor.listenTCP(1935, factory)
reactor.run()