async requestPhoto(appRequest: PhotoRequest): Promise<string> {
const {
packageName,
requestId,
saveToGallery = false,
customWebhookUrl
} = appRequest;
// Determine webhook URL
let webhookUrl: string | undefined;
if (customWebhookUrl) {
webhookUrl = customWebhookUrl;
} else {
const app = this.userSession.installedApps.get(packageName);
webhookUrl = app?.publicUrl ? `${app.publicUrl}/photo-upload` : undefined;
}
// Validate connection
if (!this.userSession.websocket ||
this.userSession.websocket.readyState !== WebSocket.OPEN) {
throw new Error("Glasses WebSocket not connected.");
}
// Create pending request
const requestInfo: PendingPhotoRequest = {
requestId,
userId: this.userSession.userId,
timestamp: Date.now(),
packageName,
saveToGallery,
timeoutId: setTimeout(
() => this._handlePhotoRequestTimeout(requestId),
PHOTO_REQUEST_TIMEOUT_MS_DEFAULT
)
};
this.pendingPhotoRequests.set(requestId, requestInfo);
// Send to glasses
const messageToGlasses = {
type: CloudToGlassesMessageType.PHOTO_REQUEST,
sessionId: this.userSession.sessionId,
requestId,
appId: packageName,
webhookUrl,
timestamp: new Date()
};
this.userSession.websocket.send(JSON.stringify(messageToGlasses));
return requestId;
}