|
@@ -16,6 +16,12 @@ ptable["video"] = [ "/home/nginx/scripts-snowmix/working-udp-video.sh", "1", "0"
|
|
|
ptable["rtmp"] = [ "/home/nginx/scripts-snowmix/stream.sh"]
|
|
ptable["rtmp"] = [ "/home/nginx/scripts-snowmix/stream.sh"]
|
|
|
|
|
|
|
|
log_list = {}
|
|
log_list = {}
|
|
|
|
|
+DEBUG = False
|
|
|
|
|
+
|
|
|
|
|
+def log(s):
|
|
|
|
|
+ if DEBUG == False:
|
|
|
|
|
+ return
|
|
|
|
|
+ print(s)
|
|
|
|
|
|
|
|
def conn(target):
|
|
def conn(target):
|
|
|
global ws
|
|
global ws
|
|
@@ -34,25 +40,25 @@ def close():
|
|
|
ws.close()
|
|
ws.close()
|
|
|
|
|
|
|
|
def sighandler(signal,frame):
|
|
def sighandler(signal,frame):
|
|
|
- print("\rExiting!")
|
|
|
|
|
|
|
+ log("\rExiting!")
|
|
|
close()
|
|
close()
|
|
|
- print("Bye!")
|
|
|
|
|
|
|
+ log("Bye!")
|
|
|
sys.exit(0)
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
def stop(key):
|
|
def stop(key):
|
|
|
if key not in p_list:
|
|
if key not in p_list:
|
|
|
- print("key %s doesn't exist! not killing!" % (key))
|
|
|
|
|
|
|
+ log("key %s doesn't exist! not killing!" % (key))
|
|
|
return
|
|
return
|
|
|
try:
|
|
try:
|
|
|
os.killpg(os.getpgid(p_list[key].pid), signal.SIGTERM)
|
|
os.killpg(os.getpgid(p_list[key].pid), signal.SIGTERM)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print("This process (%d) can't be killed! Why?" % p_list[key].pid)
|
|
|
|
|
- print(e)
|
|
|
|
|
|
|
+ log("This process (%d) can't be killed! Why?" % p_list[key].pid)
|
|
|
|
|
+ log(e)
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
log_list[key].close()
|
|
log_list[key].close()
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print("ex file: %s" % e)
|
|
|
|
|
|
|
+ log("ex file: %s" % e)
|
|
|
|
|
|
|
|
if key in log_list:
|
|
if key in log_list:
|
|
|
del log_list[key]
|
|
del log_list[key]
|
|
@@ -61,10 +67,14 @@ def stop(key):
|
|
|
|
|
|
|
|
def launch(key,options=None):
|
|
def launch(key,options=None):
|
|
|
if key in p_list:
|
|
if key in p_list:
|
|
|
- print("key %s exist! not running!" % (key))
|
|
|
|
|
|
|
+ log("key %s exist! not running!" % (key))
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
- tolaunch = ptable[j["key"]]
|
|
|
|
|
|
|
+ if key not in ptable:
|
|
|
|
|
+ log("This process (%s) is not on my table!" % key)
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ tolaunch = ptable[key]
|
|
|
if options is not None:
|
|
if options is not None:
|
|
|
tolaunch = tolaunch + options
|
|
tolaunch = tolaunch + options
|
|
|
|
|
|
|
@@ -84,9 +94,9 @@ def sendmsg(msg):
|
|
|
ret=s.recv(4096)
|
|
ret=s.recv(4096)
|
|
|
s.close()
|
|
s.close()
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
|
|
|
|
+ log(e)
|
|
|
return None
|
|
return None
|
|
|
- print("[nc output] %s " % ret)
|
|
|
|
|
|
|
+ log("[nc output] %s " % ret)
|
|
|
return ret
|
|
return ret
|
|
|
|
|
|
|
|
ip="ws://192.168.1.208:9001"
|
|
ip="ws://192.168.1.208:9001"
|
|
@@ -98,21 +108,23 @@ while True:
|
|
|
try:
|
|
try:
|
|
|
data = ws.recv()
|
|
data = ws.recv()
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
|
|
|
|
+ log(e)
|
|
|
conn(ip)
|
|
conn(ip)
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
try:
|
|
|
j = json.loads(data)
|
|
j = json.loads(data)
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
|
- print(e)
|
|
|
|
|
- print("Invalid json?")
|
|
|
|
|
|
|
+ log(e)
|
|
|
|
|
+ log("Invalid json?")
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
if ("type" not in j or "command" not in j or
|
|
if ("type" not in j or "command" not in j or
|
|
|
"key" not in j or j["type"] != "snowmix"):
|
|
"key" not in j or j["type"] != "snowmix"):
|
|
|
|
|
+ log("Dropping: %s" % j)
|
|
|
continue
|
|
continue
|
|
|
|
|
|
|
|
|
|
+ log(j)
|
|
|
if j["command"] == "launch":
|
|
if j["command"] == "launch":
|
|
|
launch(j["key"])
|
|
launch(j["key"])
|
|
|
|
|
|