@geastack/host 0.1.27 → 0.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+ #include <vector>
6
+
7
+ namespace gea::host {
8
+
9
+ using CryptoBytes = std::vector<std::uint8_t>;
10
+
11
+ // Cryptography for app code (TS `Cryptography`, core index.d.ts): the
12
+ // primitives a device protocol or an end-to-end link needs. Hashing, HMAC,
13
+ // HKDF, AES-CTR and random bytes are portable (host/crypto.cpp); P-256 key
14
+ // agreement comes from the platform (Security.framework on Apple hosts) and
15
+ // returns empty bytes where there is none.
16
+ struct CryptographyFacade {
17
+ CryptoBytes sha256(const CryptoBytes &data) const;
18
+ CryptoBytes hmacSha256(const CryptoBytes &key, const CryptoBytes &data) const;
19
+ // RFC 5869 extract-then-expand; `length` is at most 8160 bytes.
20
+ CryptoBytes hkdfSha256(const CryptoBytes &keyMaterial, const CryptoBytes &salt, const CryptoBytes &info,
21
+ double length) const;
22
+ // AES-128/192/256 in counter mode with a 16-byte big-endian counter block.
23
+ // Encrypting and decrypting are the same operation. Empty on a bad key or counter.
24
+ CryptoBytes aesCtr(const CryptoBytes &key, const CryptoBytes &counter, const CryptoBytes &data) const;
25
+ CryptoBytes randomBytes(double length) const;
26
+ // A new P-256 key pair: the 65-byte uncompressed public key (0x04 || X || Y)
27
+ // followed by the 32-byte private scalar -- 97 bytes, ANSI X9.63. The first
28
+ // 65 bytes are what the peer needs.
29
+ CryptoBytes p256GenerateKey() const;
30
+ // ECDH: the 32-byte shared X coordinate for our 97-byte key and the peer's
31
+ // 65-byte public key. Empty when either key is malformed or P-256 is unsupported.
32
+ CryptoBytes p256SharedSecret(const CryptoBytes &privateKey, const CryptoBytes &peerPublicKey) const;
33
+ bool p256Supported() const;
34
+ };
35
+
36
+ inline constexpr CryptographyFacade Cryptography{};
37
+
38
+ namespace crypto_platform {
39
+ // Platform hooks; host/crypto.cpp holds weak fallbacks.
40
+ bool randomFill(std::uint8_t *bytes, std::size_t length);
41
+ CryptoBytes p256GenerateKey();
42
+ CryptoBytes p256SharedSecret(const CryptoBytes &privateKey, const CryptoBytes &peerPublicKey);
43
+ bool p256Supported();
44
+ } // namespace crypto_platform
45
+
46
+ } // namespace gea::host
@@ -0,0 +1,42 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+ #include <string>
6
+ #include <vector>
7
+
8
+ namespace gea::host {
9
+
10
+ // Byte-level file access for app code (TS `Files`, core index.d.ts): what a
11
+ // recorder spool, a resumable download or a WAV writer needs beyond the whole-
12
+ // file cache helpers (writeCacheFile/readCacheFile/readFileRange). Paths are
13
+ // plain filesystem paths; dataDirectory() is the app's own writable place.
14
+ struct FilesFacade {
15
+ // The app's writable data directory, created on first use: Application
16
+ // Support/<app name> on macOS, the app container on iOS, /sdcard on boards,
17
+ // $XDG_DATA_HOME (or ~/.local/share)/<app name> elsewhere.
18
+ std::string dataDirectory() const;
19
+ // mkdir -p; true when the directory exists afterwards.
20
+ bool makeDirectory(const std::string &path) const;
21
+ bool exists(const std::string &path) const;
22
+ // Size in bytes, or -1 when there is no such file.
23
+ double size(const std::string &path) const;
24
+ // Bytes from `offset`, at most `length`; fewer at the end of the file.
25
+ std::vector<std::uint8_t> read(const std::string &path, double offset, double length) const;
26
+ // Creates the file when missing.
27
+ bool append(const std::string &path, const std::vector<std::uint8_t> &bytes) const;
28
+ // Overwrites in place from `offset`, creating the file when missing.
29
+ bool writeAt(const std::string &path, double offset, const std::vector<std::uint8_t> &bytes) const;
30
+ bool truncate(const std::string &path, double size) const;
31
+ bool remove(const std::string &path) const;
32
+ bool rename(const std::string &from, const std::string &to) const;
33
+ };
34
+
35
+ inline constexpr FilesFacade Files{};
36
+
37
+ namespace files_platform {
38
+ // Platform hook; host/files.cpp holds the fallback.
39
+ std::string dataDirectory();
40
+ } // namespace files_platform
41
+
42
+ } // namespace gea::host
@@ -0,0 +1,37 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <string>
5
+
6
+ namespace gea::host {
7
+
8
+ // Menu bar mode for desktop apps (TS `MenuBar`, core index.d.ts). install()
9
+ // turns the app into a menu bar extra: no Dock icon, an SF Symbol in the menu
10
+ // bar, and the app's window becomes a borderless panel that drops down under
11
+ // the icon on click and hides when the app loses focus (right-click offers
12
+ // Quit). Frames keep running while the panel is hidden, so polling work
13
+ // (Bluetooth, sockets, timers) carries on. macOS only; elsewhere supported()
14
+ // is false and the calls do nothing.
15
+ struct MenuBarFacade {
16
+ bool supported() const;
17
+ // `symbol` is an SF Symbol name, e.g. "waveform".
18
+ bool install(const std::string &symbol) const;
19
+ void setSymbol(const std::string &symbol) const;
20
+ bool shown() const;
21
+ void show() const;
22
+ void hide() const;
23
+ };
24
+
25
+ inline constexpr MenuBarFacade MenuBar{};
26
+
27
+ namespace menu_bar_platform {
28
+ // Platform hooks; host/menu_bar.cpp holds the no-op fallbacks.
29
+ bool supported();
30
+ bool install(const std::string &symbol);
31
+ void setSymbol(const std::string &symbol);
32
+ bool shown();
33
+ void show();
34
+ void hide();
35
+ } // namespace menu_bar_platform
36
+
37
+ } // namespace gea::host
@@ -2,6 +2,9 @@
2
2
  #pragma once
