@mentra/cloud-client 3.2.1 → 3.3.0-beta.1001
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/node/index.ts +2 -0
- package/package.json +2 -2
- package/src/client.ts +9 -1
- package/src/errors.ts +27 -2
- package/src/http.ts +123 -15
- package/src/index.ts +13 -6
- package/src/modules/auth/auth.ts +266 -61
- package/src/modules/core/core.ts +49 -129
- package/src/modules/core/fleet.ts +175 -0
- package/src/modules/core/reports.ts +145 -9
- package/src/modules/runtime/audio-udp.ts +56 -4
- package/src/modules/runtime/runtime.ts +25 -3
|
@@ -24,7 +24,11 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import nacl from "tweetnacl";
|
|
26
26
|
import type { UdpSocketLike } from "../../transports";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
UDP_LIVENESS_PROBE_PREFIX,
|
|
29
|
+
type AudioPosition,
|
|
30
|
+
type ConnectionAck,
|
|
31
|
+
} from "@mentra/cloud-protocol";
|
|
28
32
|
|
|
29
33
|
/** The audio block of `connection.ack`, present only when UDP audio is offered. */
|
|
30
34
|
type AudioConfig = NonNullable<ConnectionAck["audio"]>;
|
|
@@ -40,6 +44,7 @@ const SEQ_MODULO = 0x10000;
|
|
|
40
44
|
|
|
41
45
|
export interface UdpAudioDeps {
|
|
42
46
|
udp: () => UdpSocketLike;
|
|
47
|
+
audio?: { codec: "pcm" | "lc3"; sampleRate: number; frameSizeBytes?: number };
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export type RuntimeAudioTransport = "udp" | "ws" | "none";
|
|
@@ -59,6 +64,8 @@ interface UdpSession {
|
|
|
59
64
|
key: Uint8Array;
|
|
60
65
|
/** Per-session packet counter; wraps at the u16 boundary. */
|
|
61
66
|
seq: number;
|
|
67
|
+
offsetMs: number;
|
|
68
|
+
frameTimelineVersion?: 1;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
export class UdpAudio {
|
|
@@ -67,6 +74,17 @@ export class UdpAudio {
|
|
|
67
74
|
|
|
68
75
|
constructor(deps: UdpAudioDeps) {
|
|
69
76
|
this.udpFactory = deps.udp;
|
|
77
|
+
this.format = deps.audio ?? { codec: "pcm", sampleRate: 16000 };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private readonly format: NonNullable<UdpAudioDeps["audio"]>;
|
|
81
|
+
|
|
82
|
+
/** @internal Next submitted frame, used by the phone runtime's subscription cutoff. */
|
|
83
|
+
get audioPosition(): AudioPosition | null {
|
|
84
|
+
const s = this.session;
|
|
85
|
+
return s?.frameTimelineVersion === 1
|
|
86
|
+
? { sessionTag: s.sessionTag, offsetMs: s.offsetMs }
|
|
87
|
+
: null;
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
/** The audio transport currently configured for outbound frames. */
|
|
@@ -105,6 +123,8 @@ export class UdpAudio {
|
|
|
105
123
|
port: audio.udp.port,
|
|
106
124
|
key: decodeBase64(audio.encryption.key),
|
|
107
125
|
seq: 0,
|
|
126
|
+
offsetMs: 0,
|
|
127
|
+
frameTimelineVersion: audio.frameTimelineVersion,
|
|
108
128
|
};
|
|
109
129
|
}
|
|
110
130
|
|
|
@@ -122,18 +142,50 @@ export class UdpAudio {
|
|
|
122
142
|
const session = this.session;
|
|
123
143
|
if (!session) return false;
|
|
124
144
|
|
|
125
|
-
session.socket.send(
|
|
145
|
+
session.socket.send(
|
|
146
|
+
this.buildEncryptedPacket(
|
|
147
|
+
session,
|
|
148
|
+
this.positionedPayload(session, payload),
|
|
149
|
+
),
|
|
150
|
+
session.host,
|
|
151
|
+
session.port,
|
|
152
|
+
);
|
|
126
153
|
return true;
|
|
127
154
|
}
|
|
128
155
|
|
|
129
156
|
sendProbe(probeId: string): boolean {
|
|
130
|
-
|
|
157
|
+
const session = this.session;
|
|
158
|
+
if (!session) return false;
|
|
159
|
+
session.socket.send(
|
|
160
|
+
this.buildEncryptedPacket(
|
|
161
|
+
session,
|
|
162
|
+
asciiBytes(`${UDP_LIVENESS_PROBE_PREFIX}${probeId}`),
|
|
163
|
+
),
|
|
164
|
+
session.host,
|
|
165
|
+
session.port,
|
|
166
|
+
);
|
|
167
|
+
return true;
|
|
131
168
|
}
|
|
132
169
|
|
|
133
170
|
buildPlainFrame(payload: Uint8Array): Uint8Array | null {
|
|
134
171
|
const session = this.session;
|
|
135
172
|
if (!session) return null;
|
|
136
|
-
return this.buildPacket(session, payload);
|
|
173
|
+
return this.buildPacket(session, this.positionedPayload(session, payload));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private positionedPayload(
|
|
177
|
+
session: UdpSession,
|
|
178
|
+
payload: Uint8Array,
|
|
179
|
+
): Uint8Array {
|
|
180
|
+
if (session.frameTimelineVersion !== 1) return payload;
|
|
181
|
+
const result = new Uint8Array(8 + payload.length);
|
|
182
|
+
new DataView(result.buffer).setFloat64(0, session.offsetMs, false);
|
|
183
|
+
result.set(payload, 8);
|
|
184
|
+
session.offsetMs +=
|
|
185
|
+
this.format.codec === "lc3"
|
|
186
|
+
? (payload.length / (this.format.frameSizeBytes ?? 20)) * 10
|
|
187
|
+
: (Math.floor(payload.length / 2) / this.format.sampleRate) * 1000;
|
|
188
|
+
return result;
|
|
137
189
|
}
|
|
138
190
|
|
|
139
191
|
private buildEncryptedPacket(session: UdpSession, payload: Uint8Array): Uint8Array {
|
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import type {
|
|
20
20
|
AudioSubscription,
|
|
21
|
+
AudioPosition,
|
|
21
22
|
TranscriptionData,
|
|
22
23
|
TranslationData,
|
|
23
24
|
ProtocolError,
|
|
@@ -29,10 +30,25 @@ import type { Connection } from "./connection";
|
|
|
29
30
|
import { HandshakeRejectedError } from "./connection";
|
|
30
31
|
import type { RuntimeEmitter, RuntimeEvents } from "./emitter";
|
|
31
32
|
import type { Subscriptions } from "./subscriptions";
|
|
32
|
-
import type {
|
|
33
|
+
import type {
|
|
34
|
+
Camera,
|
|
35
|
+
StreamOptions,
|
|
36
|
+
ManagedStream,
|
|
37
|
+
StreamStatusResult,
|
|
38
|
+
} from "./camera";
|
|
33
39
|
import type { Meetings } from "./meetings";
|
|
34
|
-
import type {
|
|
35
|
-
|
|
40
|
+
import type {
|
|
41
|
+
Maps,
|
|
42
|
+
DirectionsRequest,
|
|
43
|
+
DirectionsResult,
|
|
44
|
+
LatLng,
|
|
45
|
+
ReverseGeocodeResult,
|
|
46
|
+
} from "./maps";
|
|
47
|
+
import type {
|
|
48
|
+
Tts,
|
|
49
|
+
RuntimeTtsSpeakOptions,
|
|
50
|
+
RuntimeTtsSpeechSource,
|
|
51
|
+
} from "./tts";
|
|
36
52
|
import type { UdpAudio } from "./audio-udp";
|
|
37
53
|
import type { RuntimeSnapshot } from "./status";
|
|
38
54
|
import { systemTimers, type CloudClientTimers } from "../../timers";
|
|
@@ -82,6 +98,8 @@ export interface RuntimeModule {
|
|
|
82
98
|
* sent before the session is configured is dropped, not thrown on.
|
|
83
99
|
*/
|
|
84
100
|
sendAudioFrame(frame: Uint8Array): void;
|
|
101
|
+
/** @internal Audio cursor for the phone runtime; not a miniapp API. */
|
|
102
|
+
getAudioPosition(): AudioPosition | null;
|
|
85
103
|
|
|
86
104
|
getStatus(): RuntimeSnapshot;
|
|
87
105
|
|
|
@@ -454,6 +472,10 @@ export class Runtime implements RuntimeModule {
|
|
|
454
472
|
return { ...this.status };
|
|
455
473
|
}
|
|
456
474
|
|
|
475
|
+
getAudioPosition(): AudioPosition | null {
|
|
476
|
+
return this.audio.audioPosition;
|
|
477
|
+
}
|
|
478
|
+
|
|
457
479
|
// --- Camera: managed photo/stream (delegated) -----------------------------
|
|
458
480
|
|
|
459
481
|
requestManagedPhoto(): Promise<{ requestId: string; readUrl: string }> {
|