Skip to content

Commit

Permalink
Drop keystroke-received socket event (#261)
Browse files Browse the repository at this point in the history
I didn't realize we can just handle it in the .emit() response parameter.
  • Loading branch information
mtlynch authored Sep 22, 2020
1 parent 9d80196 commit 0c3347d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
11 changes: 4 additions & 7 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,19 @@ def socket_keystroke(message):
except js_to_hid.UnrecognizedKeyCodeError:
logger.warning('Unrecognized key: %s (keycode=%d)', keystroke.key,
keystroke.key_code)
socketio.emit('keystroke-received', processing_result)
return
return processing_result
if hid_keycode is None:
logger.info('Ignoring %s key (keycode=%d)', keystroke.key,
keystroke.key_code)
socketio.emit('keystroke-received', processing_result)
return
return processing_result
try:
fake_keyboard.send_keystroke(keyboard_path, control_keys, hid_keycode)
except hid_write.WriteError as e:
logger.error('Failed to write key: %s (keycode=%d). %s', keystroke.key,
keystroke.key_code, e)
socketio.emit('keystroke-received', processing_result)
return
return processing_result
processing_result['success'] = True
socketio.emit('keystroke-received', processing_result)
return processing_result


@socketio.on('mouse-event')
Expand Down
7 changes: 3 additions & 4 deletions app/static/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ function sendKeystroke(keystroke) {
if (!keystroke.metaKey) {
addKeyCard(keystroke.key, keystroke.id);
}
socket.emit("keystroke", keystroke);
socket.emit("keystroke", keystroke, (result) => {
updateKeyStatus(result.keystrokeId, result.success);
});
if (!keystroke.metaKey) {
// Increment the global keystroke ID.
keystrokeId++;
Expand Down Expand Up @@ -373,6 +375,3 @@ for (const cursorOption of screenCursorOptions.splice(1)) {
}
socket.on("connect", onSocketConnect);
socket.on("disconnect", onSocketDisconnect);
socket.on("keystroke-received", (keystrokeResult) => {
updateKeyStatus(keystrokeResult.keystrokeId, keystrokeResult.success);
});

0 comments on commit 0c3347d

Please sign in to comment.