3
3
 
4
4
  #include "backends.h"
5
+ #if defined(__APPLE__)
6
+ #include <TargetConditionals.h>
7
+ #endif
5
8
 
6
9
  #include <string>
7
10
 
@@ -309,6 +312,52 @@ public:
309
312
  }
310
313
  };
311
314
 
315
+ class BluetoothCentral {
316
+ public:
317
+ // Generic GATT central role -- see BluetoothCentral in the TS API
318
+ // (index.d.ts) and BluetoothCentralDriver in ble.h.
319
+ std::string state() const { return gea::framework::bluetooth::CentralBackend::state(); }
320
+ void startScan() const { gea::framework::bluetooth::CentralBackend::startScan(std::string()); }
321
+ void startScan(const std::string &services) const {
322
+ gea::framework::bluetooth::CentralBackend::startScan(services);
323
+ }
324
+ void stopScan() const { gea::framework::bluetooth::CentralBackend::stopScan(); }
325
+ bool scanning() const { return gea::framework::bluetooth::CentralBackend::scanning(); }
326
+ double scanCount() const { return gea::framework::bluetooth::CentralBackend::scanCount(); }
327
+ std::string scanIdAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanIdAt(index); }
328
+ std::string scanNameAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanNameAt(index); }
329
+ double scanRssiAt(double index) const { return gea::framework::bluetooth::CentralBackend::scanRssiAt(index); }
330
+ std::string scanServicesAt(double index) const {
331
+ return gea::framework::bluetooth::CentralBackend::scanServicesAt(index);
332
+ }
333
+ std::vector<std::uint8_t> scanManufacturerDataAt(double index) const {
334
+ return gea::framework::bluetooth::CentralBackend::scanManufacturerDataAt(index);
335
+ }
336
+ void clearScan() const { gea::framework::bluetooth::CentralBackend::clearScan(); }
337
+ void connect(const std::string &id, const std::string &services) const {
338
+ gea::framework::bluetooth::CentralBackend::connect(id, services);
339
+ }
340
+ std::string link() const { return gea::framework::bluetooth::CentralBackend::link(); }
341
+ std::string linkError() const { return gea::framework::bluetooth::CentralBackend::linkError(); }
342
+ void subscribe(const std::string &service, const std::string &characteristic) const {
343
+ gea::framework::bluetooth::CentralBackend::subscribe(service, characteristic);
344
+ }
345
+ bool subscribed(const std::string &service, const std::string &characteristic) const {
346
+ return gea::framework::bluetooth::CentralBackend::subscribed(service, characteristic);
347
+ }
348
+ bool write(const std::string &service, const std::string &characteristic,
349
+ const std::vector<std::uint8_t> &bytes) const {
350
+ return gea::framework::bluetooth::CentralBackend::write(service, characteristic, bytes);
351
+ }
352
+ std::vector<std::uint8_t> read(const std::string &service, const std::string &characteristic) const {
353
+ return gea::framework::bluetooth::CentralBackend::read(service, characteristic);
354
+ }
355
+ void requestRead(const std::string &service, const std::string &characteristic) const {
356
+ gea::framework::bluetooth::CentralBackend::requestRead(service, characteristic);
357
+ }
358
+ void disconnect() const { gea::framework::bluetooth::CentralBackend::disconnect(); }
359
+ };
360
+
312
361
  class Bluetooth {
313
362
  public:
314
363
  BluetoothKeyboard keyboard;
@@ -317,6 +366,7 @@ public:
317
366
  BluetoothHidHost hidHost;
318
367
  BluetoothConnections connections;
319
368
  BluetoothConfig config;
369
+ BluetoothCentral central;
320
370
 
321
371
  const Bluetooth &operator()() const { return *this; }
322
372
  bool enabled() const {
@@ -424,7 +474,23 @@ class Navigator {
424
474
  public:
425
475
  const char *userAgent = "gea-embedded";
426
476
  const char *language = "en-US";
427
- const char *platform = "embedded";
477
+ // The host this build runs on: "macos", "ios", "web", "windows", "linux" or
478
+ // "embedded" (a board). Lets one app adapt where a feature only exists on
479
+ // some hosts (a menu bar, a Bluetooth central).
480
+ const char *platform =
481
+ #if defined(__EMSCRIPTEN__)
482
+ "web";
483
+ #elif defined(__APPLE__) && TARGET_OS_IPHONE
484
+ "ios";
485
+ #elif defined(__APPLE__)
486
+ "macos";
487
+ #elif defined(_WIN32)
488
+ "windows";
489
+ #elif defined(__linux__) && !defined(ESP_PLATFORM) && !defined(GEA_GEAOS)
490
+ "linux";
491
+ #else
492
+ "embedded";
493
+ #endif
428
494
  bool onLine = true;
429
495
  WiFi wifi;
430
496
  Bluetooth bluetooth;
@@ -0,0 +1,35 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+ #include <vector>
6
+
7
+ namespace gea::host {
8
+
9
+ // Opus decoding for app code (TS `Opus`, core index.d.ts): turns a stream of
10
+ // Opus packets (the 48 kHz codec every Bluetooth voice recorder and WebRTC
11
+ // peer speaks) into 16-bit PCM. A decoder keeps its state between calls, so a
12
+ // stream decoded batch by batch has no seams.
13
+ //
14
+ // Packets go in length-prefixed: each one a 16-bit little-endian byte count
15
+ // followed by the packet. PCM comes out little-endian, interleaved, at the
16
+ // decoder's sample rate. Apple hosts decode with AudioToolbox; elsewhere
17
+ // supported() is false and decoders are never created (handle 0).
18
+ struct OpusFacade {
19
+ bool supported() const;
20
+ double createDecoder(double sampleRate, double channels) const;
21
+ std::vector<std::uint8_t> decode(double decoder, const std::vector<std::uint8_t> &packets) const;
22
+ void destroyDecoder(double decoder) const;
23
+ };
24
+
25
+ inline constexpr OpusFacade Opus{};
26
+
27
+ namespace opus_platform {
28
+ // Platform hooks; host/opus.cpp holds weak fallbacks.
29
+ bool supported();
30
+ int createDecoder(int sampleRate, int channels);
31
+ std::vector<std::uint8_t> decode(int decoder, const std::vector<std::uint8_t> &packets);
32
+ void destroyDecoder(int decoder);
33
+ } // namespace opus_platform
34
+
35
+ } // namespace gea::host
@@ -81,6 +81,8 @@ class WebSocket {
81
81
  double readyState() const;
82
82
  double bufferedAmount() const;
83
83
  void send(const std::string &data) const;
84
+ // Binary frame: a Uint8Array / ArrayBuffer argument lowers to the byte vector.
85
+ void send(const std::vector<std::uint8_t> &data) const;
84
86
  void close() const;
85
87
  void close(double code) const;
86
88
  void close(double code, const std::string &reason) const;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/host",
3
- "version": "0.1.27",
3
+ "version": "0.1.28",
4
4
  "description": "GeaStack host bindings and platform service sources.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {