@robdobsn/raftjs 1.7.1 → 1.7.3
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.
- package/dist/web/RaftAttributeHandler.js +5 -5
- package/dist/web/RaftAttributeHandler.js.map +1 -1
- package/dist/web/RaftChannel.d.ts +2 -0
- package/dist/web/RaftChannelBLE.web.d.ts +2 -0
- package/dist/web/RaftChannelBLE.web.js +10 -0
- package/dist/web/RaftChannelBLE.web.js.map +1 -1
- package/dist/{react-native/RaftChannelWebSocket.d.ts → web/RaftChannelSimulated.d.ts} +9 -5
- package/dist/web/RaftChannelSimulated.js +418 -0
- package/dist/web/RaftChannelSimulated.js.map +1 -0
- package/dist/web/RaftChannelWebSerial.d.ts +2 -0
- package/dist/web/RaftChannelWebSerial.js +10 -0
- package/dist/web/RaftChannelWebSerial.js.map +1 -1
- package/dist/web/RaftChannelWebSocket.d.ts +2 -0
- package/dist/web/RaftChannelWebSocket.js +10 -0
- package/dist/web/RaftChannelWebSocket.js.map +1 -1
- package/dist/web/RaftConnector.js +5 -0
- package/dist/web/RaftConnector.js.map +1 -1
- package/dist/web/RaftDeviceInfo.d.ts +1 -1
- package/dist/web/RaftMsgHandler.d.ts +5 -0
- package/dist/web/RaftMsgHandler.js +32 -0
- package/dist/web/RaftMsgHandler.js.map +1 -1
- package/dist/web/main.d.ts +1 -0
- package/dist/web/main.js +3 -1
- package/dist/web/main.js.map +1 -1
- package/package.json +5 -2
- package/.editorconfig +0 -14
- package/.gitattributes +0 -11
- package/.nvmrc +0 -1
- package/TODO.md +0 -1
- package/dist/react-native/RaftAttributeHandler.d.ts +0 -12
- package/dist/react-native/RaftAttributeHandler.js +0 -249
- package/dist/react-native/RaftAttributeHandler.js.map +0 -1
- package/dist/react-native/RaftChannel.d.ts +0 -18
- package/dist/react-native/RaftChannel.js +0 -12
- package/dist/react-native/RaftChannel.js.map +0 -1
- package/dist/react-native/RaftChannelBLE.native.d.ts +0 -93
- package/dist/react-native/RaftChannelBLE.native.js +0 -472
- package/dist/react-native/RaftChannelBLE.native.js.map +0 -1
- package/dist/react-native/RaftChannelBLE.web.d.ts +0 -38
- package/dist/react-native/RaftChannelBLE.web.js +0 -290
- package/dist/react-native/RaftChannelBLE.web.js.map +0 -1
- package/dist/react-native/RaftChannelBLEFactory.d.ts +0 -10
- package/dist/react-native/RaftChannelBLEFactory.js +0 -17
- package/dist/react-native/RaftChannelBLEFactory.js.map +0 -1
- package/dist/react-native/RaftChannelBLEScanner.native.d.ts +0 -18
- package/dist/react-native/RaftChannelBLEScanner.native.js +0 -138
- package/dist/react-native/RaftChannelBLEScanner.native.js.map +0 -1
- package/dist/react-native/RaftChannelWebSerial.d.ts +0 -37
- package/dist/react-native/RaftChannelWebSerial.js +0 -319
- package/dist/react-native/RaftChannelWebSerial.js.map +0 -1
- package/dist/react-native/RaftChannelWebSocket.js +0 -197
- package/dist/react-native/RaftChannelWebSocket.js.map +0 -1
- package/dist/react-native/RaftCommsStats.d.ts +0 -39
- package/dist/react-native/RaftCommsStats.js +0 -128
- package/dist/react-native/RaftCommsStats.js.map +0 -1
- package/dist/react-native/RaftConnEvents.d.ts +0 -39
- package/dist/react-native/RaftConnEvents.js +0 -54
- package/dist/react-native/RaftConnEvents.js.map +0 -1
- package/dist/react-native/RaftConnector.d.ts +0 -245
- package/dist/react-native/RaftConnector.js +0 -616
- package/dist/react-native/RaftConnector.js.map +0 -1
- package/dist/react-native/RaftCustomAttrHandler.d.ts +0 -4
- package/dist/react-native/RaftCustomAttrHandler.js +0 -50
- package/dist/react-native/RaftCustomAttrHandler.js.map +0 -1
- package/dist/react-native/RaftDeviceInfo.d.ts +0 -63
- package/dist/react-native/RaftDeviceInfo.js +0 -36
- package/dist/react-native/RaftDeviceInfo.js.map +0 -1
- package/dist/react-native/RaftDeviceManager.d.ts +0 -40
- package/dist/react-native/RaftDeviceManager.js +0 -499
- package/dist/react-native/RaftDeviceManager.js.map +0 -1
- package/dist/react-native/RaftDeviceMgrIF.d.ts +0 -15
- package/dist/react-native/RaftDeviceMgrIF.js +0 -11
- package/dist/react-native/RaftDeviceMgrIF.js.map +0 -1
- package/dist/react-native/RaftDeviceMsg.d.ts +0 -9
- package/dist/react-native/RaftDeviceMsg.js +0 -11
- package/dist/react-native/RaftDeviceMsg.js.map +0 -1
- package/dist/react-native/RaftDeviceStates.d.ts +0 -37
- package/dist/react-native/RaftDeviceStates.js +0 -60
- package/dist/react-native/RaftDeviceStates.js.map +0 -1
- package/dist/react-native/RaftFileHandler.d.ts +0 -52
- package/dist/react-native/RaftFileHandler.js +0 -502
- package/dist/react-native/RaftFileHandler.js.map +0 -1
- package/dist/react-native/RaftLog.d.ts +0 -22
- package/dist/react-native/RaftLog.js +0 -63
- package/dist/react-native/RaftLog.js.map +0 -1
- package/dist/react-native/RaftMiniHDLC.d.ts +0 -18
- package/dist/react-native/RaftMiniHDLC.js +0 -383
- package/dist/react-native/RaftMiniHDLC.js.map +0 -1
- package/dist/react-native/RaftMsgHandler.d.ts +0 -57
- package/dist/react-native/RaftMsgHandler.js +0 -479
- package/dist/react-native/RaftMsgHandler.js.map +0 -1
- package/dist/react-native/RaftMsgTrackInfo.d.ts +0 -17
- package/dist/react-native/RaftMsgTrackInfo.js +0 -42
- package/dist/react-native/RaftMsgTrackInfo.js.map +0 -1
- package/dist/react-native/RaftProtocolDefs.d.ts +0 -30
- package/dist/react-native/RaftProtocolDefs.js +0 -48
- package/dist/react-native/RaftProtocolDefs.js.map +0 -1
- package/dist/react-native/RaftStreamHandler.d.ts +0 -38
- package/dist/react-native/RaftStreamHandler.js +0 -257
- package/dist/react-native/RaftStreamHandler.js.map +0 -1
- package/dist/react-native/RaftStruct.d.ts +0 -3
- package/dist/react-native/RaftStruct.js +0 -208
- package/dist/react-native/RaftStruct.js.map +0 -1
- package/dist/react-native/RaftSysTypeManager.d.ts +0 -14
- package/dist/react-native/RaftSysTypeManager.js +0 -53
- package/dist/react-native/RaftSysTypeManager.js.map +0 -1
- package/dist/react-native/RaftSystemType.d.ts +0 -28
- package/dist/react-native/RaftSystemType.js +0 -3
- package/dist/react-native/RaftSystemType.js.map +0 -1
- package/dist/react-native/RaftSystemUtils.d.ts +0 -136
- package/dist/react-native/RaftSystemUtils.js +0 -410
- package/dist/react-native/RaftSystemUtils.js.map +0 -1
- package/dist/react-native/RaftTypes.d.ts +0 -194
- package/dist/react-native/RaftTypes.js +0 -153
- package/dist/react-native/RaftTypes.js.map +0 -1
- package/dist/react-native/RaftUpdateEvents.d.ts +0 -33
- package/dist/react-native/RaftUpdateEvents.js +0 -46
- package/dist/react-native/RaftUpdateEvents.js.map +0 -1
- package/dist/react-native/RaftUpdateManager.d.ts +0 -61
- package/dist/react-native/RaftUpdateManager.js +0 -621
- package/dist/react-native/RaftUpdateManager.js.map +0 -1
- package/dist/react-native/RaftUtils.d.ts +0 -126
- package/dist/react-native/RaftUtils.js +0 -467
- package/dist/react-native/RaftUtils.js.map +0 -1
- package/dist/react-native/RaftWifiTypes.d.ts +0 -23
- package/dist/react-native/RaftWifiTypes.js +0 -43
- package/dist/react-native/RaftWifiTypes.js.map +0 -1
- package/dist/react-native/main.d.ts +0 -24
- package/dist/react-native/main.js +0 -49
- package/dist/react-native/main.js.map +0 -1
- package/eslint.config.mjs +0 -33
- package/examples/dashboard/package.json +0 -36
- package/examples/dashboard/src/CommandPanel.tsx +0 -147
- package/examples/dashboard/src/ConnManager.ts +0 -164
- package/examples/dashboard/src/DeviceActionsForm.tsx +0 -133
- package/examples/dashboard/src/DeviceAttrsForm.tsx +0 -49
- package/examples/dashboard/src/DeviceLineChart.tsx +0 -163
- package/examples/dashboard/src/DevicePanel.tsx +0 -166
- package/examples/dashboard/src/DevicesPanel.tsx +0 -58
- package/examples/dashboard/src/DispLedGrid.tsx +0 -110
- package/examples/dashboard/src/DispOneLed.tsx +0 -20
- package/examples/dashboard/src/LatencyTest.ts +0 -130
- package/examples/dashboard/src/LatencyTestPanel.tsx +0 -92
- package/examples/dashboard/src/Main.tsx +0 -234
- package/examples/dashboard/src/SettingsManager.ts +0 -67
- package/examples/dashboard/src/SettingsScreen.tsx +0 -174
- package/examples/dashboard/src/StatusPanel.tsx +0 -71
- package/examples/dashboard/src/SystemTypeCog/CogStateInfo.ts +0 -163
- package/examples/dashboard/src/SystemTypeCog/SystemTypeCog.ts +0 -91
- package/examples/dashboard/src/SystemTypeGeneric/StateInfoGeneric.ts +0 -30
- package/examples/dashboard/src/SystemTypeGeneric/SystemTypeGeneric.ts +0 -91
- package/examples/dashboard/src/SystemTypeMarty/RICAddOn.ts +0 -70
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnBase.ts +0 -33
- package/examples/dashboard/src/SystemTypeMarty/RICAddOnManager.ts +0 -342
- package/examples/dashboard/src/SystemTypeMarty/RICCommsStats.ts +0 -170
- package/examples/dashboard/src/SystemTypeMarty/RICHWElem.ts +0 -123
- package/examples/dashboard/src/SystemTypeMarty/RICLEDPatternChecker.ts +0 -207
- package/examples/dashboard/src/SystemTypeMarty/RICROSSerial.ts +0 -464
- package/examples/dashboard/src/SystemTypeMarty/RICServoFaultDetector.ts +0 -146
- package/examples/dashboard/src/SystemTypeMarty/RICStateInfo.ts +0 -97
- package/examples/dashboard/src/SystemTypeMarty/RICSystemUtils.ts +0 -371
- package/examples/dashboard/src/SystemTypeMarty/RICTypes.ts +0 -20
- package/examples/dashboard/src/SystemTypeMarty/SystemTypeMarty.ts +0 -119
- package/examples/dashboard/src/index.html +0 -15
- package/examples/dashboard/src/index.tsx +0 -13
- package/examples/dashboard/src/styles.css +0 -408
- package/examples/dashboard/tsconfig.json +0 -18
- package/jest.config.js +0 -11
- package/src/RaftAttributeHandler.ts +0 -298
- package/src/RaftChannel.ts +0 -30
- package/src/RaftChannelBLE.native.ts +0 -604
- package/src/RaftChannelBLE.web.ts +0 -359
- package/src/RaftChannelBLEFactory.ts +0 -13
- package/src/RaftChannelBLEScanner.native.ts +0 -184
- package/src/RaftChannelWebSerial.ts +0 -408
- package/src/RaftChannelWebSocket.ts +0 -245
- package/src/RaftCommsStats.ts +0 -142
- package/src/RaftConnEvents.ts +0 -58
- package/src/RaftConnector.ts +0 -739
- package/src/RaftCustomAttrHandler.ts +0 -54
- package/src/RaftDeviceInfo.ts +0 -102
- package/src/RaftDeviceManager.ts +0 -607
- package/src/RaftDeviceMgrIF.ts +0 -33
- package/src/RaftDeviceMsg.ts +0 -20
- package/src/RaftDeviceStates.ts +0 -92
- package/src/RaftFileHandler.ts +0 -668
- package/src/RaftLog.ts +0 -70
- package/src/RaftMiniHDLC.ts +0 -396
- package/src/RaftMsgHandler.ts +0 -777
- package/src/RaftMsgTrackInfo.ts +0 -51
- package/src/RaftProtocolDefs.ts +0 -46
- package/src/RaftStreamHandler.ts +0 -328
- package/src/RaftStruct.ts +0 -209
- package/src/RaftSysTypeManager.ts +0 -60
- package/src/RaftSystemType.ts +0 -32
- package/src/RaftSystemUtils.ts +0 -487
- package/src/RaftTypes.ts +0 -278
- package/src/RaftUpdateEvents.ts +0 -48
- package/src/RaftUpdateManager.ts +0 -781
- package/src/RaftUtils.ts +0 -494
- package/src/RaftWifiTypes.ts +0 -36
- package/src/main.ts +0 -37
- package/testdata/TestDeviceTypeRecs.json +0 -492
- package/tsconfig.json +0 -30
- package/tsconfig.react-native.json +0 -29
package/src/RaftMsgTrackInfo.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
//
|
|
3
|
-
// RaftMsgTrackInfo
|
|
4
|
-
// Part of RaftJS
|
|
5
|
-
//
|
|
6
|
-
// Rob Dobson & Chris Greening 2020-2024
|
|
7
|
-
// (C) 2020-2024 All rights reserved
|
|
8
|
-
//
|
|
9
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
10
|
-
|
|
11
|
-
export class RaftMsgTrackInfo {
|
|
12
|
-
static readonly MAX_MSG_NUM = 255;
|
|
13
|
-
static readonly MSG_RESPONSE_TIMEOUT_MS = 2000;
|
|
14
|
-
static readonly MSG_RETRY_COUNT = 5;
|
|
15
|
-
msgOutstanding = false;
|
|
16
|
-
msgFrame: Uint8Array = new Uint8Array();
|
|
17
|
-
msgSentMs = 0;
|
|
18
|
-
retryCount = 0;
|
|
19
|
-
withResponse = false;
|
|
20
|
-
bridgeID: number | undefined = undefined;
|
|
21
|
-
msgHandle = 0;
|
|
22
|
-
msgTimeoutMs: number | undefined = undefined;
|
|
23
|
-
resolve: unknown;
|
|
24
|
-
reject: unknown;
|
|
25
|
-
|
|
26
|
-
constructor() {
|
|
27
|
-
this.msgOutstanding = false;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
set(
|
|
31
|
-
msgOutstanding: boolean,
|
|
32
|
-
msgFrame: Uint8Array,
|
|
33
|
-
withResponse: boolean,
|
|
34
|
-
bridgeID: number | undefined = undefined,
|
|
35
|
-
msgHandle: number,
|
|
36
|
-
msgTimeoutMs: number | undefined,
|
|
37
|
-
resolve: unknown,
|
|
38
|
-
reject: unknown,
|
|
39
|
-
) {
|
|
40
|
-
this.msgOutstanding = msgOutstanding;
|
|
41
|
-
this.msgFrame = msgFrame;
|
|
42
|
-
this.retryCount = 0;
|
|
43
|
-
this.msgSentMs = Date.now();
|
|
44
|
-
this.withResponse = withResponse;
|
|
45
|
-
this.bridgeID = bridgeID;
|
|
46
|
-
this.msgHandle = msgHandle;
|
|
47
|
-
this.msgTimeoutMs = msgTimeoutMs;
|
|
48
|
-
this.resolve = resolve;
|
|
49
|
-
this.reject = reject;
|
|
50
|
-
}
|
|
51
|
-
}
|
package/src/RaftProtocolDefs.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
//
|
|
3
|
-
// Raft Protocol Definitions
|
|
4
|
-
// Part of RaftJS
|
|
5
|
-
//
|
|
6
|
-
// Rob Dobson & Chris Greening 2020-2024
|
|
7
|
-
// (C) 2020-2024 All rights reserved
|
|
8
|
-
//
|
|
9
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
10
|
-
|
|
11
|
-
// RIC Protocols
|
|
12
|
-
export const RICSERIAL_MSG_NUM_POS = 0;
|
|
13
|
-
export const RICSERIAL_PROTOCOL_POS = 1;
|
|
14
|
-
export const RICSERIAL_PAYLOAD_POS = 2;
|
|
15
|
-
export const RICREST_REST_ELEM_CODE_POS = 0;
|
|
16
|
-
export const RICREST_HEADER_PAYLOAD_POS = 1;
|
|
17
|
-
export const RICREST_FILEBLOCK_CHANNEL_POS = 0;
|
|
18
|
-
export const RICREST_FILEBLOCK_FILEPOS_POS = 0;
|
|
19
|
-
export const RICREST_FILEBLOCK_FILEPOS_POS_BYTES = 4;
|
|
20
|
-
export const RICREST_FILEBLOCK_PAYLOAD_POS = 4;
|
|
21
|
-
export const RICREST_BRIDGE_ID_POS = 2;
|
|
22
|
-
export const RICREST_BRIDGE_PAYLOAD_POS = 3;
|
|
23
|
-
|
|
24
|
-
// Protocol enums
|
|
25
|
-
export enum RICRESTElemCode {
|
|
26
|
-
RICREST_ELEM_CODE_URL,
|
|
27
|
-
RICREST_ELEM_CODE_CMDRESPJSON,
|
|
28
|
-
RICREST_ELEM_CODE_BODY,
|
|
29
|
-
RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
30
|
-
RICREST_ELEM_CODE_FILEBLOCK,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export enum RaftCommsMsgTypeCode {
|
|
34
|
-
MSG_TYPE_COMMAND,
|
|
35
|
-
MSG_TYPE_RESPONSE,
|
|
36
|
-
MSG_TYPE_PUBLISH,
|
|
37
|
-
MSG_TYPE_REPORT,
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export enum RaftCommsMsgProtocol {
|
|
41
|
-
MSG_PROTOCOL_ROSSERIAL = 0,
|
|
42
|
-
MSG_PROTOCOL_RESERVED_1 = 1,
|
|
43
|
-
MSG_PROTOCOL_RICREST = 2,
|
|
44
|
-
MSG_PROTOCOL_BRIDGE_RICREST = 3,
|
|
45
|
-
}
|
|
46
|
-
|
package/src/RaftStreamHandler.ts
DELETED
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
//
|
|
3
|
-
// RafStreamHandler
|
|
4
|
-
// Part of RaftJS
|
|
5
|
-
//
|
|
6
|
-
// Rob Dobson & Chris Greening 2020-2024
|
|
7
|
-
// (C) 2020-2024 All rights reserved
|
|
8
|
-
//
|
|
9
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
10
|
-
|
|
11
|
-
import RaftLog from './RaftLog'
|
|
12
|
-
import RaftMsgHandler from './RaftMsgHandler';
|
|
13
|
-
import RaftCommsStats from './RaftCommsStats';
|
|
14
|
-
import { RaftOKFail, RaftStreamStartResp, RaftStreamType } from './RaftTypes';
|
|
15
|
-
import RaftConnector from './RaftConnector';
|
|
16
|
-
import { RaftConnEvent } from './RaftConnEvents';
|
|
17
|
-
import { RICRESTElemCode } from './RaftProtocolDefs'
|
|
18
|
-
|
|
19
|
-
export default class RaftStreamHandler {
|
|
20
|
-
|
|
21
|
-
// Queue of audio stream requests
|
|
22
|
-
/*
|
|
23
|
-
private _streamAudioQueue: {
|
|
24
|
-
streamContents: Uint8Array;
|
|
25
|
-
audioDuration: number;
|
|
26
|
-
}[] = [];
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
// Stream state
|
|
30
|
-
private _streamID: number | null = null;
|
|
31
|
-
DEFAULT_MAX_BLOCK_SIZE = 475;
|
|
32
|
-
private _maxBlockSize: number = this.DEFAULT_MAX_BLOCK_SIZE;
|
|
33
|
-
|
|
34
|
-
// Handler of messages
|
|
35
|
-
private _msgHandler: RaftMsgHandler;
|
|
36
|
-
|
|
37
|
-
// RaftCommsStats
|
|
38
|
-
private _commsStats: RaftCommsStats;
|
|
39
|
-
|
|
40
|
-
// RaftConnector
|
|
41
|
-
private _raftConnector: RaftConnector;
|
|
42
|
-
|
|
43
|
-
// Flow control
|
|
44
|
-
private _soktoReceived = false;
|
|
45
|
-
private _soktoPos = 0;
|
|
46
|
-
|
|
47
|
-
private _streamIsStarting = false;
|
|
48
|
-
private _lastStreamStartTime = 0;
|
|
49
|
-
|
|
50
|
-
private _isStreaming = false;
|
|
51
|
-
private _isPaused = false;
|
|
52
|
-
private _streamBuffer = new Uint8Array();
|
|
53
|
-
private _audioDuration = 0;
|
|
54
|
-
private _audioByteRate = 0;
|
|
55
|
-
private _streamPos = 0;
|
|
56
|
-
private _numBlocksWithoutPause = 15;
|
|
57
|
-
private _legacySoktoMode = false;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// soundFinishPoint timer
|
|
61
|
-
private soundFinishPoint: NodeJS.Timeout | null = null;
|
|
62
|
-
|
|
63
|
-
constructor(msgHandler: RaftMsgHandler, commsStats: RaftCommsStats, raftConnector: RaftConnector) {
|
|
64
|
-
this._raftConnector = raftConnector;
|
|
65
|
-
this._msgHandler = msgHandler;
|
|
66
|
-
this._commsStats = commsStats;
|
|
67
|
-
this.onSoktoMsg = this.onSoktoMsg.bind(this);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
setNumBlocksWithoutPause(numBlocks: number){
|
|
71
|
-
this._numBlocksWithoutPause = numBlocks;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
setLegacySoktoMode(legacyMode: boolean){
|
|
75
|
-
RaftLog.debug(`Setting legacy sokto mode to ${legacyMode}`);
|
|
76
|
-
this._legacySoktoMode = legacyMode;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Start streaming audio
|
|
80
|
-
streamAudio(streamContents: Uint8Array, clearExisting: boolean, audioDuration: number): void {
|
|
81
|
-
if (!clearExisting)
|
|
82
|
-
RaftLog.debug(`only clearExisting = true is supported right now.`);
|
|
83
|
-
|
|
84
|
-
// TODO - if clearExisting is not set, form a queue
|
|
85
|
-
if (this._streamIsStarting || this._lastStreamStartTime > (Date.now() - 500)) {
|
|
86
|
-
RaftLog.error(`Unable to start sound, too soon since last request`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
this._isPaused = true;
|
|
91
|
-
this._streamIsStarting = true;
|
|
92
|
-
this._lastStreamStartTime = Date.now();
|
|
93
|
-
|
|
94
|
-
this._soktoReceived = false;
|
|
95
|
-
this._soktoPos = 0;
|
|
96
|
-
this._streamPos = 0;
|
|
97
|
-
this._streamBuffer = streamContents;
|
|
98
|
-
this._audioDuration = audioDuration;
|
|
99
|
-
this._audioByteRate = (streamContents.length / audioDuration)*1000;
|
|
100
|
-
|
|
101
|
-
this.clearFinishPointTimeout();
|
|
102
|
-
|
|
103
|
-
this._sendStreamStartMsg("audio.mp3", "streamaudio", RaftStreamType.REAL_TIME_STREAM, streamContents).then(
|
|
104
|
-
(result: boolean) => {
|
|
105
|
-
this._isPaused = false;
|
|
106
|
-
this._streamIsStarting = false;
|
|
107
|
-
if (!result){
|
|
108
|
-
RaftLog.error(`Unable to start stream. ufStart message send failed`);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
//this.streamingPerformanceChecker();
|
|
112
|
-
if (!this._isStreaming){
|
|
113
|
-
this._isStreaming = true;
|
|
114
|
-
this._sendStreamBuffer();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
async streamCancel(): Promise<void> {
|
|
122
|
-
this._streamBuffer = new Uint8Array();
|
|
123
|
-
this.clearFinishPointTimeout();
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
public isStreamStarting() {
|
|
127
|
-
return this._streamIsStarting;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
clearFinishPointTimeout() {
|
|
132
|
-
if (this.soundFinishPoint) {
|
|
133
|
-
clearTimeout(this.soundFinishPoint);
|
|
134
|
-
this.soundFinishPoint = null;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
streamingPerformanceChecker() {
|
|
139
|
-
if (this._audioDuration) {
|
|
140
|
-
this.clearFinishPointTimeout();
|
|
141
|
-
this.soundFinishPoint = setTimeout(() => {
|
|
142
|
-
// if the streaming hasn't finished before the end of the audio
|
|
143
|
-
// we can assume we are having streaming issues
|
|
144
|
-
|
|
145
|
-
// publish event in case we are having issues
|
|
146
|
-
this._raftConnector.onConnEvent(RaftConnEvent.CONN_STREAMING_ISSUE);
|
|
147
|
-
|
|
148
|
-
this.clearFinishPointTimeout();
|
|
149
|
-
}, this._audioDuration + 500);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Send the start message
|
|
154
|
-
private async _sendStreamStartMsg(
|
|
155
|
-
streamName: string,
|
|
156
|
-
targetEndpoint: string,
|
|
157
|
-
streamTypeEnum: RaftStreamType,
|
|
158
|
-
streamContents: Uint8Array,
|
|
159
|
-
): Promise<boolean> {
|
|
160
|
-
// Stream start command message
|
|
161
|
-
const streamType = 'rtstream';
|
|
162
|
-
const cmdMsg = `{"cmdName":"ufStart","reqStr":"ufStart","fileType":"${streamType}","fileName":"${streamName}","endpoint":"${targetEndpoint}","fileLen":${streamContents.length}}`;
|
|
163
|
-
|
|
164
|
-
// Debug
|
|
165
|
-
RaftLog.debug(`sendStreamStartMsg ${cmdMsg}`);
|
|
166
|
-
|
|
167
|
-
// Send
|
|
168
|
-
let streamStartResp = null;
|
|
169
|
-
try {
|
|
170
|
-
streamStartResp = await this._msgHandler.sendRICREST<RaftStreamStartResp>(
|
|
171
|
-
cmdMsg,
|
|
172
|
-
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
173
|
-
);
|
|
174
|
-
} catch (err) {
|
|
175
|
-
RaftLog.error(`sendStreamStartMsg error ${err}`);
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// Extract params
|
|
180
|
-
if (streamStartResp && (streamStartResp.rslt === 'ok')) {
|
|
181
|
-
this._streamID = streamStartResp.streamID;
|
|
182
|
-
this._maxBlockSize = streamStartResp.maxBlockSize || this.DEFAULT_MAX_BLOCK_SIZE;
|
|
183
|
-
this.streamingPerformanceChecker();
|
|
184
|
-
RaftLog.verbose(
|
|
185
|
-
`sendStreamStartMsg streamID ${this._streamID} maxBlockSize ${this._maxBlockSize} streamType ${streamTypeEnum}`,
|
|
186
|
-
);
|
|
187
|
-
} else {
|
|
188
|
-
RaftLog.warn(`sendStreamStartMsg failed ${streamStartResp ? streamStartResp.rslt : 'no response'}`);
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
get maxBlockSize () {
|
|
195
|
-
return this._maxBlockSize;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
set maxBlockSize (maxBlockSize: number) {
|
|
199
|
-
this._maxBlockSize = maxBlockSize;
|
|
200
|
-
this.DEFAULT_MAX_BLOCK_SIZE = maxBlockSize;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
private async _sendStreamEndMsg(
|
|
204
|
-
streamID: number | null,
|
|
205
|
-
): Promise<boolean> {
|
|
206
|
-
if (streamID === null) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
// Stram end command message
|
|
210
|
-
const cmdMsg = `{"cmdName":"ufEnd","reqStr":"ufEnd","streamID":${streamID}}`;
|
|
211
|
-
|
|
212
|
-
// Debug
|
|
213
|
-
RaftLog.debug(`sendStreamEndMsg ${cmdMsg}`);
|
|
214
|
-
|
|
215
|
-
// Send
|
|
216
|
-
let streamEndResp = null;
|
|
217
|
-
try {
|
|
218
|
-
streamEndResp = await this._msgHandler.sendRICREST<RaftOKFail>(
|
|
219
|
-
cmdMsg,
|
|
220
|
-
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
221
|
-
);
|
|
222
|
-
} catch (err) {
|
|
223
|
-
RaftLog.error(`sendStreamEndMsg error ${err}`);
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
return streamEndResp.rslt === 'ok';
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/*
|
|
230
|
-
private async _sendAudioStopMsg(): Promise<RaftOKFail> {
|
|
231
|
-
const cmdMsg = `{"cmdName":"audio/stop"}`;
|
|
232
|
-
|
|
233
|
-
// Debug
|
|
234
|
-
RaftLog.debug(`sendAudioStopMsg ${cmdMsg}`);
|
|
235
|
-
|
|
236
|
-
// Send
|
|
237
|
-
return this._msgHandler.sendRICREST<RaftOKFail>(
|
|
238
|
-
cmdMsg,
|
|
239
|
-
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
private async _sendStreamCancelMsg(): Promise<RaftOKFail> {
|
|
245
|
-
// File cancel command message
|
|
246
|
-
const cmdMsg = `{"cmdName":"ufCancel","reqStr":"ufCancel","streamID":${this._streamID}}`;
|
|
247
|
-
|
|
248
|
-
// Debug
|
|
249
|
-
RaftLog.debug(`sendStreamCancelMsg ${cmdMsg}`);
|
|
250
|
-
|
|
251
|
-
// Send
|
|
252
|
-
return this._msgHandler.sendRICREST<RaftOKFail>(
|
|
253
|
-
cmdMsg,
|
|
254
|
-
RICRESTElemCode.RICREST_ELEM_CODE_COMMAND_FRAME,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
*/
|
|
258
|
-
|
|
259
|
-
private async _sendStreamBuffer(): Promise<boolean> {
|
|
260
|
-
const streamStartTime = Date.now();
|
|
261
|
-
|
|
262
|
-
// Check streamID is valid
|
|
263
|
-
if (this._streamID === null) {
|
|
264
|
-
return false;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
let blockNum = 0;
|
|
268
|
-
// Send stream blocks
|
|
269
|
-
while (this._soktoPos < this._streamBuffer.length || this._isPaused) {
|
|
270
|
-
if (this._isPaused){
|
|
271
|
-
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// Check for new sokto
|
|
276
|
-
if (this._soktoReceived) {
|
|
277
|
-
if (this._legacySoktoMode)
|
|
278
|
-
this._streamPos = this._soktoPos;
|
|
279
|
-
// apart from when in legacy mode, the sokto message is now informational only,
|
|
280
|
-
// to allow the central to slow down sending of data if it is swamping the peripheral
|
|
281
|
-
RaftLog.verbose(`sendStreamContents ${Date.now() - streamStartTime}ms soktoReceived for ${this._streamPos}`);
|
|
282
|
-
this._soktoReceived = false;
|
|
283
|
-
|
|
284
|
-
// receiving an sokto message before the completion of the stream means that the streaming is not keeping up
|
|
285
|
-
this._raftConnector.onConnEvent(RaftConnEvent.CONN_STREAMING_ISSUE);
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// Send stream block
|
|
289
|
-
const blockSize = Math.min(this._streamBuffer.length - this._streamPos, this._maxBlockSize);
|
|
290
|
-
const block = this._streamBuffer.slice(this._streamPos, this._streamPos + blockSize);
|
|
291
|
-
if (block.length > 0) {
|
|
292
|
-
const sentOk = await this._msgHandler.sendStreamBlock(block, this._streamPos, this._streamID);
|
|
293
|
-
this._commsStats.recordStreamBytes(block.length);
|
|
294
|
-
|
|
295
|
-
RaftLog.verbose(
|
|
296
|
-
`sendStreamContents ${sentOk ? "OK" : "FAILED"} ${Date.now() - streamStartTime}ms pos ${this._streamPos} ${blockSize} ${block.length} ${this._soktoPos}`,
|
|
297
|
-
);
|
|
298
|
-
if (!sentOk) {
|
|
299
|
-
return false;
|
|
300
|
-
}
|
|
301
|
-
this._streamPos += blockSize;
|
|
302
|
-
blockNum += 1;
|
|
303
|
-
|
|
304
|
-
if (this._audioByteRate && blockNum > this._numBlocksWithoutPause){
|
|
305
|
-
const pauseTime = ((blockSize / this._audioByteRate)*1000) - 10;
|
|
306
|
-
RaftLog.verbose(`Pausing for ${pauseTime} ms between audio packets. Bit rate ${this._audioByteRate * 8}`)
|
|
307
|
-
await new Promise((resolve) => setTimeout(resolve, pauseTime));
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Wait to ensure we don't hog the CPU
|
|
312
|
-
await new Promise((resolve) => setTimeout(resolve, 1));
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
this._isStreaming = false;
|
|
316
|
-
this.clearFinishPointTimeout();
|
|
317
|
-
await this._sendStreamEndMsg(this._streamID);
|
|
318
|
-
|
|
319
|
-
return true;
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
onSoktoMsg(soktoPos: number) {
|
|
323
|
-
// Get how far we've progressed in file
|
|
324
|
-
this._soktoPos = soktoPos;
|
|
325
|
-
this._soktoReceived = true;
|
|
326
|
-
RaftLog.debug(`onSoktoMsg received file up to ${this._soktoPos}`);
|
|
327
|
-
}
|
|
328
|
-
}
|
package/src/RaftStruct.ts
DELETED
|
@@ -1,209 +0,0 @@
|
|
|
1
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
//
|
|
3
|
-
// RaftStruct
|
|
4
|
-
// Part of RaftJS
|
|
5
|
-
//
|
|
6
|
-
// Rob Dobson 2024
|
|
7
|
-
// (C) 2024 All rights reserved
|
|
8
|
-
//
|
|
9
|
-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
10
|
-
|
|
11
|
-
export function structUnpack(format: string, data: Uint8Array): number[] {
|
|
12
|
-
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
13
|
-
const results: number[] = [];
|
|
14
|
-
let offset = 0;
|
|
15
|
-
let littleEndian = false;
|
|
16
|
-
|
|
17
|
-
for (const char of format) {
|
|
18
|
-
switch (char) {
|
|
19
|
-
case "<":
|
|
20
|
-
littleEndian = true;
|
|
21
|
-
break;
|
|
22
|
-
case ">":
|
|
23
|
-
littleEndian = false;
|
|
24
|
-
break;
|
|
25
|
-
case "x": // Padding byte
|
|
26
|
-
offset += 1;
|
|
27
|
-
break;
|
|
28
|
-
case "c": // Char
|
|
29
|
-
results.push(view.getUint8(offset));
|
|
30
|
-
offset += 1;
|
|
31
|
-
break;
|
|
32
|
-
case "b": // Signed 8-bit integer
|
|
33
|
-
results.push(view.getInt8(offset));
|
|
34
|
-
offset += 1;
|
|
35
|
-
break;
|
|
36
|
-
case "B": // Unsigned 8-bit integer
|
|
37
|
-
results.push(view.getUint8(offset));
|
|
38
|
-
offset += 1;
|
|
39
|
-
break;
|
|
40
|
-
case "h": // Signed 16-bit integer
|
|
41
|
-
results.push(view.getInt16(offset, littleEndian));
|
|
42
|
-
offset += 2;
|
|
43
|
-
break;
|
|
44
|
-
case "H": // Unsigned 16-bit integer (big-endian)
|
|
45
|
-
results.push(view.getUint16(offset, littleEndian));
|
|
46
|
-
offset += 2;
|
|
47
|
-
break;
|
|
48
|
-
case "i": // Signed 32-bit integer (big-endian)
|
|
49
|
-
results.push(view.getInt32(offset, littleEndian));
|
|
50
|
-
offset += 4;
|
|
51
|
-
break;
|
|
52
|
-
case "I": // Unsigned 32-bit integer (big-endian)
|
|
53
|
-
results.push(view.getUint32(offset, littleEndian));
|
|
54
|
-
offset += 4;
|
|
55
|
-
break;
|
|
56
|
-
case "l": // Signed 32-bit integer (big-endian)
|
|
57
|
-
results.push(view.getInt32(offset, littleEndian));
|
|
58
|
-
offset += 4;
|
|
59
|
-
break;
|
|
60
|
-
case "L": // Unsigned 32-bit integer (big-endian)
|
|
61
|
-
results.push(view.getUint32(offset, littleEndian));
|
|
62
|
-
offset += 4;
|
|
63
|
-
break;
|
|
64
|
-
// case "q": // Signed 64-bit integer (big-endian)
|
|
65
|
-
// results.push(view.getBigInt64(offset, littleEndian));
|
|
66
|
-
// offset += 8;
|
|
67
|
-
// break;
|
|
68
|
-
// case "Q": // Unsigned 64-bit integer (big-endian)
|
|
69
|
-
// results.push(view.getBigUint64(offset, littleEndian));
|
|
70
|
-
// offset += 8;
|
|
71
|
-
// break;
|
|
72
|
-
case "f": // 32-bit float (big-endian)
|
|
73
|
-
results.push(view.getFloat32(offset, littleEndian));
|
|
74
|
-
offset += 4;
|
|
75
|
-
break;
|
|
76
|
-
case "d": // 64-bit float (big-endian)
|
|
77
|
-
results.push(view.getFloat64(offset, littleEndian));
|
|
78
|
-
offset += 8;
|
|
79
|
-
break;
|
|
80
|
-
default:
|
|
81
|
-
throw new Error(`Unknown format character: ${char}`);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return results;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export function structSizeOf(format: string): number {
|
|
89
|
-
let size = 0;
|
|
90
|
-
for (const char of format) {
|
|
91
|
-
switch (char) {
|
|
92
|
-
case "<":
|
|
93
|
-
case ">":
|
|
94
|
-
break;
|
|
95
|
-
case "x": // Padding byte
|
|
96
|
-
size += 1;
|
|
97
|
-
break;
|
|
98
|
-
case "c": // Char
|
|
99
|
-
case "b": // Signed 8-bit integer
|
|
100
|
-
case "B": // Unsigned 8-bit integer
|
|
101
|
-
size += 1;
|
|
102
|
-
break;
|
|
103
|
-
case "h": // Signed 16-bit integer
|
|
104
|
-
case "H": // Unsigned 16-bit integer
|
|
105
|
-
size += 2;
|
|
106
|
-
break;
|
|
107
|
-
case "i": // Signed 32-bit integer
|
|
108
|
-
case "I": // Unsigned 32-bit integer
|
|
109
|
-
case "l": // Signed 32-bit integer
|
|
110
|
-
case "L": // Unsigned 32-bit integer
|
|
111
|
-
size += 4;
|
|
112
|
-
break;
|
|
113
|
-
// case "q": // Signed 64-bit integer
|
|
114
|
-
// case "Q": // Unsigned 64-bit integer
|
|
115
|
-
// size += 8;
|
|
116
|
-
// break;
|
|
117
|
-
case "f": // 32-bit float
|
|
118
|
-
size += 4;
|
|
119
|
-
break;
|
|
120
|
-
case "d": // 64-bit float
|
|
121
|
-
size += 8;
|
|
122
|
-
break;
|
|
123
|
-
default:
|
|
124
|
-
throw new Error(`Unknown format character: ${char}`);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return size;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function structPack(format: string, values: number[]): Uint8Array {
|
|
131
|
-
const size = structSizeOf(format);
|
|
132
|
-
const buffer = new ArrayBuffer(size);
|
|
133
|
-
const view = new DataView(buffer);
|
|
134
|
-
let offset = 0;
|
|
135
|
-
let littleEndian = false;
|
|
136
|
-
|
|
137
|
-
const valIdx = 0;
|
|
138
|
-
for (let i = 0; i < format.length; i++) {
|
|
139
|
-
const char = format[i];
|
|
140
|
-
const value = values[valIdx];
|
|
141
|
-
switch (char) {
|
|
142
|
-
case "<":
|
|
143
|
-
littleEndian = true;
|
|
144
|
-
break;
|
|
145
|
-
case ">":
|
|
146
|
-
littleEndian = false;
|
|
147
|
-
break;
|
|
148
|
-
case "x": // Padding byte
|
|
149
|
-
offset += 1;
|
|
150
|
-
break;
|
|
151
|
-
case "c": // Char
|
|
152
|
-
view.setInt8(offset, value);
|
|
153
|
-
offset += 1;
|
|
154
|
-
break;
|
|
155
|
-
case "b": // Signed 8-bit integer
|
|
156
|
-
view.setInt8(offset, value);
|
|
157
|
-
offset += 1;
|
|
158
|
-
break;
|
|
159
|
-
case "B": // Unsigned 8-bit integer
|
|
160
|
-
view.setUint8(offset, value);
|
|
161
|
-
offset += 1;
|
|
162
|
-
break;
|
|
163
|
-
case "h": // Signed 16-bit integer
|
|
164
|
-
view.setInt16(offset, value, littleEndian);
|
|
165
|
-
offset += 2;
|
|
166
|
-
break;
|
|
167
|
-
case "H": // Unsigned 16-bit integer
|
|
168
|
-
view.setUint16(offset, value, littleEndian);
|
|
169
|
-
offset += 2;
|
|
170
|
-
break;
|
|
171
|
-
case "i": // Signed 32-bit integer
|
|
172
|
-
view.setInt32(offset, value, littleEndian);
|
|
173
|
-
offset += 4;
|
|
174
|
-
break;
|
|
175
|
-
case "I": // Unsigned 32-bit integer
|
|
176
|
-
view.setUint32(offset, value, littleEndian);
|
|
177
|
-
offset += 4;
|
|
178
|
-
break;
|
|
179
|
-
case "l": // Signed 32-bit integer
|
|
180
|
-
view.setInt32(offset, value, littleEndian);
|
|
181
|
-
offset += 4;
|
|
182
|
-
break;
|
|
183
|
-
case "L": // Unsigned 32-bit integer
|
|
184
|
-
view.setUint32(offset, value, littleEndian);
|
|
185
|
-
offset += 4;
|
|
186
|
-
break;
|
|
187
|
-
// case "q": // Signed 64-bit integer
|
|
188
|
-
// view.setBigInt64(offset, BigInt(value), littleEndian);
|
|
189
|
-
// offset += 8;
|
|
190
|
-
// break;
|
|
191
|
-
// case "Q": // Unsigned 64-bit integer
|
|
192
|
-
// view.setBigUint64(offset, BigInt(value), littleEndian);
|
|
193
|
-
// offset += 8;
|
|
194
|
-
// break;
|
|
195
|
-
case "f": // 32-bit float
|
|
196
|
-
view.setFloat32(offset, value, littleEndian);
|
|
197
|
-
offset += 4;
|
|
198
|
-
break;
|
|
199
|
-
case "d": // 64-bit float
|
|
200
|
-
view.setFloat64(offset, value, littleEndian);
|
|
201
|
-
offset += 8;
|
|
202
|
-
break;
|
|
203
|
-
default:
|
|
204
|
-
throw new Error(`Unknown format character: ${char}`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return new Uint8Array(buffer);
|
|
209
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { RaftSystemType } from "./RaftSystemType";
|
|
2
|
-
|
|
3
|
-
type RaftSystemTypeCreator = () => RaftSystemType;
|
|
4
|
-
|
|
5
|
-
export default class RaftSysTypeManager {
|
|
6
|
-
// Singleton instance
|
|
7
|
-
private static _instance: RaftSysTypeManager;
|
|
8
|
-
|
|
9
|
-
// System type map
|
|
10
|
-
private _sysTypes: Map<string, RaftSystemTypeCreator> = new Map();
|
|
11
|
-
private _defaultSysTypeFactory: RaftSystemTypeCreator | null = null;
|
|
12
|
-
|
|
13
|
-
// Get instance (Singleton)
|
|
14
|
-
public static getInstance(): RaftSysTypeManager {
|
|
15
|
-
if (!RaftSysTypeManager._instance) {
|
|
16
|
-
RaftSysTypeManager._instance = new RaftSysTypeManager();
|
|
17
|
-
}
|
|
18
|
-
return RaftSysTypeManager._instance;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// Add a system type by name with its factory
|
|
22
|
-
public addSystemType(sysType: string, factory: RaftSystemTypeCreator): void {
|
|
23
|
-
if (this._sysTypes.has(sysType)) {
|
|
24
|
-
throw new Error(`System type '${sysType}' is already registered.`);
|
|
25
|
-
}
|
|
26
|
-
this._sysTypes.set(sysType, factory);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Set the default system type factory
|
|
30
|
-
public addDefaultSystemType(factory: RaftSystemTypeCreator): void {
|
|
31
|
-
this._defaultSysTypeFactory = factory;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Create a system type by name
|
|
35
|
-
public createSystemType(sysType: string): RaftSystemType | null {
|
|
36
|
-
const factory = this._sysTypes.get(sysType);
|
|
37
|
-
if (!factory) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
return factory();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// Create the default system type
|
|
44
|
-
public createDefaultSystemType(): RaftSystemType | null {
|
|
45
|
-
if (!this._defaultSysTypeFactory) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
return this._defaultSysTypeFactory();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Get a list of all unique BLE service UUIDs
|
|
52
|
-
getAllServiceUUIDs(): string[] {
|
|
53
|
-
const serviceUUIDs = new Set<string>();
|
|
54
|
-
this._sysTypes.forEach((factory) => {
|
|
55
|
-
const sysType = factory();
|
|
56
|
-
sysType.BLEServiceUUIDs.forEach((uuid) => serviceUUIDs.add(uuid));
|
|
57
|
-
});
|
|
58
|
-
return Array.from(serviceUUIDs);
|
|
59
|
-
}
|
|
60
|
-
}
|