mirror of
https://github.com/zhaojh329/rtty.git
synced 2026-02-27 09:53:17 +08:00
Fix ID conflicts
Signed-off-by: Jianhui Zhao <jianhuizhao329@gmail.com>
This commit is contained in:
+7
-1
@@ -15,7 +15,10 @@ class Devices:
|
||||
devs = {}
|
||||
|
||||
def add(self, ws, did):
|
||||
if self.devs.get(did):
|
||||
return False
|
||||
self.devs[did] = {'ws': ws, 'active': 3}
|
||||
return True
|
||||
|
||||
def active(self, did):
|
||||
self.devs[did]['active'] = 3
|
||||
@@ -62,7 +65,10 @@ async def websocket_handler_device(request):
|
||||
await ws.prepare(request)
|
||||
|
||||
did = request.query['did']
|
||||
devices.add(ws, did)
|
||||
if not devices.add(ws, did):
|
||||
# Fix me
|
||||
ws.send_str(json.dumps({'type': 'add', 'err': 'ID conflicts'}))
|
||||
return ws
|
||||
|
||||
syslog.syslog('New device:' + did)
|
||||
|
||||
|
||||
+10
@@ -40,6 +40,7 @@ enum {
|
||||
RTTYD_TYPE,
|
||||
RTTYD_DID,
|
||||
RTTYD_SID,
|
||||
RTTYD_ERR,
|
||||
RTTYD_DATA
|
||||
};
|
||||
|
||||
@@ -56,6 +57,10 @@ static const struct blobmsg_policy pol[] = {
|
||||
.name = "sid",
|
||||
.type = BLOBMSG_TYPE_STRING,
|
||||
},
|
||||
[RTTYD_ERR] = {
|
||||
.name = "err",
|
||||
.type = BLOBMSG_TYPE_STRING,
|
||||
},
|
||||
[RTTYD_DATA] = {
|
||||
.name = "data",
|
||||
.type = BLOBMSG_TYPE_STRING,
|
||||
@@ -240,6 +245,11 @@ static void uwsc_onmessage(struct uwsc_client *cl, char *msg, uint64_t len, enum
|
||||
}
|
||||
} else if (!strcmp(type, "pong")) {
|
||||
active = 3;
|
||||
} else if (!strcmp(type, "add")) {
|
||||
if (tb[RTTYD_ERR]) {
|
||||
uwsc_log_err("add failed: %s", blobmsg_get_string(tb[RTTYD_ERR]));
|
||||
uloop_end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user