1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import os
23
24 from twisted.web.resource import Resource
25 from twisted.web.static import Data, File
26
27 from flumotion.common import log
28 from flumotion.common.errors import ComponentStartError
29 from flumotion.component.misc.httpserver.httpserver import HTTPFileStreamer
30 from flumotion.component.plugs.base import ComponentPlug
31 from flumotion.component.plugs.cortado.cortado_location import getCortadoFilename
32 from flumotion.configure import configure
33
34 __version__ = "$Rev: 6288 $"
35
37 if value:
38 return 'true'
39 return 'false'
40
41
43 """I generate the directory used to serve a cortado applet
44 It contains::
45 - a html file, usually called index.html.
46 - cortado.jar - cortado java applet
47 """
48
49 - def __init__(self, mount_point, properties, filename):
50 Resource.__init__(self)
51
52 index_name = properties.get('index', 'index.html')
53
54 root = mount_point
55 if not root.endswith("/"):
56 root += "/"
57 if index_name != 'index.html':
58 root = None
59 self._mount_point_root = root
60 self._properties = properties
61 self._index_content = self._get_index_content()
62 self._index_name = index_name
63 self._cortado_filename = filename
64 self._addChildren()
65
67 self.putChild("cortado.jar",
68 File(self._cortado_filename,
69 'application/x-java-archive'))
70
71 self.putChild(self._index_name,
72 self._index_content)
73
80
82 html_template = self._get_template_filename()
83 ns = {}
84 ns['has-audio'] = _htmlbool(self._properties['has-audio'])
85 ns['has-video'] = _htmlbool(self._properties['has-video'])
86 for attribute in ['codebase',
87 'width',
88 'height',
89 'stream-url',
90 'buffer-size',
91 'framerate']:
92 ns[attribute] = self._properties[attribute]
93
94 data = open(html_template, 'r').read()
95 content = data % ns
96 return Data(content, 'text/html')
97
98
99
101
102 if request.uri == self._mount_point_root:
103 return self._index_content
104 return Resource.getChildWithDefault(self, pathEl, request)
105
106
108 """I am a component plug for a http-server which plugs in a
109 http resource containing a cortado java applet.
110 """
111 - def start(self, component):
129
130
132 import sys
133 from twisted.internet import reactor
134 from twisted.python.log import startLogging
135 from twisted.web.server import Site
136 startLogging(sys.stderr)
137
138 properties = {'has-audio': True,
139 'has-video': True,
140 'codebase': '/',
141 'width' : 320,
142 'height' : 240,
143 'stream-url' : '/stream.ogg',
144 'buffer-size': 40,
145 'framerate' : 1}
146 root = CortadoDirectoryResource('/', properties, getCortadoFilename())
147 site = Site(root)
148
149 reactor.listenTCP(8080, site)
150 reactor.run()
151
152 if __name__ == "__main__":
153 test()
154