@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,263 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cameraWarnLog = exports.postNotificationWarnLog = exports.readNotificationWarnLog = exports.calendarWarnLog = exports.backgroundLocationWarnLog = exports.locationWarnLog = exports.microPhoneWarnLog = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* permissions-utils.ts
|
|
6
|
-
*
|
|
7
|
-
* This file provides runtime permission validation utilities for the MentraOS SDK.
|
|
8
|
-
*
|
|
9
|
-
* Each function queries the public permissions API endpoint to check if an app
|
|
10
|
-
* has declared the required permission for a specific feature. If the permission
|
|
11
|
-
* is missing, a styled warning message is displayed in the terminal.
|
|
12
|
-
*
|
|
13
|
-
* Key features:
|
|
14
|
-
* - Fetches app permissions from /api/public/permissions/:packageName
|
|
15
|
-
* - Gracefully handles offline/unreachable endpoints (silent failure)
|
|
16
|
-
* - Displays professional bordered warnings when permissions are missing
|
|
17
|
-
* - Non-blocking - allows app execution to continue even if checks fail
|
|
18
|
-
*
|
|
19
|
-
* These functions are called automatically by SDK methods that require specific
|
|
20
|
-
* permissions (e.g., microphone access, location tracking, camera, etc.) to help
|
|
21
|
-
* developers identify missing permission declarations during development.
|
|
22
|
-
*/
|
|
23
|
-
const warning_1 = require("../constants/log-messages/warning");
|
|
24
|
-
// Check if app has microphone permission, warn if missing
|
|
25
|
-
const microPhoneWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
26
|
-
if (!cloudServerUrl)
|
|
27
|
-
return;
|
|
28
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
29
|
-
// console.log(`Fetching permissions from: ${permissionsUrl}`);
|
|
30
|
-
fetch(permissionsUrl)
|
|
31
|
-
.then(async (res) => {
|
|
32
|
-
const contentType = res.headers.get("content-type");
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
if (contentType && contentType.includes("application/json")) {
|
|
38
|
-
return (await res.json());
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
const text = await res.text();
|
|
42
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
.then((data) => {
|
|
47
|
-
if (data) {
|
|
48
|
-
const hasMic = data.permissions.some((p) => p.type === "MICROPHONE");
|
|
49
|
-
if (!hasMic) {
|
|
50
|
-
console.log((0, warning_1.noMicrophoneWarn)(funcName, packageName));
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
.catch((err) => {
|
|
55
|
-
// Silently fail if endpoint is unreachable - don't block execution
|
|
56
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
exports.microPhoneWarnLog = microPhoneWarnLog;
|
|
60
|
-
// Check if app has location permission, warn if missing
|
|
61
|
-
const locationWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
62
|
-
if (!cloudServerUrl)
|
|
63
|
-
return;
|
|
64
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
65
|
-
fetch(permissionsUrl)
|
|
66
|
-
.then(async (res) => {
|
|
67
|
-
const contentType = res.headers.get("content-type");
|
|
68
|
-
if (!res.ok) {
|
|
69
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
if (contentType && contentType.includes("application/json")) {
|
|
73
|
-
return (await res.json());
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
const text = await res.text();
|
|
77
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
.then((data) => {
|
|
82
|
-
if (data) {
|
|
83
|
-
const hasLocation = data.permissions.some((p) => p.type === "LOCATION");
|
|
84
|
-
if (!hasLocation) {
|
|
85
|
-
console.log((0, warning_1.locationWarn)(funcName, packageName));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
.catch((err) => {
|
|
90
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
exports.locationWarnLog = locationWarnLog;
|
|
94
|
-
// Check if app has background location permission, warn if missing
|
|
95
|
-
const backgroundLocationWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
96
|
-
if (!cloudServerUrl)
|
|
97
|
-
return;
|
|
98
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
99
|
-
fetch(permissionsUrl)
|
|
100
|
-
.then(async (res) => {
|
|
101
|
-
const contentType = res.headers.get("content-type");
|
|
102
|
-
if (!res.ok) {
|
|
103
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
if (contentType && contentType.includes("application/json")) {
|
|
107
|
-
return (await res.json());
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
const text = await res.text();
|
|
111
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
})
|
|
115
|
-
.then((data) => {
|
|
116
|
-
if (data) {
|
|
117
|
-
const hasBackgroundLocation = data.permissions.some((p) => p.type === "BACKGROUND_LOCATION");
|
|
118
|
-
if (!hasBackgroundLocation) {
|
|
119
|
-
console.log((0, warning_1.baackgroundLocationWarn)(funcName, packageName));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
})
|
|
123
|
-
.catch((err) => {
|
|
124
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
exports.backgroundLocationWarnLog = backgroundLocationWarnLog;
|
|
128
|
-
// Check if app has calendar permission, warn if missing
|
|
129
|
-
const calendarWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
130
|
-
if (!cloudServerUrl)
|
|
131
|
-
return;
|
|
132
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
133
|
-
fetch(permissionsUrl)
|
|
134
|
-
.then(async (res) => {
|
|
135
|
-
const contentType = res.headers.get("content-type");
|
|
136
|
-
if (!res.ok) {
|
|
137
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
if (contentType && contentType.includes("application/json")) {
|
|
141
|
-
return (await res.json());
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const text = await res.text();
|
|
145
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
146
|
-
return null;
|
|
147
|
-
}
|
|
148
|
-
})
|
|
149
|
-
.then((data) => {
|
|
150
|
-
if (data) {
|
|
151
|
-
const hasCalendar = data.permissions.some((p) => p.type === "CALENDAR");
|
|
152
|
-
if (!hasCalendar) {
|
|
153
|
-
console.log((0, warning_1.calendarWarn)(funcName, packageName));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
})
|
|
157
|
-
.catch((err) => {
|
|
158
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
159
|
-
});
|
|
160
|
-
};
|
|
161
|
-
exports.calendarWarnLog = calendarWarnLog;
|
|
162
|
-
// Check if app has read notifications permission, warn if missing
|
|
163
|
-
const readNotificationWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
164
|
-
if (!cloudServerUrl)
|
|
165
|
-
return;
|
|
166
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
167
|
-
fetch(permissionsUrl)
|
|
168
|
-
.then(async (res) => {
|
|
169
|
-
const contentType = res.headers.get("content-type");
|
|
170
|
-
if (!res.ok) {
|
|
171
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
if (contentType && contentType.includes("application/json")) {
|
|
175
|
-
return (await res.json());
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const text = await res.text();
|
|
179
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
180
|
-
return null;
|
|
181
|
-
}
|
|
182
|
-
})
|
|
183
|
-
.then((data) => {
|
|
184
|
-
if (data) {
|
|
185
|
-
const hasReadNotifications = data.permissions.some((p) => p.type === "READ_NOTIFICATIONS");
|
|
186
|
-
if (!hasReadNotifications) {
|
|
187
|
-
console.log((0, warning_1.readNotficationWarn)(funcName, packageName));
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
.catch((err) => {
|
|
192
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
193
|
-
});
|
|
194
|
-
};
|
|
195
|
-
exports.readNotificationWarnLog = readNotificationWarnLog;
|
|
196
|
-
// Check if app has post notifications permission, warn if missing
|
|
197
|
-
const postNotificationWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
198
|
-
if (!cloudServerUrl)
|
|
199
|
-
return;
|
|
200
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
201
|
-
fetch(permissionsUrl)
|
|
202
|
-
.then(async (res) => {
|
|
203
|
-
const contentType = res.headers.get("content-type");
|
|
204
|
-
if (!res.ok) {
|
|
205
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
if (contentType && contentType.includes("application/json")) {
|
|
209
|
-
return (await res.json());
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
const text = await res.text();
|
|
213
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
214
|
-
return null;
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
.then((data) => {
|
|
218
|
-
if (data) {
|
|
219
|
-
const hasPostNotifications = data.permissions.some((p) => p.type === "POST_NOTIFICATIONS");
|
|
220
|
-
if (!hasPostNotifications) {
|
|
221
|
-
console.log((0, warning_1.postNotficationWarn)(funcName, packageName));
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
})
|
|
225
|
-
.catch((err) => {
|
|
226
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
227
|
-
});
|
|
228
|
-
};
|
|
229
|
-
exports.postNotificationWarnLog = postNotificationWarnLog;
|
|
230
|
-
// Check if app has camera permission, warn if missing
|
|
231
|
-
const cameraWarnLog = (cloudServerUrl, packageName, funcName) => {
|
|
232
|
-
if (!cloudServerUrl)
|
|
233
|
-
return;
|
|
234
|
-
const permissionsUrl = `${cloudServerUrl}/api/public/permissions/${encodeURIComponent(packageName)}`;
|
|
235
|
-
fetch(permissionsUrl)
|
|
236
|
-
.then(async (res) => {
|
|
237
|
-
const contentType = res.headers.get("content-type");
|
|
238
|
-
if (!res.ok) {
|
|
239
|
-
console.warn(`Permission API returned ${res.status}: ${res.statusText}`);
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
if (contentType && contentType.includes("application/json")) {
|
|
243
|
-
return (await res.json());
|
|
244
|
-
}
|
|
245
|
-
else {
|
|
246
|
-
const text = await res.text();
|
|
247
|
-
console.warn(`Permission API returned non-JSON response: ${text}`);
|
|
248
|
-
return null;
|
|
249
|
-
}
|
|
250
|
-
})
|
|
251
|
-
.then((data) => {
|
|
252
|
-
if (data) {
|
|
253
|
-
const hasCamera = data.permissions.some((p) => p.type === "CAMERA");
|
|
254
|
-
if (!hasCamera) {
|
|
255
|
-
console.log((0, warning_1.cameraWarn)(funcName, packageName));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
})
|
|
259
|
-
.catch((err) => {
|
|
260
|
-
console.debug("Permission check skipped - endpoint unreachable:", err.message);
|
|
261
|
-
});
|
|
262
|
-
};
|
|
263
|
-
exports.cameraWarnLog = cameraWarnLog;
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Resource Tracker
|
|
4
|
-
*
|
|
5
|
-
* A utility class for tracking and automatically cleaning up resources
|
|
6
|
-
* like timers, event listeners, and other disposable objects.
|
|
7
|
-
*
|
|
8
|
-
* This helps prevent memory leaks by ensuring that all resources are
|
|
9
|
-
* properly disposed when they're no longer needed.
|
|
10
|
-
*/
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ResourceTracker = void 0;
|
|
13
|
-
exports.createResourceTracker = createResourceTracker;
|
|
14
|
-
/**
|
|
15
|
-
* Manages resources to prevent memory leaks
|
|
16
|
-
*/
|
|
17
|
-
class ResourceTracker {
|
|
18
|
-
constructor() {
|
|
19
|
-
// Collection of cleanup functions to call when dispose() is called
|
|
20
|
-
this.cleanupFunctions = [];
|
|
21
|
-
// Flag to track if this resource tracker has been disposed
|
|
22
|
-
this.isDisposed = false;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Add a cleanup function to be executed when dispose() is called
|
|
26
|
-
*
|
|
27
|
-
* @param cleanup - The cleanup function to register
|
|
28
|
-
* @returns A function that will remove this cleanup function
|
|
29
|
-
*/
|
|
30
|
-
track(cleanup) {
|
|
31
|
-
if (this.isDisposed) {
|
|
32
|
-
throw new Error('Cannot track resources on a disposed ResourceTracker');
|
|
33
|
-
}
|
|
34
|
-
this.cleanupFunctions.push(cleanup);
|
|
35
|
-
// Return a function that will remove this cleanup function
|
|
36
|
-
return () => {
|
|
37
|
-
const index = this.cleanupFunctions.indexOf(cleanup);
|
|
38
|
-
if (index !== -1) {
|
|
39
|
-
this.cleanupFunctions.splice(index, 1);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Track a disposable object (anything with a dispose or close method)
|
|
45
|
-
*
|
|
46
|
-
* @param disposable - The object to track
|
|
47
|
-
* @returns A function that will remove this disposable
|
|
48
|
-
*/
|
|
49
|
-
trackDisposable(disposable) {
|
|
50
|
-
return this.track(() => {
|
|
51
|
-
if (typeof disposable.dispose === 'function') {
|
|
52
|
-
disposable.dispose();
|
|
53
|
-
}
|
|
54
|
-
else if (typeof disposable.close === 'function') {
|
|
55
|
-
disposable.close();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Track a timer and ensure it gets cleared
|
|
61
|
-
*
|
|
62
|
-
* @param timerId - The timer ID to track
|
|
63
|
-
* @param isInterval - Whether this is an interval (true) or timeout (false)
|
|
64
|
-
* @returns A function that will remove this timer
|
|
65
|
-
*/
|
|
66
|
-
trackTimer(timerId, isInterval = false) {
|
|
67
|
-
return this.track(() => {
|
|
68
|
-
if (isInterval) {
|
|
69
|
-
clearInterval(timerId);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
clearTimeout(timerId);
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Track a timeout and ensure it gets cleared
|
|
78
|
-
*
|
|
79
|
-
* @param timerId - The timeout ID to track
|
|
80
|
-
* @returns A function that will remove this timeout
|
|
81
|
-
*/
|
|
82
|
-
trackTimeout(timerId) {
|
|
83
|
-
return this.trackTimer(timerId, false);
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Track an interval and ensure it gets cleared
|
|
87
|
-
*
|
|
88
|
-
* @param timerId - The interval ID to track
|
|
89
|
-
* @returns A function that will remove this interval
|
|
90
|
-
*/
|
|
91
|
-
trackInterval(timerId) {
|
|
92
|
-
return this.trackTimer(timerId, true);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Create a tracked timeout
|
|
96
|
-
*
|
|
97
|
-
* @param callback - Function to call when the timeout expires
|
|
98
|
-
* @param ms - Milliseconds to wait
|
|
99
|
-
* @returns The timeout ID
|
|
100
|
-
*/
|
|
101
|
-
setTimeout(callback, ms) {
|
|
102
|
-
const timerId = setTimeout(callback, ms);
|
|
103
|
-
this.trackTimeout(timerId);
|
|
104
|
-
return timerId;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create a tracked interval
|
|
108
|
-
*
|
|
109
|
-
* @param callback - Function to call at each interval
|
|
110
|
-
* @param ms - Milliseconds between intervals
|
|
111
|
-
* @returns The interval ID
|
|
112
|
-
*/
|
|
113
|
-
setInterval(callback, ms) {
|
|
114
|
-
const timerId = setInterval(callback, ms);
|
|
115
|
-
this.trackInterval(timerId);
|
|
116
|
-
return timerId;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Dispose of all tracked resources
|
|
120
|
-
*/
|
|
121
|
-
dispose() {
|
|
122
|
-
if (this.isDisposed) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
// Run all cleanup functions
|
|
126
|
-
for (const cleanup of this.cleanupFunctions) {
|
|
127
|
-
try {
|
|
128
|
-
cleanup();
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
console.error('Error during resource cleanup:', error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Clear the array
|
|
135
|
-
this.cleanupFunctions = [];
|
|
136
|
-
this.isDisposed = true;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Check if this tracker has been disposed
|
|
140
|
-
*/
|
|
141
|
-
get disposed() {
|
|
142
|
-
return this.isDisposed;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
exports.ResourceTracker = ResourceTracker;
|
|
146
|
-
/**
|
|
147
|
-
* Create a new ResourceTracker instance
|
|
148
|
-
*
|
|
149
|
-
* @returns A new ResourceTracker
|
|
150
|
-
*/
|
|
151
|
-
function createResourceTracker() {
|
|
152
|
-
return new ResourceTracker();
|
|
153
|
-
}
|