@mentra/sdk 2.1.27 → 2.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.
- package/dist/app/session/api-client.d.ts.map +1 -1
- package/dist/app/session/dashboard.d.ts +5 -8
- package/dist/app/session/dashboard.d.ts.map +1 -1
- package/dist/app/session/events.d.ts +2 -1
- package/dist/app/session/events.d.ts.map +1 -1
- package/dist/app/session/index.d.ts +62 -3
- package/dist/app/session/index.d.ts.map +1 -1
- package/dist/app/session/modules/audio.d.ts +33 -4
- package/dist/app/session/modules/audio.d.ts.map +1 -1
- package/dist/app/session/modules/camera-managed-extension.d.ts +2 -3
- package/dist/app/session/modules/camera-managed-extension.d.ts.map +1 -1
- package/dist/app/session/modules/camera.d.ts +5 -5
- package/dist/app/session/modules/camera.d.ts.map +1 -1
- package/dist/app/session/modules/led.d.ts +141 -0
- package/dist/app/session/modules/led.d.ts.map +1 -0
- package/dist/app/session/modules/location.d.ts +1 -2
- package/dist/app/session/modules/location.d.ts.map +1 -1
- package/dist/app/session/modules/simple-storage.d.ts.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5347 -112
- package/dist/index.js.map +45 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/logging/logger.d.ts.map +1 -1
- package/dist/types/capabilities.d.ts +3 -0
- package/dist/types/capabilities.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -14
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/message-types.d.ts +8 -1
- package/dist/types/message-types.d.ts.map +1 -1
- package/dist/types/messages/app-to-cloud.d.ts +48 -2
- package/dist/types/messages/app-to-cloud.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-app.d.ts +16 -6
- package/dist/types/messages/cloud-to-app.d.ts.map +1 -1
- package/dist/types/messages/cloud-to-glasses.d.ts +29 -1
- package/dist/types/messages/cloud-to-glasses.d.ts.map +1 -1
- package/dist/types/messages/glasses-to-cloud.d.ts +24 -1
- package/dist/types/messages/glasses-to-cloud.d.ts.map +1 -1
- package/dist/types/rtmp-stream.d.ts +1 -1
- package/dist/types/rtmp-stream.d.ts.map +1 -1
- package/dist/types/streams.d.ts +28 -1
- package/dist/types/streams.d.ts.map +1 -1
- package/package.json +9 -3
- package/dist/app/index.js +0 -24
- package/dist/app/server/index.js +0 -658
- package/dist/app/session/api-client.js +0 -101
- package/dist/app/session/dashboard.js +0 -149
- package/dist/app/session/events.js +0 -315
- package/dist/app/session/index.js +0 -1573
- package/dist/app/session/layouts.js +0 -372
- package/dist/app/session/modules/audio.js +0 -321
- package/dist/app/session/modules/camera-managed-extension.js +0 -310
- package/dist/app/session/modules/camera.js +0 -607
- package/dist/app/session/modules/index.js +0 -19
- package/dist/app/session/modules/location.js +0 -61
- package/dist/app/session/modules/simple-storage.js +0 -232
- package/dist/app/session/settings.js +0 -358
- package/dist/app/token/index.js +0 -22
- package/dist/app/token/utils.js +0 -144
- package/dist/app/webview/index.js +0 -382
- package/dist/constants/index.js +0 -16
- package/dist/constants/log-messages/color.js +0 -14
- package/dist/constants/log-messages/logos.js +0 -48
- package/dist/constants/log-messages/updates.js +0 -55
- package/dist/constants/log-messages/warning.js +0 -89
- package/dist/examples/managed-rtmp-streaming-example.js +0 -158
- package/dist/examples/managed-rtmp-streaming-with-restream-example.js +0 -124
- package/dist/examples/rtmp-streaming-example.js +0 -102
- package/dist/logging/logger.js +0 -79
- package/dist/types/capabilities.js +0 -9
- package/dist/types/dashboard/index.js +0 -12
- package/dist/types/enums.js +0 -75
- package/dist/types/index.js +0 -101
- package/dist/types/layouts.js +0 -3
- package/dist/types/message-types.js +0 -212
- package/dist/types/messages/app-to-cloud.js +0 -95
- package/dist/types/messages/base.js +0 -3
- package/dist/types/messages/cloud-to-app.js +0 -78
- package/dist/types/messages/cloud-to-glasses.js +0 -68
- package/dist/types/messages/glasses-to-cloud.js +0 -140
- package/dist/types/models.js +0 -101
- package/dist/types/photo-data.js +0 -2
- package/dist/types/rtmp-stream.js +0 -3
- package/dist/types/streams.js +0 -306
- package/dist/types/token.js +0 -7
- package/dist/types/webhooks.js +0 -28
- package/dist/utils/animation-utils.js +0 -340
- package/dist/utils/bitmap-utils.js +0 -475
- package/dist/utils/permissions-utils.js +0 -263
- package/dist/utils/resource-tracker.js +0 -153
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Simple Storage SDK Module for MentraOS Apps
|
|
4
|
-
* Provides localStorage-like API with cloud synchronization
|
|
5
|
-
*/
|
|
6
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
-
};
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.SimpleStorage = void 0;
|
|
11
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
-
/**
|
|
13
|
-
* Key-value storage with local caching and cloud sync
|
|
14
|
-
* Data is isolated by userId and packageName
|
|
15
|
-
*/
|
|
16
|
-
class SimpleStorage {
|
|
17
|
-
constructor(appSession) {
|
|
18
|
-
this.storage = null;
|
|
19
|
-
this.appSession = appSession;
|
|
20
|
-
this.userId = appSession.userId;
|
|
21
|
-
this.packageName = appSession.getPackageName();
|
|
22
|
-
this.baseUrl = this.getBaseUrl();
|
|
23
|
-
}
|
|
24
|
-
// Convert WebSocket URL to HTTP for API calls
|
|
25
|
-
getBaseUrl() {
|
|
26
|
-
const serverUrl = this.appSession.getServerUrl();
|
|
27
|
-
if (!serverUrl)
|
|
28
|
-
return "http://localhost:8002";
|
|
29
|
-
return serverUrl.replace(/\/app-ws$/, "").replace(/^ws/, "http");
|
|
30
|
-
}
|
|
31
|
-
// Generate auth headers for API requests
|
|
32
|
-
getAuthHeaders() {
|
|
33
|
-
const apiKey = this.appSession.config?.apiKey || "unknown-api-key";
|
|
34
|
-
return {
|
|
35
|
-
Authorization: `Bearer ${this.packageName}:${apiKey}`,
|
|
36
|
-
"Content-Type": "application/json",
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
// Fetch all data from cloud and cache locally
|
|
40
|
-
async fetchStorageFromCloud() {
|
|
41
|
-
try {
|
|
42
|
-
const response = await (0, node_fetch_1.default)(`${this.baseUrl}/api/sdk/simple-storage/${encodeURIComponent(this.userId)}`, {
|
|
43
|
-
headers: this.getAuthHeaders(),
|
|
44
|
-
});
|
|
45
|
-
if (response.ok) {
|
|
46
|
-
const result = await response.json();
|
|
47
|
-
if (result.success && result.data) {
|
|
48
|
-
this.storage = result.data;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
this.storage = {};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
console.error("Failed to fetch storage from cloud:", await response.text());
|
|
56
|
-
this.storage = {};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
console.error("Error fetching storage from cloud:", error);
|
|
61
|
-
this.storage = {};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
// Get item from cache or cloud
|
|
65
|
-
async get(key) {
|
|
66
|
-
try {
|
|
67
|
-
if (this.storage !== null && this.storage !== undefined) {
|
|
68
|
-
return this.storage[key];
|
|
69
|
-
}
|
|
70
|
-
await this.fetchStorageFromCloud();
|
|
71
|
-
return this.storage?.[key];
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
console.error("Error getting item:", error);
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
// Set item with optimistic update and cloud sync
|
|
79
|
-
async set(key, value) {
|
|
80
|
-
try {
|
|
81
|
-
if (this.storage === null || this.storage === undefined) {
|
|
82
|
-
await this.fetchStorageFromCloud();
|
|
83
|
-
}
|
|
84
|
-
// Update cache immediately (optimistic update)
|
|
85
|
-
if (this.storage) {
|
|
86
|
-
this.storage[key] = value;
|
|
87
|
-
}
|
|
88
|
-
// Sync to cloud
|
|
89
|
-
const response = await (0, node_fetch_1.default)(`${this.baseUrl}/api/sdk/simple-storage/${encodeURIComponent(this.userId)}/${encodeURIComponent(key)}`, {
|
|
90
|
-
method: "PUT",
|
|
91
|
-
headers: this.getAuthHeaders(),
|
|
92
|
-
body: JSON.stringify({ value }),
|
|
93
|
-
});
|
|
94
|
-
if (!response.ok) {
|
|
95
|
-
console.error("Failed to sync item to cloud:", await response.text());
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
catch (error) {
|
|
99
|
-
console.error("Error setting item:", error);
|
|
100
|
-
throw error;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// Delete item from cache and cloud
|
|
104
|
-
async delete(key) {
|
|
105
|
-
try {
|
|
106
|
-
if (this.storage === null || this.storage === undefined) {
|
|
107
|
-
await this.fetchStorageFromCloud();
|
|
108
|
-
}
|
|
109
|
-
// Remove from cache
|
|
110
|
-
if (this.storage) {
|
|
111
|
-
delete this.storage[key];
|
|
112
|
-
}
|
|
113
|
-
// Sync to cloud
|
|
114
|
-
const response = await (0, node_fetch_1.default)(`${this.baseUrl}/api/sdk/simple-storage/${encodeURIComponent(this.userId)}/${encodeURIComponent(key)}`, {
|
|
115
|
-
method: "DELETE",
|
|
116
|
-
headers: this.getAuthHeaders(),
|
|
117
|
-
});
|
|
118
|
-
if (response.ok) {
|
|
119
|
-
const result = await response.json();
|
|
120
|
-
return result.success;
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
console.error("Failed to delete item from cloud:", await response.text());
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
console.error("Error deleting item:", error);
|
|
129
|
-
return false;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
// Clear all data from cache and cloud
|
|
133
|
-
async clear() {
|
|
134
|
-
try {
|
|
135
|
-
this.storage = {};
|
|
136
|
-
const response = await (0, node_fetch_1.default)(`${this.baseUrl}/api/sdk/simple-storage/${encodeURIComponent(this.userId)}`, {
|
|
137
|
-
method: "DELETE",
|
|
138
|
-
headers: this.getAuthHeaders(),
|
|
139
|
-
});
|
|
140
|
-
if (response.ok) {
|
|
141
|
-
const result = await response.json();
|
|
142
|
-
return result.success;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
console.error("Failed to clear storage from cloud:", await response.text());
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (error) {
|
|
150
|
-
console.error("Error clearing storage:", error);
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Get all storage keys
|
|
155
|
-
async keys() {
|
|
156
|
-
try {
|
|
157
|
-
if (this.storage === null || this.storage === undefined) {
|
|
158
|
-
await this.fetchStorageFromCloud();
|
|
159
|
-
}
|
|
160
|
-
return Object.keys(this.storage || {});
|
|
161
|
-
}
|
|
162
|
-
catch (error) {
|
|
163
|
-
console.error("Error getting keys:", error);
|
|
164
|
-
return [];
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
// Get number of stored items
|
|
168
|
-
async size() {
|
|
169
|
-
try {
|
|
170
|
-
if (this.storage === null || this.storage === undefined) {
|
|
171
|
-
await this.fetchStorageFromCloud();
|
|
172
|
-
}
|
|
173
|
-
return Object.keys(this.storage || {}).length;
|
|
174
|
-
}
|
|
175
|
-
catch (error) {
|
|
176
|
-
console.error("Error getting storage size:", error);
|
|
177
|
-
return 0;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
// Check if key exists
|
|
181
|
-
async hasKey(key) {
|
|
182
|
-
try {
|
|
183
|
-
if (this.storage === null || this.storage === undefined) {
|
|
184
|
-
await this.fetchStorageFromCloud();
|
|
185
|
-
}
|
|
186
|
-
return key in (this.storage || {});
|
|
187
|
-
}
|
|
188
|
-
catch (error) {
|
|
189
|
-
console.error("Error checking key:", error);
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
// Get copy of all stored data
|
|
194
|
-
async getAllData() {
|
|
195
|
-
try {
|
|
196
|
-
if (this.storage === null || this.storage === undefined) {
|
|
197
|
-
await this.fetchStorageFromCloud();
|
|
198
|
-
}
|
|
199
|
-
return { ...(this.storage || {}) };
|
|
200
|
-
}
|
|
201
|
-
catch (error) {
|
|
202
|
-
console.error("Error getting all data:", error);
|
|
203
|
-
return {};
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
// Set multiple items at once
|
|
207
|
-
async setMultiple(data) {
|
|
208
|
-
try {
|
|
209
|
-
if (this.storage === null || this.storage === undefined) {
|
|
210
|
-
await this.fetchStorageFromCloud();
|
|
211
|
-
}
|
|
212
|
-
// Update cache
|
|
213
|
-
if (this.storage) {
|
|
214
|
-
Object.assign(this.storage, data);
|
|
215
|
-
}
|
|
216
|
-
// Bulk upsert to cloud
|
|
217
|
-
const response = await (0, node_fetch_1.default)(`${this.baseUrl}/api/sdk/simple-storage/${encodeURIComponent(this.userId)}`, {
|
|
218
|
-
method: "PUT",
|
|
219
|
-
headers: this.getAuthHeaders(),
|
|
220
|
-
body: JSON.stringify({ data }),
|
|
221
|
-
});
|
|
222
|
-
if (!response.ok) {
|
|
223
|
-
console.error("Failed to upsert multiple items to cloud:", await response.text());
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
catch (error) {
|
|
227
|
-
console.error("Error setting multiple items:", error);
|
|
228
|
-
throw error;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.SimpleStorage = SimpleStorage;
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.SettingsManager = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* 🔧 Settings Manager Module
|
|
9
|
-
*
|
|
10
|
-
* Manages App settings with automatic synchronization and change notifications.
|
|
11
|
-
* Provides type-safe access to settings with default values.
|
|
12
|
-
*/
|
|
13
|
-
const events_1 = __importDefault(require("events"));
|
|
14
|
-
const api_client_1 = require("./api-client");
|
|
15
|
-
const logger_1 = require("../../logging/logger"); // Adjust import path as needed
|
|
16
|
-
/**
|
|
17
|
-
* Internal event names
|
|
18
|
-
*/
|
|
19
|
-
var SettingsEvents;
|
|
20
|
-
(function (SettingsEvents) {
|
|
21
|
-
SettingsEvents["CHANGE"] = "settings:change";
|
|
22
|
-
SettingsEvents["VALUE_CHANGE"] = "settings:value:";
|
|
23
|
-
})(SettingsEvents || (SettingsEvents = {}));
|
|
24
|
-
/**
|
|
25
|
-
* 🔧 Settings Manager
|
|
26
|
-
*
|
|
27
|
-
* Provides a type-safe interface for accessing and reacting to App settings.
|
|
28
|
-
* Automatically synchronizes with MentraOS Cloud.
|
|
29
|
-
*/
|
|
30
|
-
class SettingsManager {
|
|
31
|
-
/**
|
|
32
|
-
* Create a new settings manager
|
|
33
|
-
*
|
|
34
|
-
* @param initialSettings Initial settings values (if available)
|
|
35
|
-
* @param packageName Package name for the App
|
|
36
|
-
* @param wsUrl WebSocket URL (for deriving HTTP API URL)
|
|
37
|
-
* @param userId User ID (for authenticated requests)
|
|
38
|
-
* @param subscribeFn Optional function to call to subscribe to streams
|
|
39
|
-
*/
|
|
40
|
-
constructor(initialSettings = [], packageName, wsUrl, userId, subscribeFn) {
|
|
41
|
-
// Current settings values
|
|
42
|
-
this.settings = [];
|
|
43
|
-
// Event emitter for change notifications
|
|
44
|
-
this.emitter = new events_1.default();
|
|
45
|
-
// --- MentraOS settings event system ---
|
|
46
|
-
this.mentraosSettings = {};
|
|
47
|
-
this.mentraosEmitter = new events_1.default();
|
|
48
|
-
this.settings = [...initialSettings];
|
|
49
|
-
this.subscribeFn = subscribeFn; // Store the subscribe function
|
|
50
|
-
// Create API client if we have enough information
|
|
51
|
-
if (packageName) {
|
|
52
|
-
this.apiClient = new api_client_1.ApiClient(packageName, wsUrl, userId);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Configure the API client
|
|
57
|
-
*
|
|
58
|
-
* @param packageName Package name for the App
|
|
59
|
-
* @param wsUrl WebSocket URL
|
|
60
|
-
* @param userId User ID
|
|
61
|
-
*/
|
|
62
|
-
configureApiClient(packageName, wsUrl, userId) {
|
|
63
|
-
if (!this.apiClient) {
|
|
64
|
-
this.apiClient = new api_client_1.ApiClient(packageName, wsUrl, userId);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
this.apiClient.setWebSocketUrl(wsUrl);
|
|
68
|
-
this.apiClient.setUserId(userId);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Update the current settings
|
|
73
|
-
* This is called internally when settings are loaded or changed
|
|
74
|
-
*
|
|
75
|
-
* @param newSettings New settings values
|
|
76
|
-
* @returns Map of changed settings
|
|
77
|
-
*/
|
|
78
|
-
updateSettings(newSettings) {
|
|
79
|
-
const changes = {};
|
|
80
|
-
// Copy the new settings
|
|
81
|
-
const updatedSettings = [...newSettings];
|
|
82
|
-
// Detect changes comparing old and new settings
|
|
83
|
-
for (const newSetting of updatedSettings) {
|
|
84
|
-
const oldSetting = this.settings.find((s) => s.key === newSetting.key);
|
|
85
|
-
// Skip if value hasn't changed
|
|
86
|
-
if (oldSetting && this.areEqual(oldSetting.value, newSetting.value)) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
// Record change
|
|
90
|
-
changes[newSetting.key] = {
|
|
91
|
-
oldValue: oldSetting?.value,
|
|
92
|
-
newValue: newSetting.value,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
// Check for removed settings
|
|
96
|
-
for (const oldSetting of this.settings) {
|
|
97
|
-
const stillExists = updatedSettings.some((s) => s.key === oldSetting.key);
|
|
98
|
-
if (!stillExists) {
|
|
99
|
-
changes[oldSetting.key] = {
|
|
100
|
-
oldValue: oldSetting.value,
|
|
101
|
-
newValue: undefined,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
// If there are changes, update the settings and emit events
|
|
106
|
-
if (Object.keys(changes).length > 0) {
|
|
107
|
-
this.settings = updatedSettings;
|
|
108
|
-
this.emitChanges(changes);
|
|
109
|
-
}
|
|
110
|
-
return changes;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Check if two setting values are equal
|
|
114
|
-
*
|
|
115
|
-
* @param a First value
|
|
116
|
-
* @param b Second value
|
|
117
|
-
* @returns True if the values are equal
|
|
118
|
-
*/
|
|
119
|
-
areEqual(a, b) {
|
|
120
|
-
// Simple equality check - for objects, this won't do a deep equality check
|
|
121
|
-
// but for most setting values (strings, numbers, booleans) it works
|
|
122
|
-
return a === b;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Emit change events for updated settings
|
|
126
|
-
*
|
|
127
|
-
* @param changes Map of changed settings
|
|
128
|
-
*/
|
|
129
|
-
emitChanges(changes) {
|
|
130
|
-
// Emit the general change event
|
|
131
|
-
this.emitter.emit(SettingsEvents.CHANGE, changes);
|
|
132
|
-
// Emit individual value change events
|
|
133
|
-
for (const [key, change] of Object.entries(changes)) {
|
|
134
|
-
this.emitter.emit(`${SettingsEvents.VALUE_CHANGE}${key}`, change.newValue, change.oldValue);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* 🔄 Listen for changes to any setting
|
|
139
|
-
*
|
|
140
|
-
* @param handler Function to call when settings change
|
|
141
|
-
* @returns Function to remove the listener
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* ```typescript
|
|
145
|
-
* settings.onChange((changes) => {
|
|
146
|
-
* console.log('Settings changed:', changes);
|
|
147
|
-
* });
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
onChange(handler) {
|
|
151
|
-
this.emitter.on(SettingsEvents.CHANGE, handler);
|
|
152
|
-
return () => this.emitter.off(SettingsEvents.CHANGE, handler);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* 🔄 Listen for changes to a specific setting
|
|
156
|
-
*
|
|
157
|
-
* @param key Setting key to monitor
|
|
158
|
-
* @param handler Function to call when the setting changes
|
|
159
|
-
* @returns Function to remove the listener
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```typescript
|
|
163
|
-
* settings.onValueChange('transcribe_language', (newValue, oldValue) => {
|
|
164
|
-
* console.log(`Language changed from ${oldValue} to ${newValue}`);
|
|
165
|
-
* });
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
onValueChange(key, handler) {
|
|
169
|
-
const eventName = `${SettingsEvents.VALUE_CHANGE}${key}`;
|
|
170
|
-
this.emitter.on(eventName, handler);
|
|
171
|
-
return () => this.emitter.off(eventName, handler);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* 🔍 Check if a setting exists
|
|
175
|
-
*
|
|
176
|
-
* @param key Setting key to check
|
|
177
|
-
* @returns True if the setting exists
|
|
178
|
-
*/
|
|
179
|
-
has(key) {
|
|
180
|
-
return this.settings.some((s) => s.key === key);
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 🔍 Get all settings
|
|
184
|
-
*
|
|
185
|
-
* @returns Copy of all settings
|
|
186
|
-
*/
|
|
187
|
-
getAll() {
|
|
188
|
-
return [...this.settings];
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* 🔍 Get a setting value with type safety
|
|
192
|
-
*
|
|
193
|
-
* @param key Setting key to get
|
|
194
|
-
* @param defaultValue Default value if setting doesn't exist or is undefined
|
|
195
|
-
* @returns Setting value or default value
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* const lineWidth = settings.get<number>('line_width', 30);
|
|
200
|
-
* const language = settings.get<string>('transcribe_language', 'English');
|
|
201
|
-
* ```
|
|
202
|
-
*/
|
|
203
|
-
get(key, defaultValue) {
|
|
204
|
-
const setting = this.settings.find((s) => s.key === key);
|
|
205
|
-
if (setting && setting.value !== undefined) {
|
|
206
|
-
return setting.value;
|
|
207
|
-
}
|
|
208
|
-
return defaultValue;
|
|
209
|
-
}
|
|
210
|
-
/**
|
|
211
|
-
* 🎛️ Get an MentraOS system setting value with optional default
|
|
212
|
-
*
|
|
213
|
-
* @param key MentraOS setting key (e.g., 'metricSystemEnabled', 'brightness')
|
|
214
|
-
* @param defaultValue Default value to return if the setting is not found
|
|
215
|
-
* @returns The setting value or the default value
|
|
216
|
-
*
|
|
217
|
-
* @example
|
|
218
|
-
* ```typescript
|
|
219
|
-
* const isMetric = settings.getMentraOS<boolean>('metricSystemEnabled', false);
|
|
220
|
-
* const brightness = settings.getMentraOS<number>('brightness', 50);
|
|
221
|
-
* ```
|
|
222
|
-
*/
|
|
223
|
-
getMentraOS(key, defaultValue) {
|
|
224
|
-
const value = this.mentraosSettings[key];
|
|
225
|
-
if (value !== undefined) {
|
|
226
|
-
return value;
|
|
227
|
-
}
|
|
228
|
-
return defaultValue;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* 🔍 Find a setting by key
|
|
232
|
-
*
|
|
233
|
-
* @param key Setting key to find
|
|
234
|
-
* @returns Setting object or undefined
|
|
235
|
-
*/
|
|
236
|
-
getSetting(key) {
|
|
237
|
-
return this.settings.find((s) => s.key === key);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* 🔄 Fetch settings from the cloud
|
|
241
|
-
* This is generally not needed since settings are automatically kept in sync,
|
|
242
|
-
* but can be used to force a refresh if needed.
|
|
243
|
-
*
|
|
244
|
-
* @returns Promise that resolves to the updated settings
|
|
245
|
-
* @throws Error if the API client is not configured or the request fails
|
|
246
|
-
*/
|
|
247
|
-
async fetch() {
|
|
248
|
-
if (!this.apiClient) {
|
|
249
|
-
throw new Error("Settings API client is not configured");
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
const newSettings = await this.apiClient.fetchSettings();
|
|
253
|
-
this.updateSettings(newSettings);
|
|
254
|
-
return this.settings;
|
|
255
|
-
}
|
|
256
|
-
catch (error) {
|
|
257
|
-
console.error("Error fetching settings:", error);
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* 🎛️ Listen for changes to a specific MentraOS setting (e.g., metricSystemEnabled)
|
|
263
|
-
*
|
|
264
|
-
* @param key The mentraosSettings key to listen for (e.g., 'metricSystemEnabled')
|
|
265
|
-
* @param handler Function to call when the value changes
|
|
266
|
-
* @returns Function to remove the listener
|
|
267
|
-
*
|
|
268
|
-
* @example
|
|
269
|
-
* ```typescript
|
|
270
|
-
* settings.onMentraosChange('metricSystemEnabled', (isMetric, wasMetric) => {
|
|
271
|
-
* console.log(`Units changed: ${wasMetric ? 'metric' : 'imperial'} → ${isMetric ? 'metric' : 'imperial'}`);
|
|
272
|
-
* });
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
onMentraosChange(key, handler) {
|
|
276
|
-
return this.onMentraosSettingChange(key, handler);
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Listen for changes to a specific MentraOS setting (e.g., metricSystemEnabled)
|
|
280
|
-
* This is a convenience wrapper for onValueChange for well-known mentraosSettings keys.
|
|
281
|
-
* @param key The mentraosSettings key to listen for (e.g., 'metricSystemEnabled')
|
|
282
|
-
* @param handler Function to call when the value changes
|
|
283
|
-
* @returns Function to remove the listener
|
|
284
|
-
* @deprecated Use onMentraosChange instead
|
|
285
|
-
*/
|
|
286
|
-
onMentraosSettingsChange(key, handler) {
|
|
287
|
-
return this.onMentraosSettingChange(key, handler);
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Update the current MentraOS settings
|
|
291
|
-
* Compares new and old values, emits per-key events, and updates stored values.
|
|
292
|
-
* @param newSettings The new MentraOS settings object
|
|
293
|
-
*/
|
|
294
|
-
updateMentraosSettings(newSettings) {
|
|
295
|
-
const oldSettings = this.mentraosSettings;
|
|
296
|
-
logger_1.logger.debug({ newSettings }, `[SettingsManager] Updating MentraOS settings. New settings`);
|
|
297
|
-
for (const key of Object.keys(newSettings)) {
|
|
298
|
-
const oldValue = oldSettings[key];
|
|
299
|
-
const newValue = newSettings[key];
|
|
300
|
-
if (oldValue !== newValue) {
|
|
301
|
-
logger_1.logger.info(`[SettingsManager] MentraOS setting '${key}' changed: ${oldValue} -> ${newValue}. Emitting event.`);
|
|
302
|
-
this.mentraosEmitter.emit(`augmentos:value:${key}`, newValue, oldValue);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
// Also handle keys that might have been removed from newSettings but existed in oldSettings
|
|
306
|
-
for (const key of Object.keys(oldSettings)) {
|
|
307
|
-
if (!(key in newSettings)) {
|
|
308
|
-
logger_1.logger.info(`[SettingsManager] MentraOS setting '${key}' removed. Old value: ${oldSettings[key]}. Emitting event with undefined newValue.`);
|
|
309
|
-
this.mentraosEmitter.emit(`augmentos:value:${key}`, undefined, oldSettings[key]);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
this.mentraosSettings = { ...newSettings };
|
|
313
|
-
logger_1.logger.debug({ mentraosSettings: this.mentraosSettings }, `[SettingsManager] Finished updating MentraOS settings. Current state:`);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Subscribe to changes for a specific MentraOS setting (e.g., 'metricSystemEnabled')
|
|
317
|
-
* @param key The MentraOS setting key to listen for
|
|
318
|
-
* @param handler Function to call when the value changes (newValue, oldValue)
|
|
319
|
-
* @returns Function to remove the listener
|
|
320
|
-
*/
|
|
321
|
-
onMentraosSettingChange(key, handler) {
|
|
322
|
-
const eventName = `augmentos:value:${key}`;
|
|
323
|
-
logger_1.logger.info(`[SettingsManager] Registering handler for MentraOS setting '${key}' on event '${eventName}'.`);
|
|
324
|
-
this.mentraosEmitter.on(eventName, (...args) => {
|
|
325
|
-
logger_1.logger.info({ args }, `[SettingsManager] MentraOS setting '${key}' event fired. Args:`);
|
|
326
|
-
handler(...args);
|
|
327
|
-
});
|
|
328
|
-
if (this.subscribeFn) {
|
|
329
|
-
const subscriptionKey = `augmentos:${key}`;
|
|
330
|
-
logger_1.logger.info(`[SettingsManager] Calling subscribeFn for stream '${subscriptionKey}'.`);
|
|
331
|
-
this.subscribeFn([subscriptionKey])
|
|
332
|
-
.then(() => {
|
|
333
|
-
logger_1.logger.info(`[SettingsManager] subscribeFn resolved for stream '${subscriptionKey}'.`);
|
|
334
|
-
})
|
|
335
|
-
.catch((err) => {
|
|
336
|
-
logger_1.logger.error(`[SettingsManager] subscribeFn failed for stream '${subscriptionKey}':`, err);
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
else {
|
|
340
|
-
logger_1.logger.warn(`[SettingsManager] 'subscribeFn' not provided. Cannot auto-subscribe for MentraOS setting '${key}'. Manual App subscription might be required.`);
|
|
341
|
-
}
|
|
342
|
-
return () => {
|
|
343
|
-
logger_1.logger.info(`[SettingsManager] Unregistering handler for MentraOS setting '${key}' from event '${eventName}'.`);
|
|
344
|
-
this.mentraosEmitter.off(eventName, handler);
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
/**
|
|
348
|
-
* Get the current value of an MentraOS setting
|
|
349
|
-
*/
|
|
350
|
-
getMentraosSetting(key, defaultValue) {
|
|
351
|
-
console.log(`[SettingsManager] Getting MentraOS setting '${key}' with settings:`, this.mentraosSettings);
|
|
352
|
-
if (key in this.mentraosSettings) {
|
|
353
|
-
return this.mentraosSettings[key];
|
|
354
|
-
}
|
|
355
|
-
return defaultValue;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
exports.SettingsManager = SettingsManager;
|
package/dist/app/token/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
/**
|
|
18
|
-
* 🔐 App Token Module
|
|
19
|
-
*
|
|
20
|
-
* Provides utilities for working with App tokens.
|
|
21
|
-
*/
|
|
22
|
-
__exportStar(require("./utils"), exports);
|