@robotical/webapp-types 3.18.9 → 3.18.11

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.
@@ -9,6 +9,7 @@ import MartyAddonsManager from "./MartyAddonsManager";
9
9
  import CalibrationManager from "./CalibrationManager";
10
10
  import { RICNotificationsManager } from "./notifications-manager/RICNotificationsManager";
11
11
  import PublishedDataAnalyser from "./PublishedDataAnalyser";
12
+ import MartySoundStreamingStats, { MartySoundStreamingProfile } from "./MartySoundStreamingStats";
12
13
  export declare class Marty extends RAFT implements RICInterface {
13
14
  id: string;
14
15
  type: RaftTypeE;
@@ -19,11 +20,13 @@ export declare class Marty extends RAFT implements RICInterface {
19
20
  calibrationManager: CalibrationManager;
20
21
  ricNotificationManager: RICNotificationsManager;
21
22
  publishedDataAnalyser: PublishedDataAnalyser;
23
+ soundStreamingStats: MartySoundStreamingStats;
22
24
  _ledLcdColours: RICLedLcdColours;
23
25
  private rssiValues;
24
26
  private MAX_RSSI_VALUES_N;
25
27
  constructor(id: string);
26
28
  get ledLcdColours(): RICLedLcdColours;
29
+ getSoundStreamingProfile(): MartySoundStreamingProfile;
27
30
  /**
28
31
  * Gets the RSSI of the RAFT
29
32
  */
@@ -52,6 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  import { RaftTypeE } from "../../../types/raft";
53
53
  import RAFT from "../RAFT";
54
54
  import { RaftConnEvent, RaftPublishEvent } from "@robdobsn/raftjs";
55
+ import { RaftInfoEvents } from "../../../types/events/raft-info";
55
56
  import { MartyWifiManager } from "./MartyWifiManager";
56
57
  import MartyAddonsManager from "./MartyAddonsManager";
57
58
  import CalibrationManager from "./CalibrationManager";
@@ -59,6 +60,7 @@ import Logger from "../../../services/logger/Logger";
59
60
  import { AppSentMessage } from "../../../types/communication-between-apps/wrapper-communication";
60
61
  import { RICNotificationsManager } from "./notifications-manager/RICNotificationsManager";
61
62
  import PublishedDataAnalyser from "./PublishedDataAnalyser";
63
+ import MartySoundStreamingStats from "./MartySoundStreamingStats";
62
64
  var SHOW_LOGS = true;
63
65
  var TAG = "Marty";
64
66
  var Marty = /** @class */ (function (_super) {
@@ -80,6 +82,7 @@ var Marty = /** @class */ (function (_super) {
80
82
  _this.ricNotificationManager = new RICNotificationsManager(_this);
81
83
  // Published data analyser
82
84
  _this.publishedDataAnalyser = new PublishedDataAnalyser(_this);
85
+ _this.soundStreamingStats = new MartySoundStreamingStats();
83
86
  // Colours to use for LED patterns
84
87
  _this._ledLcdColours = [
85
88
  { led: "#202000", lcd: "#FFFF00" },
@@ -109,6 +112,9 @@ var Marty = /** @class */ (function (_super) {
109
112
  enumerable: false,
110
113
  configurable: true
111
114
  });
115
+ Marty.prototype.getSoundStreamingProfile = function () {
116
+ return this.soundStreamingStats.getCurrentProfile();
117
+ };
112
118
  /**
113
119
  * Gets the RSSI of the RAFT
114
120
  */
@@ -220,8 +226,9 @@ var Marty = /** @class */ (function (_super) {
220
226
  _a = eventEnum;
221
227
  switch (_a) {
222
228
  case RaftConnEvent.CONN_VERIFIED_CORRECT: return [3 /*break*/, 1];
229
+ case RaftConnEvent.CONN_STREAMING_ISSUE: return [3 /*break*/, 3];
223
230
  }
224
- return [3 /*break*/, 3];
231
+ return [3 /*break*/, 4];
225
232
  case 1: return [4 /*yield*/, this.sendAtomicReadOperation()];
226
233
  case 2:
227
234
  wasSent = _b.sent();
@@ -231,9 +238,12 @@ var Marty = /** @class */ (function (_super) {
231
238
  else {
232
239
  Logger.warn(SHOW_LOGS, TAG, "Warn! sending atomic read operation to Marty");
233
240
  }
234
- return [3 /*break*/, 4];
235
- case 3: return [3 /*break*/, 4];
236
- case 4: return [2 /*return*/];
241
+ return [3 /*break*/, 5];
242
+ case 3:
243
+ this.soundStreamingStats.increaseWarning();
244
+ return [3 /*break*/, 5];
245
+ case 4: return [3 /*break*/, 5];
246
+ case 5: return [2 /*return*/];
237
247
  }
238
248
  });
239
249
  });
@@ -261,6 +271,9 @@ var Marty = /** @class */ (function (_super) {
261
271
  return __awaiter(this, void 0, void 0, function () {
262
272
  return __generator(this, function (_a) {
263
273
  switch (eventEnum) {
274
+ case RaftInfoEvents.SYSTEM_INFO:
275
+ this.soundStreamingStats.configureSoundStreamingForRobot(data.systemInfo);
276
+ break;
264
277
  default:
265
278
  break;
266
279
  }
@@ -0,0 +1,16 @@
1
+ import { RaftSystemInfo } from "@robdobsn/raftjs";
2
+ export type MartySoundStreamingProfile = {
3
+ bitRate: number;
4
+ sampleRate: number;
5
+ avgFlag: boolean;
6
+ };
7
+ export default class MartySoundStreamingStats {
8
+ private readonly MAX_WARNINGS_PER_PROFILE;
9
+ private readonly RIC_VERSION_NEW_SOKTO_MODE;
10
+ private readonly soundStreamingProfiles;
11
+ private currentSoundStreamingProfileIndex;
12
+ getCurrentProfile(): MartySoundStreamingProfile;
13
+ increaseWarning(): void;
14
+ setBitRate(bitRate: number): boolean;
15
+ configureSoundStreamingForRobot(systemInfo: Pick<RaftSystemInfo, "SystemVersion"> | null): void;
16
+ }
@@ -0,0 +1,57 @@
1
+ import isVersionGreater from "../../../utils/helpers/compare-version";
2
+ var SoundStreamingProfile = /** @class */ (function () {
3
+ function SoundStreamingProfile(bitRate, sampleRate, avgFlag) {
4
+ this.bitRate = bitRate;
5
+ this.sampleRate = sampleRate;
6
+ this.avgFlag = avgFlag;
7
+ this.numWarnings = 0;
8
+ }
9
+ return SoundStreamingProfile;
10
+ }());
11
+ var MartySoundStreamingStats = /** @class */ (function () {
12
+ function MartySoundStreamingStats() {
13
+ this.MAX_WARNINGS_PER_PROFILE = 2;
14
+ this.RIC_VERSION_NEW_SOKTO_MODE = "1.2.52";
15
+ // Profiles must be listed in decreasing order by bitrate.
16
+ this.soundStreamingProfiles = [
17
+ new SoundStreamingProfile(64, 44100, true),
18
+ new SoundStreamingProfile(48, 32000, true),
19
+ new SoundStreamingProfile(32, 22050, true),
20
+ new SoundStreamingProfile(24, 16000, true),
21
+ new SoundStreamingProfile(16, 11025, true),
22
+ ];
23
+ this.currentSoundStreamingProfileIndex = 0;
24
+ }
25
+ MartySoundStreamingStats.prototype.getCurrentProfile = function () {
26
+ var profile = this.soundStreamingProfiles[this.currentSoundStreamingProfileIndex];
27
+ return {
28
+ bitRate: profile.bitRate,
29
+ sampleRate: profile.sampleRate,
30
+ avgFlag: profile.avgFlag,
31
+ };
32
+ };
33
+ MartySoundStreamingStats.prototype.increaseWarning = function () {
34
+ var profile = this.soundStreamingProfiles[this.currentSoundStreamingProfileIndex];
35
+ profile.numWarnings++;
36
+ if (profile.numWarnings > this.MAX_WARNINGS_PER_PROFILE &&
37
+ this.currentSoundStreamingProfileIndex < this.soundStreamingProfiles.length - 1) {
38
+ this.currentSoundStreamingProfileIndex++;
39
+ }
40
+ };
41
+ MartySoundStreamingStats.prototype.setBitRate = function (bitRate) {
42
+ var profileIndex = this.soundStreamingProfiles.findIndex(function (profile) { return profile.bitRate <= bitRate; });
43
+ if (profileIndex === -1) {
44
+ return false;
45
+ }
46
+ this.currentSoundStreamingProfileIndex = profileIndex;
47
+ return true;
48
+ };
49
+ MartySoundStreamingStats.prototype.configureSoundStreamingForRobot = function (systemInfo) {
50
+ if ((systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.SystemVersion) &&
51
+ isVersionGreater(this.RIC_VERSION_NEW_SOKTO_MODE, systemInfo.SystemVersion)) {
52
+ this.setBitRate(16);
53
+ }
54
+ };
55
+ return MartySoundStreamingStats;
56
+ }());
57
+ export default MartySoundStreamingStats;
@@ -11,5 +11,5 @@ export default class ConnectorFactory {
11
11
  *
12
12
  */
13
13
  static connectToRaftHelper(method: RaftConnectionMethod, uuids: string[], onConnManagerCreated?: (connManager: ConnManager) => void): Promise<Connector | null>;
14
- static createConnector(raftType: string | undefined, connManager: ConnManager): Connector;
14
+ static createConnector(raftType: string | undefined, connManager: ConnManager, connectionMethod: RaftConnectionMethod): Connector;
15
15
  }
@@ -76,7 +76,7 @@ var ConnectorFactory = /** @class */ (function () {
76
76
  }
77
77
  systemInfo = connManager.getConnector().getRaftSystemUtils().getCachedSystemInfo();
78
78
  raftType = systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.SystemName;
79
- connector = this.createConnector(raftType, connManager);
79
+ connector = this.createConnector(raftType, connManager, method);
80
80
  connectorWasCreated = true;
81
81
  return [2 /*return*/, connector];
82
82
  case 3:
@@ -106,14 +106,14 @@ var ConnectorFactory = /** @class */ (function () {
106
106
  });
107
107
  });
108
108
  };
109
- ConnectorFactory.createConnector = function (raftType, connManager) {
109
+ ConnectorFactory.createConnector = function (raftType, connManager, connectionMethod) {
110
110
  var systemInfo = connManager.getConnector().getRaftSystemUtils().getCachedSystemInfo();
111
111
  var serialNo = (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.MAC) || (systemInfo === null || systemInfo === void 0 ? void 0 : systemInfo.SerialNo);
112
112
  var connector;
113
113
  var randomId = serialNo || randomHashGenerator();
114
114
  switch (raftType) {
115
115
  case "RIC":
116
- connector = new MartyConnector(randomId, connManager);
116
+ connector = new MartyConnector(randomId, connManager, connectionMethod);
117
117
  break;
118
118
  case "Cog":
119
119
  connector = new CogConnector(randomId, connManager);
@@ -1,12 +1,12 @@
1
1
  import { RaftInfoEvents } from "../../../types/events/raft-info";
2
- import { ConnectionAttemptResults, RaftTypeE } from "../../../types/raft";
2
+ import { ConnectionAttemptResults, RaftConnectionMethod, RaftTypeE } from "../../../types/raft";
3
3
  import Connector from "../Connector";
4
4
  import ConnectorInterface from "../ConnectorInterface";
5
5
  import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent } from "@robdobsn/raftjs";
6
6
  import { ConnManager } from "@robotical/roboticaljs";
7
7
  declare class MartyConnector extends Connector implements ConnectorInterface {
8
8
  type: RaftTypeE;
9
- constructor(raftId: string, connManager: ConnManager);
9
+ constructor(raftId: string, connManager: ConnManager, connectionMethod: RaftConnectionMethod);
10
10
  /**
11
11
  * Publish an event to all observers
12
12
  * Set in RICConnector as an event listener callback
@@ -52,7 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
52
52
  import { RICRoboticalAddOns } from "@robotical/ricjs-robotical-addons";
53
53
  import { RaftInfoEvents } from "../../../types/events/raft-info";
54
54
  import Logger from "../../../services/logger/Logger";
55
- import { RaftTypeE } from "../../../types/raft";
55
+ import { RaftConnectionMethod, RaftTypeE } from "../../../types/raft";
56
56
  import Connector from "../Connector";
57
57
  import { RaftConnEvent, RaftUpdateEvent, RaftPublishEvent, } from "@robdobsn/raftjs";
58
58
  import { RICServoParamUpdater, RICSystemUtils, } from "@robotical/roboticaljs";
@@ -60,6 +60,7 @@ import { WrapperSentMessage } from "../../../types/communication-between-apps/wr
60
60
  var SHOW_LOGS = true;
61
61
  var TAG = "MartyConnector";
62
62
  var UNPLUGGED_MODE_CHECK_TIMEOUT_MS = 750;
63
+ var WEB_BLE_AUDIO_BLOCKS_WITHOUT_PAUSE = 0;
63
64
  var timeout = function (promise, timeoutMs) {
64
65
  var timeoutId;
65
66
  var timeoutPromise = new Promise(function (resolve) {
@@ -73,9 +74,14 @@ var timeout = function (promise, timeoutMs) {
73
74
  };
74
75
  var MartyConnector = /** @class */ (function (_super) {
75
76
  __extends(MartyConnector, _super);
76
- function MartyConnector(raftId, connManager) {
77
+ function MartyConnector(raftId, connManager, connectionMethod) {
77
78
  var _this = _super.call(this, raftId, connManager) || this;
78
79
  _this.type = RaftTypeE.MARTY;
80
+ if (connectionMethod === RaftConnectionMethod.WEB_BLE) {
81
+ var streamHandler = _this.connManager.getConnector().getStreamHandler();
82
+ // RaftJS chunks logical stream blocks to the safe Web Bluetooth write size.
83
+ streamHandler.setNumBlocksWithoutPause(WEB_BLE_AUDIO_BLOCKS_WITHOUT_PAUSE);
84
+ }
79
85
  return _this;
80
86
  }
81
87
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robotical/webapp-types",
3
- "version": "3.18.9",
3
+ "version": "3.18.11",
4
4
  "description": "Type definitions for the Application Manager",
5
5
  "main": "dist/application-manager.d.ts",
6
6
  "types": "dist/application-manager.d.ts",