Mercurial > code > home > repos > light9
annotate bin/subserver @ 1517:3bb58b74c9c1
timeline: add cache of floats between graph updates for smoother redraws
Ignore-this: dbdc4782855087f4ec12f1d24d440484
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Wed, 12 Apr 2017 06:04:18 +0000 |
parents | 6fd81bd4b4a7 |
children | a5a44077c54c |
rev | line source |
---|---|
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
1 #!bin/python |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
2 """ |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
3 live web display of all existing subs with pictures, mainly for |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
4 dragging them into CC |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
5 """ |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
6 from run_local import log |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
7 import sys, optparse, logging, json, subprocess, datetime |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
8 from dateutil.tz import tzlocal |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
9 from twisted.internet import reactor, defer |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
10 import cyclone.web, cyclone.httpclient, cyclone.websocket |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
11 from rdflib import RDF, URIRef, Literal |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
12 import pyjade.utils |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
13 from light9.rdfdb.syncedgraph import SyncedGraph |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
14 from light9.rdfdb.patch import Patch |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
15 from light9.namespaces import L9, DCTERMS |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
16 from light9 import networking, showconfig |
222 | 17 |
1060
473db8bebb8f
install a copy of cycloneerr.py
Drew Perttula <drewp@bigasterisk.com>
parents:
1041
diff
changeset
|
18 from lib.cycloneerr import PrettyErrorHandler |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
19 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
20 liveClients = set() |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
21 def sendToLiveClients(d=None, asJson=None): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
22 j = asJson or json.dumps(d) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
23 for c in liveClients: |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
24 c.sendMessage(j) |
222 | 25 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
26 class Live(cyclone.websocket.WebSocketHandler): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
27 def connectionMade(self, *args, **kwargs): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
28 log.info("websocket opened") |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
29 liveClients.add(self) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
30 self.settings.onNewClient() |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
31 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
32 def connectionLost(self, reason): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
33 log.info("websocket closed") |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
34 liveClients.remove(self) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
35 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
36 def messageReceived(self, message): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
37 log.info("got message %s" % message) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
38 self.sendMessage(message) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
39 |
1104
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
40 class EffectsUpdates(cyclone.websocket.WebSocketHandler): |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
41 def connectionMade(self, *args, **kwargs): |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
42 self.connected = True |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
43 self.settings.graph.addHandler(self.onGraphChange) |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
44 |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
45 def connectionLost(self, reason): |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
46 self.connected = False |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
47 |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
48 def onGraphChange(self): |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
49 if not self.connected: |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
50 return |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
51 graph = self.settings.graph |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
52 classes = [] |
1384
6fd81bd4b4a7
song has 25 demo notes. drop Class from EffectClass
Drew Perttula <drewp@bigasterisk.com>
parents:
1247
diff
changeset
|
53 for e in graph.subjects(RDF.type, L9['Effect']): |
1104
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
54 classes.append({'uri': e, |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
55 'label': graph.label(e), |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
56 'code': graph.value(e, L9['code'])}) |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
57 self.sendMessage({'classes': classes}) |
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
58 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
59 class Static(PrettyErrorHandler, cyclone.web.StaticFileHandler): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
60 def get(self, path, *args, **kw): |
1104
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
61 if path in ['', 'effects']: |
953
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
62 return self.respondStaticJade("light9/subserver/%s.jade" % |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
63 (path or 'index')) |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
64 |
1041
a4632a7b2e17
upgrade knockout and jquery, simplify the static/ dirs for all web services
Drew Perttula <drewp@bigasterisk.com>
parents:
976
diff
changeset
|
65 if path.endswith(".js"): |
953
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
66 return self.responseStaticCoffee( |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
67 'light9/subserver/%s' % |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
68 path.replace(".js", ".coffee")) # potential security hole |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
69 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
70 cyclone.web.StaticFileHandler.get(self, path, *args, **kw) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
71 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
72 def respondStaticJade(self, src): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
73 html = pyjade.utils.process(open(src).read()) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
74 self.write(html) |
222 | 75 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
76 def responseStaticCoffee(self, src): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
77 self.write(subprocess.check_output([ |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
78 '/usr/bin/coffee', '--compile', '--print', src])) |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
79 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
80 class Snapshot(PrettyErrorHandler, cyclone.web.RequestHandler): |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
81 @defer.inlineCallbacks |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
82 def post(self): |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
83 about = URIRef(self.get_argument("about")) |
976 | 84 response = yield cyclone.httpclient.fetch(networking.vidref.path("snapshot"), method="POST", timeout=1) |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
85 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
86 snapUri = URIRef(json.loads(response.body)['snapshot']) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
87 # vidref could write about when it was taken, etc. would it be |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
88 # better for us to tell vidref where to attach the result in |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
89 # the graph, and then it doesn't even have to return anything? |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
90 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
91 ctx = showconfig.showUri() + "/snapshots" |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
92 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
93 self.settings.graph.patch(Patch(addQuads=[ |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
94 (about, L9['image'], snapUri, ctx), |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
95 (snapUri, DCTERMS['created'], |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
96 Literal(datetime.datetime.now(tzlocal())), ctx), |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
97 ])) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
98 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
99 self.write(json.dumps({'snapshot': snapUri})) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
100 |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
101 def newestImage(subject): |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
102 newest = (None, None) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
103 for img in graph.objects(subject, L9['image']): |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
104 created = graph.value(img, DCTERMS['created']) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
105 if created > newest[0]: |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
106 newest = (created, img) |
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
107 return newest[1] |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
108 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
109 if __name__ == "__main__": |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
110 parser = optparse.OptionParser() |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
111 parser.add_option("-v", "--verbose", action="store_true", |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
112 help="logging.DEBUG") |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
113 (options, args) = parser.parse_args() |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
114 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
115 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
116 |
1217
e703b3434dbd
websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents:
1212
diff
changeset
|
117 graph = SyncedGraph(networking.rdfdb.url, "subServer") |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
118 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
119 d = {} |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
120 def updateSubs(): |
923
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
121 subs = [] |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
122 for sub in sorted(graph.subjects(RDF.type, L9['Submaster'])): |
923
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
123 rec = {'uri' : sub} |
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
124 rec['isLocal'] = graph.contains((sub, RDF.type, |
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
125 L9['LocalSubmaster'])) |
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
126 rec['label'] = graph.label(sub) |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
127 rec['img'] = newestImage(sub) |
923
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
128 subs.append(rec) |
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
129 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
130 d.clear() |
923
8b95d2865643
subserver shows real submasters, stays live. pretty sweet
drewp@bigasterisk.com
parents:
919
diff
changeset
|
131 d.update({'subs': subs}) |
953
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
132 |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
133 d['chases'] = [] |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
134 for chase in sorted(graph.subjects(RDF.type, L9['Chase'])): |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
135 fakeLabel = chase.rsplit('/', 1)[-1] |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
136 d['chases'].append({ |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
137 'uri': chase, |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
138 'label': fakeLabel, |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
139 }) |
891f2d75c686
subserver now also serves some premade subterms with the defined chases
drewp@bigasterisk.com
parents:
942
diff
changeset
|
140 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
141 sendToLiveClients(d=d) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
142 def onNewClient(): |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
143 sendToLiveClients(d=d) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
144 |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
145 graph.addHandler(updateSubs) |
222 | 146 |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
147 |
1217
e703b3434dbd
websocket and web cleanup
Drew Perttula <drewp@bigasterisk.com>
parents:
1212
diff
changeset
|
148 port = networking.subServer.port |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
149 reactor.listenTCP(port, cyclone.web.Application(handlers=[ |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
150 (r'/live', Live), |
1104
448fe9f81501
start to convert subserver to offer the new effects
Drew Perttula <drewp@bigasterisk.com>
parents:
1060
diff
changeset
|
151 (r'/effectsUpdates', EffectsUpdates), |
942
dd896321faee
subserver can get a snapshot from vidref and display it on the sub
drewp@bigasterisk.com
parents:
923
diff
changeset
|
152 (r'/snapshot', Snapshot), |
919
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
153 (r'/(.*)', Static, |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
154 {"path" : "light9/subserver", |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
155 "default_filename" : "index.jade"}), |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
156 ], debug=True, graph=graph, onNewClient=onNewClient)) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
157 log.info("serving on %s" % port) |
33a5a98e9bf1
start subserver webapp with websockets, cyclone, jade, coffee
drewp@bigasterisk.com
parents:
310
diff
changeset
|
158 reactor.run() |