Skip to content

Commit bfdf31f

Browse files
committed
Master Slave Working
Needs to remove styles when master is released
1 parent 371979a commit bfdf31f

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

server.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,21 @@ def handle_message(self, msg):
4343
#only the user with the lock can control
4444
if self._hasLock():
4545
msg_data = json.loads(msg)
46-
if "LOCK" in msg_data:
47-
if msg_data["LOCK"]:
46+
if "MASTER_REQUEST" in msg_data:
47+
if msg_data["MASTER_REQUEST"]:
4848
WebSocketHandler.lock_id = threading.current_thread().ident
49-
self.send_json(dict(LOCK=True));
49+
self.send_json(dict(MASTER_STATUS=True));
5050
print("Locking to thread: " ,WebSocketHandler.lock_id, " : ", threading.current_thread().ident)
5151
else:
5252
WebSocketHandler.lock_id = None
53-
self.send_json(dict(LOCK=False));
53+
self.send_json(dict(MASTER_STATUS=False));
5454
#elif "MESSAGE" in msg_data:
5555
# self.on_message(msg["MESSAGE"])
5656
#else:
5757
# print("Unknown CMD, trashing: ", msg_data)
5858
self.on_message(msg_data)
5959
else:
60+
self.send_json(dict(SLAVE=True));
6061
print("Locked, trashing: ", msg)
6162

6263
def on_close(self):

web/css/style.css

+12-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,18 @@ button:active{
4343
padding: 20px 20px 0px 20px;
4444
font-weight:bold;
4545
}
46-
46+
.disabled{
47+
background: #ccc;
48+
color: #999;
49+
box-shadow: none;
50+
}
51+
.disabled:hover{
52+
box-shadow: none;
53+
}
54+
.disabled:active{
55+
box-shadow: none;
56+
background: #ccc;
57+
}
4758

4859

4960
html,body,#wrapper {

web/js/controller.js

+33-12
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
Hammer.plugins.fakeMultitouch();
1212
var s = null;
1313
var somekeyDown = 0;
14-
var hasLock = false;
14+
var isMaster = false;
1515

1616
window.onbeforeunload = close;
1717

1818
/* -------------------------- Websocket Fucntions ----------------------------
1919
Functions used to handel the connection, opening, closing sendgin, and reciveing of the websocket
2020
*/
21-
21+
function log(msg){
22+
$("#DebugMsgList").append("<p>log: "+ msg + "</p>");
23+
}
2224
function open (e) {
2325
$("#DebugMsgList").append("<p>Connect!</p>");
2426
$("#ToggleCxnStatus").removeClass("danger");
@@ -31,11 +33,12 @@ function close(e) {
3133
};
3234
function msg (e) {
3335
msg_data = JSON.parse(e.data);
34-
if (msg_data.hasOwnProperty("LOCK")){
35-
$("#MasterLock").toggleClass("danger");
36-
msg_data["LOCK"] ? hasLock = true: hasLock = false;
36+
if (msg_data.hasOwnProperty("SLAVE")){ toggleSlave(msg_data["SLAVE"]); }
37+
if (msg_data.hasOwnProperty("MASTER_STATUS")){
38+
isMaster = msg_data["MASTER_STATUS"];
39+
styleMaster();
3740
}
38-
$("#DebugMsgList").append("<p>Received: "+ e.data + "</p>");
41+
log(e.data);
3942
};
4043
function error(e) {
4144
$("#DebugMsgList").append("<p>Error: "+e+"</p>");
@@ -52,7 +55,7 @@ function send(key,msg){
5255
$("#DebugMsgList").append("<p>Event: "+ data + "</p>");
5356
}
5457
}
55-
function toggleConnection(){
58+
function toggleConnection() {
5659
//Opens and closes a conenction using the address in #CxnWSAddress
5760
if(s){
5861
s.close(1000, "Try to Close");
@@ -74,13 +77,31 @@ function toggleConnection(){
7477
}
7578
}
7679
}
77-
function toggleLock(){
78-
if(hasLock){
79-
send("LOCK", false);
80+
function toggleLockCommand() { send("MASTER_REQUEST", !isMaster ); }
81+
function toggleSlave(locked) {
82+
//Toogle the control of all commands with locked status
83+
if(locked){
84+
//$(".ctrlBtn").attr("disabled", true).addClass("disabled");
85+
$(".ctrlBtn").addClass("disabled");
86+
//$("#MasterLock").addClass("danger");
87+
$("#ErrMsg").text("Locked").fadeIn();
8088
}else{
81-
send("LOCK", true);
89+
//$(".ctrlBtn").attr("disabled", false).removeClass("disabled");
90+
$(".ctrlBtn").removeClass("disabled");
91+
//$("#MasterLock").removeClass("danger");
92+
$("#ErrMsg").text("Locked").fadeOut();
8293
}
8394
}
95+
function styleMaster(){
96+
if(isMaster){
97+
log("You are now Master");
98+
$("#MasterLock").addClass("danger");
99+
}else{
100+
$("#MasterLock").removeClass("danger");
101+
}
102+
103+
}
104+
84105
/* -------------------------- Document Ready Function ----------------------------
85106
Main function, Handels all events, swipe, and keybord control
86107
Makes the QR code
@@ -107,7 +128,7 @@ $(document).ready(function(){
107128
$("#PopWrap").fadeIn();
108129
});
109130
$("#ToggleCxnBtn") .click( toggleConnection );
110-
$("#MasterLock") .click( toggleLock );
131+
$("#MasterLock") .click( toggleLockCommand );
111132
$("#PopWrapCloseBtn").click( function() { $("#PopWrap").fadeOut(); });
112133
$("#DebugMsgListBtn").click( function() { $("#DebugMsgList").empty(); });
113134
$("#ToggleControl") .click( function() {

0 commit comments

Comments
 (0)