author | rougeronj |
Sat, 18 Apr 2015 09:37:57 +0200 | |
changeset 167 | 2b99fed0285e |
parent 43 | e27c3c1c57f1 |
permissions | -rw-r--r-- |
0 | 1 |
|
2 |
from autobahn.twisted.resource import WebSocketResource, \ |
|
3 |
WSGIRootResource, \ |
|
4 |
HTTPChannelHixie76Aware |
|
5 |
||
6 |
||
7 |
from twisted.application import service, internet, strports |
|
8 |
from twisted.internet import reactor |
|
9 |
from twisted.python.threadpool import ThreadPool |
|
43
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
10 |
from twisted.web import server, resource |
0 | 11 |
from twisted.web.wsgi import WSGIResource |
2
fc1ab0074e29
export config in config file + add static file
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
12 |
from twisted.web.static import Data, File |
0 | 13 |
|
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
14 |
import config |
0 | 15 |
from oscserver import OSCServerProtocol |
16 |
from websockets import BroadcastServerFactory, AnotationServerFactory |
|
17 |
from webapp import app |
|
18 |
||
19 |
||
20 |
WEB_PORT = 8080 |
|
21 |
WS_PORT = 8090 |
|
22 |
OSC_PORT = 9090 |
|
23 |
||
43
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
24 |
class BaseRedirect(resource.Resource): |
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
25 |
isLeaf = True |
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
26 |
def render_GET(self, request): |
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
27 |
request.redirect(request.URLPath().child('p/')) |
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
28 |
return "" |
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
29 |
|
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
30 |
def make_service(conn, debug=False): |
0 | 31 |
|
32 |
s = service.MultiService() |
|
33 |
# Create and start a thread pool, |
|
34 |
wsgiThreadPool = ThreadPool() |
|
35 |
wsgiThreadPool.start() |
|
36 |
||
37 |
# ensuring that it will be stopped when the reactor shuts down |
|
38 |
reactor.addSystemEventTrigger('after', 'shutdown', wsgiThreadPool.stop) |
|
39 |
||
40 |
||
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
41 |
wsFactory = BroadcastServerFactory("ws://localhost:%d/broadcast" % getattr(config,'WS_PORT',WS_PORT), |
0 | 42 |
debug = debug, |
43 |
debugCodePaths = debug) |
|
44 |
wsFactory.setProtocolOptions(allowHixie76 = True) |
|
45 |
wsResource = WebSocketResource(wsFactory) |
|
46 |
||
47 |
||
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
48 |
wsAnnotFactory = AnotationServerFactory("ws://localhost:%d/annot" % getattr(config,'WS_PORT',WS_PORT), |
0 | 49 |
debug = debug, |
50 |
debugCodePaths = debug, |
|
51 |
ws_factory = wsFactory, |
|
52 |
conn = conn) |
|
53 |
wsAnnotFactory.setProtocolOptions(allowHixie76 = True) |
|
54 |
wsAnnotResource = WebSocketResource(wsAnnotFactory) |
|
55 |
||
56 |
||
57 |
rootWs = Data("", "text/plain") |
|
58 |
||
59 |
rootWs.putChild("broadcast", wsResource) |
|
60 |
rootWs.putChild("annot", wsAnnotResource) |
|
61 |
||
2
fc1ab0074e29
export config in config file + add static file
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
62 |
webResource = resource.Resource() |
43
e27c3c1c57f1
end of admin. change the index page and add a redirect to it on the landing page
ymh <ymh.work@gmail.com>
parents:
13
diff
changeset
|
63 |
webResource.putChild("",BaseRedirect()) |
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
64 |
webResource.putChild(getattr(config,'STATIC_URL').lstrip('/'), File(getattr(config,'STATIC_ROOT'))) |
0 | 65 |
# Create the WSGI resource |
66 |
wsgiAppAsResource = WSGIResource(reactor, wsgiThreadPool, app) |
|
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
67 |
webResource.putChild('p', wsgiAppAsResource) |
2
fc1ab0074e29
export config in config file + add static file
ymh <ymh.work@gmail.com>
parents:
0
diff
changeset
|
68 |
|
0 | 69 |
|
70 |
# Hooks for twistd |
|
71 |
||
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
72 |
webserver = strports.service('tcp:%d' % getattr(config,'WEB_PORT',WEB_PORT), server.Site(webResource)) |
0 | 73 |
webserver.setServiceParent(s) |
74 |
||
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
75 |
wsserver = strports.service('tcp:%d' % getattr(config,'WS_PORT',WS_PORT), server.Site(rootWs)) |
0 | 76 |
wsserver.setServiceParent(s) |
77 |
||
13
435d5c15275a
clean client npm and gulp config, change flask root url, reference static url in template, change config management to follow flask convention
ymh <ymh.work@gmail.com>
parents:
2
diff
changeset
|
78 |
oscservice = internet.UDPServer(getattr(config,'OSC_PORT',OSC_PORT), OSCServerProtocol(wsFactory, conn)) |
0 | 79 |
oscservice.setServiceParent(s) |
80 |
||
81 |
return s |