also looking at this
fix(bridge): stop discarding the fields the page actually sends
#82
7 files
+375
-34
| @@ -463,16 +463,28 @@ pub const BluetoothBridge = struct { | ||
| 463 | 463 | |
| 464 | 464 | /// Connect to a Bluetooth device |
| 465 | 465 | /// JSON: {"address": "XX:XX:XX:XX:XX:XX"} |
| 466 | fn connectDevice(self: *Self, data: []const u8) !void { | |
| 467 | _ = self; | |
| 468 | var address: []const u8 = ""; | |
| 469 | ||
| 470 | if (std.mem.indexOf(u8, data, "\"address\":\"")) |idx| { | |
| 471 | const start = idx + 11; | |
| 472 | if (std.mem.indexOfPos(u8, data, start, "\"")) |end| { | |
| 473 | address = data[start..end]; | |
| 466 | /// The device a connect/disconnect names. | |
| 467 | /// | |
| 468 | /// `craft.bluetooth.connectDevice(id)` sends `{"id":"…"}`, and both | |
| 469 | /// handlers scanned only for `"address":"`. The needle never matched, the | |
| 470 | /// address stayed empty, and the call failed its own `MissingData` check — | |
| 471 | /// so connecting to a device found by `craft.bluetooth.onDeviceFound` was | |
| 472 | /// impossible. `address` stays accepted for anything posting raw messages. | |
| 473 | fn deviceAddress(data: []const u8) []const u8 { | |
| 474 | for ([_][]const u8{ "\"id\":\"", "\"address\":\"" }) |key| { | |
| 475 | if (std.mem.indexOf(u8, data, key)) |idx| { | |
| 476 | const start = idx + key.len; | |
| 477 | if (std.mem.indexOfPos(u8, data, start, "\"")) |end| { | |
| 478 | return data[start..end]; | |
| 479 | } | |
| 474 | 480 | } |
| 475 | 481 | } |
| 482 | return ""; | |
| 483 | } | |
| 484 | ||
| 485 | fn connectDevice(self: *Self, data: []const u8) !void { | |
| 486 | _ = self; | |
| 487 | const address = deviceAddress(data); | |
| 476 | 488 | |
| 477 | 489 | if (address.len == 0) return BridgeError.MissingData; |
| 478 | 490 | |
| @@ -497,14 +509,7 @@ pub const BluetoothBridge = struct { | ||
| 497 | 509 | /// JSON: {"address": "XX:XX:XX:XX:XX:XX"} |
| 498 | 510 | fn disconnectDevice(self: *Self, data: []const u8) !void { |
| 499 | 511 | _ = self; |
| 500 | var address: []const u8 = ""; | |
| 501 | ||
| 502 | if (std.mem.indexOf(u8, data, "\"address\":\"")) |idx| { | |
| 503 | const start = idx + 11; | |
| 504 | if (std.mem.indexOfPos(u8, data, start, "\"")) |end| { | |
| 505 | address = data[start..end]; | |
| 506 | } | |
| 507 | } | |
| 512 | const address = deviceAddress(data); | |
| 508 | 513 | |
| 509 | 514 | if (address.len == 0) return BridgeError.MissingData; |
| 510 | 515 | |