brilliantsole 0.0.29 → 0.0.30
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/build/brilliantsole.cjs +5630 -494
- package/build/brilliantsole.cjs.map +1 -1
- package/build/brilliantsole.js +21293 -3088
- package/build/brilliantsole.js.map +1 -1
- package/build/brilliantsole.ls.js +23153 -6240
- package/build/brilliantsole.ls.js.map +1 -1
- package/build/brilliantsole.min.js +1 -1
- package/build/brilliantsole.min.js.map +1 -1
- package/build/brilliantsole.module.d.ts +1158 -74
- package/build/brilliantsole.module.js +21259 -3089
- package/build/brilliantsole.module.js.map +1 -1
- package/build/brilliantsole.module.min.d.ts +1158 -74
- package/build/brilliantsole.module.min.js +1 -1
- package/build/brilliantsole.module.min.js.map +1 -1
- package/build/brilliantsole.node.module.d.ts +869 -70
- package/build/brilliantsole.node.module.js +5608 -495
- package/build/brilliantsole.node.module.js.map +1 -1
- package/build/dts/BS.d.ts +20 -1
- package/build/dts/Device.d.ts +135 -13
- package/build/dts/DeviceManager.d.ts +3 -3
- package/build/dts/DisplayManager.d.ts +320 -0
- package/build/dts/FileTransferManager.d.ts +10 -4
- package/build/dts/connection/BaseConnectionManager.d.ts +2 -2
- package/build/dts/connection/bluetooth/BluetoothUUID.d.ts +12 -0
- package/build/dts/devicePair/DevicePair.d.ts +5 -5
- package/build/dts/sensor/SensorConfigurationManager.d.ts +2 -1
- package/build/dts/server/BaseClient.d.ts +4 -4
- package/build/dts/server/udp/UDPUtils.d.ts +1 -1
- package/build/dts/utils/ArrayBufferUtils.d.ts +1 -0
- package/build/dts/utils/BitmapUtils.d.ts +17 -0
- package/build/dts/utils/ColorUtils.d.ts +5 -0
- package/build/dts/utils/DisplayBitmapUtils.d.ts +47 -0
- package/build/dts/utils/DisplayCanvasHelper.d.ts +270 -0
- package/build/dts/utils/DisplayContextCommand.d.ts +300 -0
- package/build/dts/utils/DisplayContextState.d.ts +51 -0
- package/build/dts/utils/DisplayContextStateHelper.d.ts +9 -0
- package/build/dts/utils/DisplayManagerInterface.d.ts +173 -0
- package/build/dts/utils/DisplaySpriteSheetUtils.d.ts +72 -0
- package/build/dts/utils/DisplayUtils.d.ts +70 -0
- package/build/dts/utils/MathUtils.d.ts +16 -0
- package/build/dts/utils/PathUtils.d.ts +4 -0
- package/build/dts/utils/RangeHelper.d.ts +7 -0
- package/build/dts/utils/SpriteSheetUtils.d.ts +20 -0
- package/build/index.d.ts +1156 -72
- package/build/index.node.d.ts +867 -68
- package/examples/3d-generic/index.html +5 -0
- package/examples/3d-generic/script.js +1 -0
- package/examples/basic/index.html +335 -0
- package/examples/basic/script.js +1303 -3
- package/examples/camera/utils.js +1 -1
- package/examples/display-3d/index.html +195 -0
- package/examples/display-3d/script.js +1235 -0
- package/examples/display-canvas/aframe.js +42950 -0
- package/examples/display-canvas/index.html +245 -0
- package/examples/display-canvas/script.js +2312 -0
- package/examples/display-image/index.html +189 -0
- package/examples/display-image/script.js +1093 -0
- package/examples/display-spritesheet/index.html +960 -0
- package/examples/display-spritesheet/script.js +4243 -0
- package/examples/display-text/index.html +195 -0
- package/examples/display-text/script.js +1418 -0
- package/examples/display-wireframe/index.html +204 -0
- package/examples/display-wireframe/script.js +1167 -0
- package/examples/glasses-gestures/index.html +6 -1
- package/examples/glasses-gestures/script.js +10 -8
- package/examples/microphone/index.html +3 -1
- package/examples/punch/index.html +4 -1
- package/examples/server/script.js +0 -1
- package/package.json +10 -2
- package/src/BS.ts +92 -1
- package/src/CameraManager.ts +6 -2
- package/src/Device.ts +544 -13
- package/src/DisplayManager.ts +2989 -0
- package/src/FileTransferManager.ts +79 -26
- package/src/InformationManager.ts +8 -7
- package/src/MicrophoneManager.ts +10 -3
- package/src/TfliteManager.ts +4 -2
- package/src/WifiManager.ts +4 -1
- package/src/connection/BaseConnectionManager.ts +2 -0
- package/src/connection/bluetooth/bluetoothUUIDs.ts +36 -1
- package/src/devicePair/DevicePairPressureSensorDataManager.ts +1 -1
- package/src/scanner/NobleScanner.ts +1 -1
- package/src/sensor/SensorConfigurationManager.ts +16 -8
- package/src/server/udp/UDPServer.ts +4 -4
- package/src/server/udp/UDPUtils.ts +1 -1
- package/src/server/websocket/WebSocketClient.ts +50 -1
- package/src/utils/ArrayBufferUtils.ts +23 -5
- package/src/utils/AudioUtils.ts +1 -1
- package/src/utils/ColorUtils.ts +66 -0
- package/src/utils/DisplayBitmapUtils.ts +695 -0
- package/src/utils/DisplayCanvasHelper.ts +4222 -0
- package/src/utils/DisplayContextCommand.ts +1566 -0
- package/src/utils/DisplayContextState.ts +138 -0
- package/src/utils/DisplayContextStateHelper.ts +48 -0
- package/src/utils/DisplayManagerInterface.ts +1356 -0
- package/src/utils/DisplaySpriteSheetUtils.ts +782 -0
- package/src/utils/DisplayUtils.ts +529 -0
- package/src/utils/EventDispatcher.ts +59 -14
- package/src/utils/MathUtils.ts +88 -2
- package/src/utils/ObjectUtils.ts +6 -1
- package/src/utils/PathUtils.ts +192 -0
- package/src/utils/RangeHelper.ts +15 -3
- package/src/utils/Timer.ts +1 -1
- package/src/utils/environment.ts +15 -6
- package/examples/microphone/gender.js +0 -54
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createConsole } from "./utils/Console.ts";
|
|
2
2
|
import { crc32 } from "./utils/checksum.ts";
|
|
3
|
-
import { getFileBuffer } from "./utils/ArrayBufferUtils.ts";
|
|
3
|
+
import { getFileBuffer, UInt8ByteBuffer } from "./utils/ArrayBufferUtils.ts";
|
|
4
4
|
import { FileLike } from "./utils/ArrayBufferUtils.ts";
|
|
5
5
|
import Device, { SendMessageCallback } from "./Device.ts";
|
|
6
6
|
import EventDispatcher from "./utils/EventDispatcher.ts";
|
|
@@ -25,7 +25,12 @@ export const FileTransferMessageTypes = [
|
|
|
25
25
|
] as const;
|
|
26
26
|
export type FileTransferMessageType = (typeof FileTransferMessageTypes)[number];
|
|
27
27
|
|
|
28
|
-
export const FileTypes = [
|
|
28
|
+
export const FileTypes = [
|
|
29
|
+
"tflite",
|
|
30
|
+
"wifiServerCert",
|
|
31
|
+
"wifiServerKey",
|
|
32
|
+
"spriteSheet",
|
|
33
|
+
] as const;
|
|
29
34
|
export type FileType = (typeof FileTypes)[number];
|
|
30
35
|
|
|
31
36
|
export const FileTransferStatuses = ["idle", "sending", "receiving"] as const;
|
|
@@ -68,11 +73,17 @@ export interface FileTransferEventMessages {
|
|
|
68
73
|
getFileType: { fileType: FileType };
|
|
69
74
|
getFileLength: { fileLength: number };
|
|
70
75
|
getFileChecksum: { fileChecksum: number };
|
|
71
|
-
fileTransferStatus: {
|
|
76
|
+
fileTransferStatus: {
|
|
77
|
+
fileType: FileType;
|
|
78
|
+
fileTransferStatus: FileTransferStatus;
|
|
79
|
+
};
|
|
72
80
|
getFileBlock: { fileTransferBlock: DataView };
|
|
73
|
-
fileTransferProgress: { progress: number };
|
|
74
|
-
fileTransferComplete: {
|
|
75
|
-
|
|
81
|
+
fileTransferProgress: { fileType: FileType; progress: number };
|
|
82
|
+
fileTransferComplete: {
|
|
83
|
+
fileType: FileType;
|
|
84
|
+
direction: FileTransferDirection;
|
|
85
|
+
};
|
|
86
|
+
fileReceived: { fileType: FileType; file: File | Blob };
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
export type FileTransferEventDispatcher = EventDispatcher<
|
|
@@ -83,6 +94,12 @@ export type FileTransferEventDispatcher = EventDispatcher<
|
|
|
83
94
|
export type SendFileTransferMessageCallback =
|
|
84
95
|
SendMessageCallback<FileTransferMessageType>;
|
|
85
96
|
|
|
97
|
+
export type SendFileCallback = (
|
|
98
|
+
type: FileType,
|
|
99
|
+
file: FileLike,
|
|
100
|
+
override?: boolean
|
|
101
|
+
) => Promise<boolean>;
|
|
102
|
+
|
|
86
103
|
class FileTransferManager {
|
|
87
104
|
constructor() {
|
|
88
105
|
autoBind(this);
|
|
@@ -194,8 +211,9 @@ class FileTransferManager {
|
|
|
194
211
|
const promise = this.waitForEvent("getFileType");
|
|
195
212
|
|
|
196
213
|
const typeEnum = FileTypes.indexOf(newType);
|
|
214
|
+
|
|
197
215
|
this.sendMessage(
|
|
198
|
-
[{ type: "setFileType", data:
|
|
216
|
+
[{ type: "setFileType", data: UInt8ByteBuffer(typeEnum) }],
|
|
199
217
|
sendImmediately
|
|
200
218
|
);
|
|
201
219
|
|
|
@@ -276,11 +294,12 @@ class FileTransferManager {
|
|
|
276
294
|
const promise = this.waitForEvent("fileTransferStatus");
|
|
277
295
|
_console.log(`setting command ${command}`);
|
|
278
296
|
const commandEnum = FileTransferCommands.indexOf(command);
|
|
297
|
+
|
|
279
298
|
this.sendMessage(
|
|
280
299
|
[
|
|
281
300
|
{
|
|
282
301
|
type: "setFileTransferCommand",
|
|
283
|
-
data:
|
|
302
|
+
data: UInt8ByteBuffer(commandEnum),
|
|
284
303
|
},
|
|
285
304
|
],
|
|
286
305
|
sendImmediately
|
|
@@ -303,9 +322,14 @@ class FileTransferManager {
|
|
|
303
322
|
#updateStatus(status: FileTransferStatus) {
|
|
304
323
|
_console.log({ status });
|
|
305
324
|
this.#status = status;
|
|
306
|
-
this.#dispatchEvent("fileTransferStatus", { fileTransferStatus: status });
|
|
307
325
|
this.#receivedBlocks.length = 0;
|
|
308
326
|
this.#isCancelling = false;
|
|
327
|
+
this.#buffer = undefined;
|
|
328
|
+
this.#bytesTransferred = 0;
|
|
329
|
+
this.#dispatchEvent("fileTransferStatus", {
|
|
330
|
+
fileTransferStatus: status,
|
|
331
|
+
fileType: this.type!,
|
|
332
|
+
});
|
|
309
333
|
}
|
|
310
334
|
#assertIsIdle() {
|
|
311
335
|
_console.assertWithError(this.#status == "idle", "status is not idle");
|
|
@@ -332,7 +356,10 @@ class FileTransferManager {
|
|
|
332
356
|
`received ${bytesReceived} of ${this.#length} bytes (${progress * 100}%)`
|
|
333
357
|
);
|
|
334
358
|
|
|
335
|
-
this.#dispatchEvent("fileTransferProgress", {
|
|
359
|
+
this.#dispatchEvent("fileTransferProgress", {
|
|
360
|
+
progress,
|
|
361
|
+
fileType: this.type!,
|
|
362
|
+
});
|
|
336
363
|
|
|
337
364
|
if (bytesReceived != this.#length) {
|
|
338
365
|
const dataView = new DataView(new ArrayBuffer(4));
|
|
@@ -383,8 +410,11 @@ class FileTransferManager {
|
|
|
383
410
|
_console.log("received file", file);
|
|
384
411
|
|
|
385
412
|
this.#dispatchEvent("getFileBlock", { fileTransferBlock: dataView });
|
|
386
|
-
this.#dispatchEvent("fileTransferComplete", {
|
|
387
|
-
|
|
413
|
+
this.#dispatchEvent("fileTransferComplete", {
|
|
414
|
+
direction: "receiving",
|
|
415
|
+
fileType: this.type!,
|
|
416
|
+
});
|
|
417
|
+
this.#dispatchEvent("fileReceived", { file, fileType: this.type! });
|
|
388
418
|
}
|
|
389
419
|
|
|
390
420
|
parseMessage(messageType: FileTransferMessageType, dataView: DataView) {
|
|
@@ -423,7 +453,7 @@ class FileTransferManager {
|
|
|
423
453
|
}
|
|
424
454
|
}
|
|
425
455
|
|
|
426
|
-
async send(type: FileType, file: FileLike) {
|
|
456
|
+
async send(type: FileType, file: FileLike, override?: boolean) {
|
|
427
457
|
if (true) {
|
|
428
458
|
this.#assertIsIdle();
|
|
429
459
|
this.#assertValidType(type);
|
|
@@ -441,16 +471,19 @@ class FileTransferManager {
|
|
|
441
471
|
const fileBuffer = await getFileBuffer(file);
|
|
442
472
|
const fileLength = fileBuffer.byteLength;
|
|
443
473
|
const checksum = crc32(fileBuffer);
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
474
|
+
this.#assertValidLength(fileLength);
|
|
475
|
+
|
|
476
|
+
if (!override) {
|
|
477
|
+
if (type != this.type) {
|
|
478
|
+
_console.log("different fileTypes - sending");
|
|
479
|
+
} else if (fileLength != this.length) {
|
|
480
|
+
_console.log("different fileLengths - sending");
|
|
481
|
+
} else if (checksum != this.checksum) {
|
|
482
|
+
_console.log("different fileChecksums - sending");
|
|
483
|
+
} else {
|
|
484
|
+
_console.log("already sent file");
|
|
485
|
+
return false;
|
|
486
|
+
}
|
|
454
487
|
}
|
|
455
488
|
|
|
456
489
|
const promises: Promise<any>[] = [];
|
|
@@ -464,6 +497,16 @@ class FileTransferManager {
|
|
|
464
497
|
|
|
465
498
|
await Promise.all(promises);
|
|
466
499
|
|
|
500
|
+
if (this.#buffer) {
|
|
501
|
+
return false;
|
|
502
|
+
}
|
|
503
|
+
if (this.#length != fileLength) {
|
|
504
|
+
return false;
|
|
505
|
+
}
|
|
506
|
+
if (this.#checksum != checksum) {
|
|
507
|
+
return false;
|
|
508
|
+
}
|
|
509
|
+
|
|
467
510
|
await this.#send(fileBuffer);
|
|
468
511
|
|
|
469
512
|
return true;
|
|
@@ -473,7 +516,6 @@ class FileTransferManager {
|
|
|
473
516
|
#bytesTransferred = 0;
|
|
474
517
|
async #send(buffer: ArrayBuffer) {
|
|
475
518
|
this.#buffer = buffer;
|
|
476
|
-
this.#bytesTransferred = 0;
|
|
477
519
|
return this.#sendBlock();
|
|
478
520
|
}
|
|
479
521
|
|
|
@@ -506,10 +548,16 @@ class FileTransferManager {
|
|
|
506
548
|
buffer.byteLength
|
|
507
549
|
} bytes (${progress * 100}%)`
|
|
508
550
|
);
|
|
509
|
-
this.#dispatchEvent("fileTransferProgress", {
|
|
551
|
+
this.#dispatchEvent("fileTransferProgress", {
|
|
552
|
+
progress,
|
|
553
|
+
fileType: this.type!,
|
|
554
|
+
});
|
|
510
555
|
if (slicedBuffer.byteLength == 0) {
|
|
511
556
|
_console.log("finished sending buffer");
|
|
512
|
-
this.#dispatchEvent("fileTransferComplete", {
|
|
557
|
+
this.#dispatchEvent("fileTransferComplete", {
|
|
558
|
+
direction: "sending",
|
|
559
|
+
fileType: this.type!,
|
|
560
|
+
});
|
|
513
561
|
} else {
|
|
514
562
|
await this.sendMessage([{ type: "setFileBlock", data: slicedBuffer }]);
|
|
515
563
|
this.#bytesTransferred = offset + slicedBuffer.byteLength;
|
|
@@ -575,6 +623,11 @@ class FileTransferManager {
|
|
|
575
623
|
}));
|
|
576
624
|
this.sendMessage(messages, false);
|
|
577
625
|
}
|
|
626
|
+
|
|
627
|
+
clear() {
|
|
628
|
+
this.#status = "idle";
|
|
629
|
+
this.#isServerSide = false;
|
|
630
|
+
}
|
|
578
631
|
}
|
|
579
632
|
|
|
580
633
|
export default FileTransferManager;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ConnectionType } from "./connection/BaseConnectionManager.ts";
|
|
2
2
|
import Device, { SendMessageCallback } from "./Device.ts";
|
|
3
|
+
import { UInt8ByteBuffer } from "./utils/ArrayBufferUtils.ts";
|
|
3
4
|
import { createConsole } from "./utils/Console.ts";
|
|
4
|
-
import { isInBrowser } from "./utils/environment.ts";
|
|
5
5
|
import EventDispatcher from "./utils/EventDispatcher.ts";
|
|
6
6
|
import { Uint16Max } from "./utils/MathUtils.ts";
|
|
7
7
|
import { textDecoder, textEncoder } from "./utils/Text.ts";
|
|
@@ -165,10 +165,10 @@ class InformationManager {
|
|
|
165
165
|
}
|
|
166
166
|
updateType(updatedType: DeviceType) {
|
|
167
167
|
this.#assertValidDeviceType(updatedType);
|
|
168
|
-
if (updatedType == this.type) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
168
|
+
// if (updatedType == this.type) {
|
|
169
|
+
// _console.log("redundant type assignment");
|
|
170
|
+
// return;
|
|
171
|
+
// }
|
|
172
172
|
this.#type = updatedType;
|
|
173
173
|
_console.log({ updatedType: this.#type });
|
|
174
174
|
|
|
@@ -176,10 +176,11 @@ class InformationManager {
|
|
|
176
176
|
}
|
|
177
177
|
async #setTypeEnum(newTypeEnum: number) {
|
|
178
178
|
this.#assertValidDeviceTypeEnum(newTypeEnum);
|
|
179
|
-
|
|
179
|
+
|
|
180
|
+
const setTypeData = UInt8ByteBuffer(newTypeEnum);
|
|
180
181
|
_console.log({ setTypeData });
|
|
181
182
|
const promise = this.waitForEvent("getType");
|
|
182
|
-
this.sendMessage([{ type: "setType", data: setTypeData
|
|
183
|
+
this.sendMessage([{ type: "setType", data: setTypeData }]);
|
|
183
184
|
await promise;
|
|
184
185
|
}
|
|
185
186
|
async setType(newType: DeviceType) {
|
package/src/MicrophoneManager.ts
CHANGED
|
@@ -2,7 +2,10 @@ import Device, { SendMessageCallback } from "./Device.ts";
|
|
|
2
2
|
import { createConsole } from "./utils/Console.ts";
|
|
3
3
|
import EventDispatcher from "./utils/EventDispatcher.ts";
|
|
4
4
|
import autoBind from "auto-bind";
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
concatenateArrayBuffers,
|
|
7
|
+
UInt8ByteBuffer,
|
|
8
|
+
} from "./utils/ArrayBufferUtils.ts";
|
|
6
9
|
import { float32ArrayToWav } from "./utils/AudioUtils.ts";
|
|
7
10
|
|
|
8
11
|
const _console = createConsole("MicrophoneManager", { log: false });
|
|
@@ -149,11 +152,12 @@ class MicrophoneManager {
|
|
|
149
152
|
const promise = this.waitForEvent("microphoneStatus");
|
|
150
153
|
_console.log(`setting command "${command}"`);
|
|
151
154
|
const commandEnum = MicrophoneCommands.indexOf(command);
|
|
155
|
+
|
|
152
156
|
this.sendMessage(
|
|
153
157
|
[
|
|
154
158
|
{
|
|
155
159
|
type: "microphoneCommand",
|
|
156
|
-
data:
|
|
160
|
+
data: UInt8ByteBuffer(commandEnum),
|
|
157
161
|
},
|
|
158
162
|
],
|
|
159
163
|
sendImmediately
|
|
@@ -184,7 +188,10 @@ class MicrophoneManager {
|
|
|
184
188
|
await this.#sendMicrophoneCommand("start");
|
|
185
189
|
}
|
|
186
190
|
async stop() {
|
|
187
|
-
this
|
|
191
|
+
if (this.microphoneStatus == "idle") {
|
|
192
|
+
_console.log("microphone is already idle");
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
188
195
|
await this.#sendMicrophoneCommand("stop");
|
|
189
196
|
}
|
|
190
197
|
async vad() {
|
package/src/TfliteManager.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { SensorType } from "./sensor/SensorDataManager.ts";
|
|
|
9
9
|
import Device, { SendMessageCallback } from "./Device.ts";
|
|
10
10
|
import autoBind from "auto-bind";
|
|
11
11
|
import { FileConfiguration as BaseFileConfiguration } from "./FileTransferManager.ts";
|
|
12
|
+
import { UInt8ByteBuffer } from "./utils/ArrayBufferUtils.ts";
|
|
12
13
|
|
|
13
14
|
const _console = createConsole("TfliteManager", { log: false });
|
|
14
15
|
|
|
@@ -188,7 +189,7 @@ class TfliteManager {
|
|
|
188
189
|
|
|
189
190
|
const taskEnum = TfliteTasks.indexOf(newTask);
|
|
190
191
|
this.sendMessage(
|
|
191
|
-
[{ type: "setTfliteTask", data:
|
|
192
|
+
[{ type: "setTfliteTask", data: UInt8ByteBuffer(taskEnum) }],
|
|
192
193
|
sendImmediately
|
|
193
194
|
);
|
|
194
195
|
|
|
@@ -429,7 +430,8 @@ class TfliteManager {
|
|
|
429
430
|
[
|
|
430
431
|
{
|
|
431
432
|
type: "setTfliteInferencingEnabled",
|
|
432
|
-
|
|
433
|
+
|
|
434
|
+
data: UInt8ByteBuffer(Number(newInferencingEnabled)),
|
|
433
435
|
},
|
|
434
436
|
],
|
|
435
437
|
sendImmediately
|
package/src/WifiManager.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Device, { SendMessageCallback } from "./Device.ts";
|
|
2
|
+
import { UInt8ByteBuffer } from "./utils/ArrayBufferUtils.ts";
|
|
2
3
|
import { createConsole } from "./utils/Console.ts";
|
|
3
4
|
import { isInNode } from "./utils/environment.ts";
|
|
4
5
|
import EventDispatcher from "./utils/EventDispatcher.ts";
|
|
@@ -197,11 +198,13 @@ class WifiManager {
|
|
|
197
198
|
}
|
|
198
199
|
|
|
199
200
|
const promise = this.waitForEvent("getWifiConnectionEnabled");
|
|
201
|
+
|
|
200
202
|
this.sendMessage(
|
|
201
203
|
[
|
|
202
204
|
{
|
|
203
205
|
type: "setWifiConnectionEnabled",
|
|
204
|
-
|
|
206
|
+
|
|
207
|
+
data: UInt8ByteBuffer(Number(newWifiConnectionEnabled)),
|
|
205
208
|
},
|
|
206
209
|
],
|
|
207
210
|
sendImmediately
|
|
@@ -13,6 +13,7 @@ import { SensorDataMessageTypes } from "../sensor/SensorDataManager.ts";
|
|
|
13
13
|
import { WifiMessageTypes } from "../WifiManager.ts";
|
|
14
14
|
import { CameraMessageTypes } from "../CameraManager.ts";
|
|
15
15
|
import { MicrophoneMessageTypes } from "../MicrophoneManager.ts";
|
|
16
|
+
import { DisplayMessageTypes } from "../DisplayManager.ts";
|
|
16
17
|
|
|
17
18
|
const _console = createConsole("BaseConnectionManager", { log: false });
|
|
18
19
|
|
|
@@ -95,6 +96,7 @@ export const TxRxMessageTypes = [
|
|
|
95
96
|
...WifiMessageTypes,
|
|
96
97
|
...CameraMessageTypes,
|
|
97
98
|
...MicrophoneMessageTypes,
|
|
99
|
+
...DisplayMessageTypes,
|
|
98
100
|
] as const;
|
|
99
101
|
export type TxRxMessageType = (typeof TxRxMessageTypes)[number];
|
|
100
102
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isInBrowser,
|
|
3
|
+
isInLensStudio,
|
|
4
|
+
isInNode,
|
|
5
|
+
} from "../../utils/environment.ts";
|
|
2
6
|
import { createConsole } from "../../utils/Console.ts";
|
|
3
7
|
|
|
4
8
|
const _console = createConsole("bluetoothUUIDs", { log: false });
|
|
@@ -7,12 +11,43 @@ const _console = createConsole("bluetoothUUIDs", { log: false });
|
|
|
7
11
|
import * as webbluetooth from "webbluetooth";
|
|
8
12
|
var BluetoothUUID = webbluetooth.BluetoothUUID;
|
|
9
13
|
/** NODE_END */
|
|
14
|
+
|
|
10
15
|
/** BROWSER_START */
|
|
11
16
|
if (isInBrowser) {
|
|
12
17
|
var BluetoothUUID = window.BluetoothUUID;
|
|
13
18
|
}
|
|
14
19
|
/** BROWSER_END */
|
|
15
20
|
|
|
21
|
+
/** LS_START */
|
|
22
|
+
|
|
23
|
+
var BluetoothUUID = {
|
|
24
|
+
getService: (uuid: number | string): string => toUUID(uuid),
|
|
25
|
+
|
|
26
|
+
getCharacteristic: (uuid: number | string): string => toUUID(uuid),
|
|
27
|
+
|
|
28
|
+
getDescriptor: (uuid: number | string): string => toUUID(uuid),
|
|
29
|
+
|
|
30
|
+
getCharacteristicName: (uuid: number | string): string | null => null,
|
|
31
|
+
|
|
32
|
+
getServiceName: (uuid: number | string): string | null => null,
|
|
33
|
+
|
|
34
|
+
getDescriptorName: (uuid: number | string): string | null => null,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function toUUID(uuid: number | string): string {
|
|
38
|
+
if (typeof uuid === "number") {
|
|
39
|
+
uuid = uuid.toString(16).padStart(4, "0");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (/^[0-9a-fA-F]{4,8}$/.test(uuid)) {
|
|
43
|
+
return `0000${uuid.padStart(8, "0")}-0000-1000-8000-00805f9b34fb`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return uuid.toLowerCase();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** LS_END */
|
|
50
|
+
|
|
16
51
|
function generateBluetoothUUID(value: string): BluetoothServiceUUID {
|
|
17
52
|
_console.assertTypeWithError(value, "string");
|
|
18
53
|
_console.assertWithError(
|
|
@@ -101,7 +101,7 @@ class DevicePairPressureSensorDataManager {
|
|
|
101
101
|
}
|
|
102
102
|
} else {
|
|
103
103
|
sidePressure.sensors.forEach((sensor) => {
|
|
104
|
-
const _sensor: PressureSensorValue =
|
|
104
|
+
const _sensor: PressureSensorValue = structuredClone(sensor);
|
|
105
105
|
_sensor.weightedValue = sensor.scaledValue / pressure.scaledSum;
|
|
106
106
|
let { x, y } = sensor.position;
|
|
107
107
|
x /= 2;
|
|
@@ -122,7 +122,7 @@ class NobleScanner extends BaseScanner {
|
|
|
122
122
|
ipAddress = new Uint8Array(
|
|
123
123
|
manufacturerData.buffer.slice(3, 3 + 4)
|
|
124
124
|
).join(".");
|
|
125
|
-
|
|
125
|
+
_console.log({ ipAddress });
|
|
126
126
|
}
|
|
127
127
|
if (manufacturerData.byteLength >= 3 + 4 + 1) {
|
|
128
128
|
isWifiSecure = manufacturerData.readUint8(3 + 4) != 0;
|
|
@@ -84,6 +84,10 @@ class SensorConfigurationManager {
|
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
clear() {
|
|
88
|
+
this.#updateConfiguration({});
|
|
89
|
+
}
|
|
90
|
+
|
|
87
91
|
#isRedundant(sensorConfiguration: SensorConfiguration) {
|
|
88
92
|
let sensorTypes = Object.keys(sensorConfiguration) as SensorType[];
|
|
89
93
|
return sensorTypes.every((sensorType) => {
|
|
@@ -93,11 +97,12 @@ class SensorConfigurationManager {
|
|
|
93
97
|
|
|
94
98
|
async setConfiguration(
|
|
95
99
|
newSensorConfiguration: SensorConfiguration,
|
|
96
|
-
clearRest?: boolean
|
|
100
|
+
clearRest?: boolean,
|
|
101
|
+
sendImmediately?: boolean
|
|
97
102
|
) {
|
|
98
103
|
if (clearRest) {
|
|
99
104
|
newSensorConfiguration = Object.assign(
|
|
100
|
-
|
|
105
|
+
structuredClone(this.zeroSensorConfiguration),
|
|
101
106
|
newSensorConfiguration
|
|
102
107
|
);
|
|
103
108
|
}
|
|
@@ -110,12 +115,15 @@ class SensorConfigurationManager {
|
|
|
110
115
|
_console.log({ setSensorConfigurationData });
|
|
111
116
|
|
|
112
117
|
const promise = this.waitForEvent("getSensorConfiguration");
|
|
113
|
-
this.sendMessage(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
118
|
+
this.sendMessage(
|
|
119
|
+
[
|
|
120
|
+
{
|
|
121
|
+
type: "setSensorConfiguration",
|
|
122
|
+
data: setSensorConfigurationData.buffer,
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
sendImmediately
|
|
126
|
+
);
|
|
119
127
|
await promise;
|
|
120
128
|
}
|
|
121
129
|
|
|
@@ -56,10 +56,10 @@ class UDPServer extends BaseServer {
|
|
|
56
56
|
client = {
|
|
57
57
|
...remoteInfo,
|
|
58
58
|
isAlive: true,
|
|
59
|
-
removeSelfTimer: new Timer(
|
|
60
|
-
(
|
|
61
|
-
|
|
62
|
-
),
|
|
59
|
+
removeSelfTimer: new Timer(() => {
|
|
60
|
+
_console.log("removing client due to timeout...");
|
|
61
|
+
this.#removeClient(client!);
|
|
62
|
+
}, removeUDPClientTimeout),
|
|
63
63
|
lastTimeSentData: 0,
|
|
64
64
|
};
|
|
65
65
|
_console.log("created new client", client);
|
|
@@ -4,7 +4,7 @@ import { createMessage, Message } from "../ServerUtils.ts";
|
|
|
4
4
|
const _console = createConsole("UDPUtils", { log: false });
|
|
5
5
|
|
|
6
6
|
export const pongUDPClientTimeout = 2_000;
|
|
7
|
-
export const removeUDPClientTimeout =
|
|
7
|
+
export const removeUDPClientTimeout = 4_000;
|
|
8
8
|
|
|
9
9
|
export const UDPServerMessageTypes = [
|
|
10
10
|
"ping",
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
WebSocketMessage,
|
|
22
22
|
} from "./WebSocketUtils.ts";
|
|
23
23
|
import { parseMessage } from "../../utils/ParseUtils.ts";
|
|
24
|
+
import { isInLensStudio, isInBrowser } from "../../utils/environment.ts";
|
|
24
25
|
|
|
25
26
|
const _console = createConsole("WebSocketClient", { log: false });
|
|
26
27
|
|
|
@@ -62,7 +63,55 @@ class WebSocketClient extends BaseClient {
|
|
|
62
63
|
this.assertDisconnection();
|
|
63
64
|
}
|
|
64
65
|
this._connectionStatus = "connecting";
|
|
65
|
-
|
|
66
|
+
|
|
67
|
+
if (isInLensStudio) {
|
|
68
|
+
if (globalThis.internetModule) {
|
|
69
|
+
// FILL
|
|
70
|
+
/*
|
|
71
|
+
let socket = globalThis.internetModule.createWebSocket(url);
|
|
72
|
+
socket.binaryType = "blob";
|
|
73
|
+
|
|
74
|
+
socket.onopen = (event) => {
|
|
75
|
+
socket.send("Message 1");
|
|
76
|
+
|
|
77
|
+
// Try sending a binary message
|
|
78
|
+
// (the bytes below spell 'Message 2')
|
|
79
|
+
const message = [77, 101, 115, 115, 97, 103, 101, 32, 50];
|
|
80
|
+
const bytes = new Uint8Array(message);
|
|
81
|
+
socket.send(bytes);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Listen for messages
|
|
85
|
+
socket.onmessage = async (event) => {
|
|
86
|
+
if (event.data instanceof Blob) {
|
|
87
|
+
// Binary frame, can be retrieved as either Uint8Array or string
|
|
88
|
+
let bytes = await event.data.bytes();
|
|
89
|
+
let text = await event.data.text();
|
|
90
|
+
|
|
91
|
+
print("Received binary message, printing as text: " + text);
|
|
92
|
+
} else {
|
|
93
|
+
// Text frame
|
|
94
|
+
let text = event.data;
|
|
95
|
+
print("Received text message: " + text);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
socket.onclose = (event) => {
|
|
100
|
+
if (event.wasClean) {
|
|
101
|
+
print("Socket closed cleanly");
|
|
102
|
+
} else {
|
|
103
|
+
print("Socket closed with error, code: " + event.code);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
socket.onerror = (event) => {
|
|
108
|
+
print("Socket error");
|
|
109
|
+
};
|
|
110
|
+
*/
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
this.webSocket = new WebSocket(url);
|
|
114
|
+
}
|
|
66
115
|
}
|
|
67
116
|
|
|
68
117
|
disconnect() {
|
|
@@ -4,7 +4,9 @@ import { textEncoder } from "./Text.ts";
|
|
|
4
4
|
const _console = createConsole("ArrayBufferUtils", { log: false });
|
|
5
5
|
|
|
6
6
|
export function concatenateArrayBuffers(...arrayBuffers: any[]): ArrayBuffer {
|
|
7
|
-
arrayBuffers = arrayBuffers.filter(
|
|
7
|
+
arrayBuffers = arrayBuffers.filter(
|
|
8
|
+
(arrayBuffer) => arrayBuffer != undefined || arrayBuffer != null
|
|
9
|
+
);
|
|
8
10
|
arrayBuffers = arrayBuffers.map((arrayBuffer) => {
|
|
9
11
|
if (typeof arrayBuffer == "number") {
|
|
10
12
|
const number = arrayBuffer;
|
|
@@ -20,7 +22,10 @@ export function concatenateArrayBuffers(...arrayBuffers: any[]): ArrayBuffer {
|
|
|
20
22
|
return concatenateArrayBuffers(...array);
|
|
21
23
|
} else if (arrayBuffer instanceof ArrayBuffer) {
|
|
22
24
|
return arrayBuffer;
|
|
23
|
-
} else if (
|
|
25
|
+
} else if (
|
|
26
|
+
"buffer" in arrayBuffer &&
|
|
27
|
+
arrayBuffer.buffer instanceof ArrayBuffer
|
|
28
|
+
) {
|
|
24
29
|
const bufferContainer = arrayBuffer;
|
|
25
30
|
return bufferContainer.buffer;
|
|
26
31
|
} else if (arrayBuffer instanceof DataView) {
|
|
@@ -33,8 +38,13 @@ export function concatenateArrayBuffers(...arrayBuffers: any[]): ArrayBuffer {
|
|
|
33
38
|
return arrayBuffer;
|
|
34
39
|
}
|
|
35
40
|
});
|
|
36
|
-
arrayBuffers = arrayBuffers.filter(
|
|
37
|
-
|
|
41
|
+
arrayBuffers = arrayBuffers.filter(
|
|
42
|
+
(arrayBuffer) => arrayBuffer && "byteLength" in arrayBuffer
|
|
43
|
+
);
|
|
44
|
+
const length = arrayBuffers.reduce(
|
|
45
|
+
(length, arrayBuffer) => length + arrayBuffer.byteLength,
|
|
46
|
+
0
|
|
47
|
+
);
|
|
38
48
|
const uint8Array = new Uint8Array(length);
|
|
39
49
|
let byteOffset = 0;
|
|
40
50
|
arrayBuffers.forEach((arrayBuffer) => {
|
|
@@ -57,7 +67,11 @@ export function objectToArrayBuffer(object: object) {
|
|
|
57
67
|
return stringToArrayBuffer(JSON.stringify(object));
|
|
58
68
|
}
|
|
59
69
|
|
|
60
|
-
export function sliceDataView(
|
|
70
|
+
export function sliceDataView(
|
|
71
|
+
dataView: DataView,
|
|
72
|
+
begin: number,
|
|
73
|
+
length?: number
|
|
74
|
+
) {
|
|
61
75
|
let end;
|
|
62
76
|
if (length != undefined) {
|
|
63
77
|
end = dataView.byteOffset + begin + length;
|
|
@@ -86,3 +100,7 @@ export async function getFileBuffer(file: FileLike) {
|
|
|
86
100
|
}
|
|
87
101
|
return fileBuffer;
|
|
88
102
|
}
|
|
103
|
+
|
|
104
|
+
export function UInt8ByteBuffer(value: number) {
|
|
105
|
+
return Uint8Array.from([value]).buffer;
|
|
106
|
+
}
|
package/src/utils/AudioUtils.ts
CHANGED