-
Notifications
You must be signed in to change notification settings - Fork 6
/
webserver.py
52 lines (41 loc) · 1.24 KB
/
webserver.py
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
import cherrypy
import zmq
import json
context = zmq.Context()
socket = context.socket(zmq.PUB)
socket.bind("tcp://*:5891")
class Base(object):
@cherrypy.expose
def index(self):
return open('index.html').read()
@cherrypy.expose
def pause(self):
message = {'action': 'PAUSE'}
self.send_message(message)
@cherrypy.expose
def play(self):
message = {'action': 'PLAY'}
self.send_message(message)
@cherrypy.expose
def next(self):
message = {'action': 'NEXT'}
self.send_message(message)
@cherrypy.expose
def next_jump(self):
message = {'action': 'NEXT_LOOP'}
self.send_message(message)
@cherrypy.expose
def previous_loop(self):
message = {'action': 'PREV_LOOP'}
self.send_message(message)
@cherrypy.expose
def previous_section(self):
message = {'action': 'PREV_SECTION'}
self.send_message(message)
def send_message(self, message):
raw_message = json.dumps(message)
socket.send_string("DDP {}".format(raw_message))
print("Sending {}.".format(message))
raise cherrypy.HTTPRedirect("/")
cherrypy.config.update({'server.socket_host': '0.0.0.0'})
cherrypy.quickstart(Base())