summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--voctocore/controlserver.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/voctocore/controlserver.py b/voctocore/controlserver.py
index 8397705..da27408 100644
--- a/voctocore/controlserver.py
+++ b/voctocore/controlserver.py
@@ -1,4 +1,33 @@
-class ControlServer:
+import socket, threading, queue
+from gi.repository import GObject
+class ControlServer():
def __init__(self, videomix):
+ '''Initialize server and start listening.'''
self.videomix = videomix
+
+ sock = socket.socket()
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ sock.bind(('0.0.0.0', 23000))
+ sock.listen(1)
+ GObject.io_add_watch(sock, GObject.IO_IN, self.listener)
+
+ def listener(self, sock, *args):
+ '''Asynchronous connection listener. Starts a handler for each connection.'''
+ conn, addr = sock.accept()
+ print("Connected")
+ GObject.io_add_watch(conn, GObject.IO_IN, self.handler)
+ return True
+
+ def handler(self, conn, *args):
+ '''Asynchronous connection handler. Processes each line from the socket.'''
+ line = conn.recv(4096)
+ if not len(line):
+ print("Connection closed.")
+ return False
+
+ livevideo = self.videomix.pipeline.get_by_name('livevideo')
+ pad = livevideo.get_static_pad('sink_1')
+ pad.set_property('alpha', 00)
+ print(line)
+ return True