diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index c73765d..6211113 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -52,6 +52,7 @@ + @@ -61,4 +62,5 @@ + diff --git a/docs/changes/0-video-recording-relay/spec.md b/docs/changes/0-video-recording-relay/spec.md new file mode 100644 index 0000000..0555374 --- /dev/null +++ b/docs/changes/0-video-recording-relay/spec.md @@ -0,0 +1,62 @@ +# Spec: Gravação e Envio de Vídeos no Maestri Remote Mobile via Relay para a Estação + +**Work Item:** `0-video-recording-relay` (Projeto autônomo sem Azure Boards) +**Criada em:** 2026-11-21 22:00 +**Status:** 4/4 tasks concluídas. +**Baseline:** `maestri-remote@76defab` (`feat/video-recording-relay`, 2026-11-21) +**Complexidade:** M (3 pts brutos: 1 camada Frontend + 1 camada Gateway/Relay + Permissões Android e Testes E2E) +**Estimativa (h):** 2.0h + +--- + +## Estado atual +2026-11-21 22:05 · Builder · change concluída — Suporte a gravação de vídeos via câmera nativa e seleção da galeria implementado no menu flutuante (+); pré-visualização interativa com badge 🎬, tamanho e remoção antes do envio; player de vídeo HTML5 inline no histórico de mensagens; sanitização e persistência segura de vídeos em .maestri-remote/uploads/ com extensão garantida (.mp4/.webm) e injeção formatada no terminal da estação; permissão READ_MEDIA_VIDEO e autofocus no AndroidManifest.xml; 149 testes automatizados passando com 100% de sucesso; novo bundle OTA gerado (build ID c9c26243) e pacote maestri-agent atualizado. +Papel que retoma: N/A (Entrega finalizada) + +- Dispensas do usuário: + - Não há gestão por Azure Boards. + - Dispensa formal de Code Reviewer para fluxo direto autônomo de Builder. + +--- + +## Capabilities Afetadas +- `docs/capabilities/maestri-remote.md`: Suporte a captura e envio de vídeos no chat do app móvel com persistência no gateway local. + +--- + +## Skills Aplicáveis +- `.context/skills/command-line-environment/SKILL.md`: Manipulação de arquivos, empacotamento e comandos locais. +- `.context/skills/ota-k3s-publishing/SKILL.md`: Workflow de build de bundle OTA e empacotamento do daemon do agente. + +--- + +## Contexto e Descrição do Problema + +Atualmente, o **Maestri Remote** suporta envio de fotos (tiradas via câmera ou selecionadas da galeria), documentos, logs e mensagens de áudio com transcrição de voz. No entanto, o operador móvel frequentemente precisa demonstrar problemas visuais dinâmicos, bugs em movimento, comportamento de telas ou gravar vídeos curtos de inspeção na estação de trabalho para que o agente possa analisar o arquivo. + +Esta change adiciona o suporte completo e de ponta a ponta à gravação e envio de vídeos no app móvel: +1. No menu flutuante de anexos (+), opções de gravar vídeo com a câmera móvel e selecionar vídeos existentes (.mp4, .webm, etc.). +2. Barra de pré-visualização interativa exibindo badge de vídeo, nome e tamanho formatado antes do envio, permitindo remover ou confirmar. +3. Roteamento seguro do payload via WebSocket no Relay server até o gateway conectado. +4. Persistência do vídeo em `.maestri-remote/uploads/` com sanitização rigorosa de nome e extensão no Gateway e injeção formatada no terminal da estação (`[Anexo recebido do operador: ] `). +5. Permissões Android atualizadas no `AndroidManifest.xml` (`READ_MEDIA_VIDEO`, câmera). +6. Cobertura completa de testes automatizados com 100% de sucesso. + +--- + +## Tasks + +- [x] 1. Declarar permissões de vídeo e hardware no AndroidManifest.xml `[2026-11-21 22:00]` +- [x] 2. Implementar opções de vídeo no frontend (index.html, style.css e app.js) com preview e player `[2026-11-21 22:02]` +- [x] 3. Implementar sanitização e persistência de vídeos no Gateway e tráfego no Relay `[2026-11-21 22:03]` +- [x] 4. Cobrir com testes automatizados (unitários e integração), gerar bundle OTA e sincronizar `[2026-11-21 22:05]` + +--- + +## Critérios de Aceite +1. O menu de anexos (+) deve conter as opções "Gravar Vídeo (Câmera)" e "Galeria de Vídeos". +2. Os inputs HTML5 devem utilizar atributos adequados (`capture="environment"` para gravação direta e `accept="video/mp4,video/webm,video/quicktime,video/*"` para seleção). +3. A barra de preview deve apresentar thumbnail/indicador de vídeo, nome do arquivo e tamanho em bytes antes do envio. +4. O Gateway deve persistir o arquivo em `.maestri-remote/uploads/` com extensão sanitizada e injetar a mensagem formatada no terminal. +5. Toda a suíte de testes (`npm test`) deve passar com 100% de sucesso. +6. O bundle OTA deve ser empacotado (`npm run build:bundle`). diff --git a/package-lock.json b/package-lock.json index 928815d..05c1779 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "maestri-remote-agent", - "version": "1.0.28", + "version": "1.0.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "maestri-remote-agent", - "version": "1.0.28", + "version": "1.0.30", "dependencies": { "@capacitor/push-notifications": "^6.0.2", "pg": "^8.23.1", diff --git a/public/app.js b/public/app.js index a066007..9267fec 100644 --- a/public/app.js +++ b/public/app.js @@ -373,10 +373,14 @@ const chatInput = document.getElementById('chat-input'); const chatFileInput = document.getElementById('chat-file-input'); const chatCameraInput = document.getElementById('chat-camera-input'); const chatGalleryInput = document.getElementById('chat-gallery-input'); +const chatVideoRecordInput = document.getElementById('chat-video-record-input'); +const chatVideoInput = document.getElementById('chat-video-input'); const attachMenu = document.getElementById('attach-menu'); const attachBackdrop = document.getElementById('attach-backdrop'); const btnAttachCamera = document.getElementById('btn-attach-camera'); const btnAttachGallery = document.getElementById('btn-attach-gallery'); +const btnAttachVideoRecord = document.getElementById('btn-attach-video-record'); +const btnAttachVideoGallery = document.getElementById('btn-attach-video-gallery'); const btnAttachFile = document.getElementById('btn-attach-file'); const btnAttach = document.getElementById('btn-attach'); const btnVoice = document.getElementById('btn-voice'); @@ -2443,6 +2447,7 @@ function openFilePreviewModal(fileData) { bodyEl.innerHTML = ''; const isImage = mimeType.startsWith('image/'); + const isVideo = mimeType.startsWith('video/') || /\.(mp4|webm|mov|mkv|avi|ogv)$/i.test(fileName); const isText = mimeType.startsWith('text/') || mimeType === 'application/json' || mimeType === 'application/xml' || @@ -2461,6 +2466,24 @@ function openFilePreviewModal(fileData) { img.className = 'file-preview-image'; imgContainer.appendChild(img); bodyEl.appendChild(imgContainer); + } else if (isVideo) { + if (iconEl) iconEl.textContent = '🎬'; + if (copyBtn) copyBtn.style.display = 'none'; + + const vidContainer = document.createElement('div'); + vidContainer.className = 'file-preview-video-container'; + vidContainer.style.textAlign = 'center'; + const video = document.createElement('video'); + video.controls = true; + video.autoplay = false; + video.playsInline = true; + video.src = `data:${mimeType};base64,${fileData.contentBase64}`; + video.style.maxWidth = '100%'; + video.style.maxHeight = '65vh'; + video.style.borderRadius = '8px'; + video.style.background = '#000'; + vidContainer.appendChild(video); + bodyEl.appendChild(vidContainer); } else if (isText) { if (iconEl) iconEl.textContent = '📝'; if (copyBtn) copyBtn.style.display = 'inline-flex'; @@ -4060,11 +4083,12 @@ function renderChatMessages(forceScroll = false) { attachBox.className = 'chat-attachment-bubble'; const imageItems = itemsToRender.filter(att => att && att.isImage && att.dataUrl); - const fileItems = itemsToRender.filter(att => att && (!att.isImage || !att.dataUrl)); + const videoItems = itemsToRender.filter(att => att && (att.isVideo || (att.mimeType && att.mimeType.startsWith('video/'))) && att.dataUrl); + const fileItems = itemsToRender.filter(att => att && (!att.isImage || !att.dataUrl) && (!att.isVideo && (!att.mimeType || !att.mimeType.startsWith('video/')))); - if (imageItems.length === 1 && fileItems.length === 0) { + if (imageItems.length === 1 && fileItems.length === 0 && videoItems.length === 0) { attachBox.innerHTML = `${escapeHtml(imageItems[0].name)}`; - } else if (imageItems.length > 1) { + } else if (imageItems.length > 0) { const grid = document.createElement('div'); grid.className = 'chat-attachment-grid'; imageItems.forEach(imgAtt => { @@ -4077,6 +4101,22 @@ function renderChatMessages(forceScroll = false) { attachBox.appendChild(grid); } + if (videoItems.length > 0) { + const videoContainer = document.createElement('div'); + videoContainer.className = 'chat-attachment-video-container'; + videoItems.forEach(vAtt => { + const vWrapper = document.createElement('div'); + vWrapper.className = 'chat-attachment-video-wrapper'; + vWrapper.style.marginTop = '6px'; + vWrapper.innerHTML = ` + +
🎬 ${escapeHtml(vAtt.name || 'video')} (${formatBytes(vAtt.size || 0)})
+ `; + videoContainer.appendChild(vWrapper); + }); + attachBox.appendChild(videoContainer); + } + if (fileItems.length > 0) { const fileListEl = document.createElement('div'); fileListEl.className = 'chat-attachment-file-list'; @@ -4309,6 +4349,8 @@ function setupChatEvents() { if (chatFileInput) chatFileInput.value = ''; if (chatCameraInput) chatCameraInput.value = ''; if (chatGalleryInput) chatGalleryInput.value = ''; + if (chatVideoRecordInput) chatVideoRecordInput.value = ''; + if (chatVideoInput) chatVideoInput.value = ''; } function optimizeImageFile(file, maxDimension = 2048, quality = 0.82) { @@ -4473,6 +4515,8 @@ function setupChatEvents() { if (attachmentThumbWrapper && currentAttachment) { if (currentAttachment.isImage && currentAttachment.dataUrl) { attachmentThumbWrapper.innerHTML = `Thumbnail`; + } else if (currentAttachment.isVideo) { + attachmentThumbWrapper.innerHTML = `🎬`; } else { attachmentThumbWrapper.innerHTML = ``; } @@ -4490,6 +4534,8 @@ function setupChatEvents() { thumb.className = 'attachment-chip-thumb'; if (att.isImage && att.dataUrl) { thumb.innerHTML = `${escapeHtml(att.name)}`; + } else if (att.isVideo) { + thumb.innerHTML = `🎬`; } else { thumb.innerHTML = ``; } @@ -4568,13 +4614,28 @@ function setupChatEvents() { } const isImage = file.type && file.type.startsWith('image/'); + const isVideo = Boolean(file.type && file.type.startsWith('video/')) || /\.(mp4|webm|mov|mkv|avi|ogv|m4v)$/i.test(file.name); const processed = await optimizeImageFile(file); + let attName = processed.name || file.name || 'video.mp4'; + let attMime = processed.mimeType || file.type; + if (isVideo) { + if (!attMime || attMime === 'application/octet-stream') { + if (/\.webm$/i.test(attName)) attMime = 'video/webm'; + else if (/\.mov$/i.test(attName)) attMime = 'video/quicktime'; + else attMime = 'video/mp4'; + } + if (!/\.[a-zA-Z0-9]+$/.test(attName)) { + attName = attName + (attMime.includes('webm') ? '.webm' : '.mp4'); + } + } + currentAttachments.push({ - name: processed.name, - mimeType: processed.mimeType, - size: processed.size, + name: attName, + mimeType: attMime, + size: processed.size || file.size, isImage, + isVideo, dataUrl: processed.dataUrl, dataBase64: processed.dataBase64 }); @@ -4592,7 +4653,7 @@ function setupChatEvents() { await handleFilesSelected([file]); } - // Controle do Menu Flutuante de Anexo (Câmera / Galeria / Arquivos) + // Controle do Menu Flutuante de Anexo (Câmera / Galeria / Gravação de Vídeo / Galeria de Vídeos / Arquivos) if (btnAttach) { btnAttach.addEventListener('click', (e) => { e.preventDefault(); @@ -4620,6 +4681,20 @@ function setupChatEvents() { }); } + if (btnAttachVideoRecord) { + btnAttachVideoRecord.addEventListener('click', () => { + toggleAttachMenu(false); + if (chatVideoRecordInput) chatVideoRecordInput.click(); + }); + } + + if (btnAttachVideoGallery) { + btnAttachVideoGallery.addEventListener('click', () => { + toggleAttachMenu(false); + if (chatVideoInput) chatVideoInput.click(); + }); + } + if (btnAttachFile) { btnAttachFile.addEventListener('click', () => { toggleAttachMenu(false); @@ -4646,6 +4721,8 @@ function setupChatEvents() { bindFileInput(chatCameraInput); bindFileInput(chatGalleryInput); + bindFileInput(chatVideoRecordInput); + bindFileInput(chatVideoInput); bindFileInput(chatFileInput); if (btnRemoveAttachment) { diff --git a/public/bundles/bundle-1.0.30.zip b/public/bundles/bundle-1.0.30.zip index ca003eb..15207ea 100644 Binary files a/public/bundles/bundle-1.0.30.zip and b/public/bundles/bundle-1.0.30.zip differ diff --git a/public/bundles/bundle-latest.zip b/public/bundles/bundle-latest.zip index ca003eb..15207ea 100644 Binary files a/public/bundles/bundle-latest.zip and b/public/bundles/bundle-latest.zip differ diff --git a/public/bundles/manifest.json b/public/bundles/manifest.json index 2fab160..e65d7a2 100644 --- a/public/bundles/manifest.json +++ b/public/bundles/manifest.json @@ -1,9 +1,9 @@ { "version": "1.0.30", - "buildId": "1a30dc06", - "releasedAt": "2026-11-22T00:12:47.004Z", + "buildId": "c9c26243", + "releasedAt": "2026-11-22T01:05:18.116Z", "bundleUrl": "/bundles/bundle-1.0.30.zip", "latestUrl": "/bundles/bundle-latest.zip", - "checksum": "d6c15fa467d18257241f3aa2544b26ee9356ddf433ce556c912b9513ff99b113", - "sizeBytes": 71856 + "checksum": "7ff3e869423692aa19843ebd4c237fe2fcd6ef5b238fe993420c34ed9b5026c2", + "sizeBytes": 73028 } \ No newline at end of file diff --git a/public/index.html b/public/index.html index cb9a6f1..43f0ae0 100644 --- a/public/index.html +++ b/public/index.html @@ -368,7 +368,7 @@ - +