Fix bug preventing manual snes reconnect. Update WebUI to automatically connect if only one SNES device is detected.

This commit is contained in:
Chris 2020-06-06 19:58:10 -04:00
parent fbd00136e7
commit 7d42137782
4 changed files with 28 additions and 40 deletions

View File

@ -1209,7 +1209,7 @@ async def websocket_server(websocket: websockets.WebSocketServerProtocol, path,
async for incoming_data in websocket: async for incoming_data in websocket:
try: try:
data = json.loads(incoming_data) data = json.loads(incoming_data)
logging.debug(f"WebUIData:{data}") logging.info(f"WebUIData:{data}")
if ('type' not in data) or ('content' not in data): if ('type' not in data) or ('content' not in data):
raise Exception('Invalid data received in websocket') raise Exception('Invalid data received in websocket')
@ -1229,11 +1229,10 @@ async def websocket_server(websocket: websockets.WebSocketServerProtocol, path,
ctx.ui_node.manual_snes = None ctx.ui_node.manual_snes = None
ctx.snes_reconnect_address = None ctx.snes_reconnect_address = None
await snes_disconnect(ctx) await snes_disconnect(ctx)
return else:
await snes_disconnect(ctx)
await snes_disconnect(ctx) ctx.ui_node.manual_snes = data['content']['deviceId']
ctx.ui_node.manual_snes = data['content']['deviceId'] await snes_connect(ctx, ctx.snes_address)
await snes_connect(ctx, ctx.snes_address)
elif data['type'] == 'webControl': elif data['type'] == 'webControl':
if 'disconnect' in data['content']: if 'disconnect' in data['content']:

View File

@ -5044,14 +5044,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
@ -5066,20 +5064,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
@ -5196,8 +5191,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
@ -5209,7 +5203,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
@ -5224,7 +5217,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
@ -5232,14 +5224,12 @@
"minimist": { "minimist": {
"version": "1.2.5", "version": "1.2.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.9.0", "version": "2.9.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
@ -5258,7 +5248,6 @@
"version": "0.5.3", "version": "0.5.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "^1.2.5" "minimist": "^1.2.5"
} }
@ -5320,8 +5309,7 @@
"npm-normalize-package-bin": { "npm-normalize-package-bin": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"npm-packlist": { "npm-packlist": {
"version": "1.4.8", "version": "1.4.8",
@ -5349,8 +5337,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
@ -5362,7 +5349,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@ -5476,7 +5462,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",

File diff suppressed because one or more lines are too long

View File

@ -41,20 +41,24 @@ class MonitorControls extends Component {
if (this.props.webSocket) { if (this.props.webSocket) {
// Poll for available devices // Poll for available devices
this.pollSnesDevices(); this.pollSnesDevices();
setTimeout(() => {
if (this.props.availableDevices.length === 1) {
this.setState({ deviceId: this.props.availableDevices[0] }, () => {
if (!this.props.snesConnected) {
this.connectToSnes();
}
});
}
}, 500);
} }
}, 500); }, 500);
} }
componentDidUpdate(prevProps) {
if (
prevProps.availableDevices.length !== this.props.availableDevices.length &&
this.props.availableDevices.length === 1
) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({ deviceId: this.props.availableDevices[0] }, () => {
if (!this.props.snesConnected) {
this.connectToSnes();
}
});
}
}
increaseTextSize = () => { increaseTextSize = () => {
if (this.props.fontSize >= 25) return; if (this.props.fontSize >= 25) return;
this.props.updateFontSize(this.props.fontSize + 1); this.props.updateFontSize(this.props.fontSize + 1);