Compare commits
7 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5c05df26cf | ||
|
|
ef5e6d9017 | ||
|
|
049143a385 | ||
|
|
ce97f7984a | ||
|
|
d4f53653d2 | ||
|
|
7afdc64e8f | ||
| 526567c599 |
10 changed files with 425 additions and 122 deletions
|
|
@ -11,3 +11,4 @@
|
||||||
- [Front Camera Preview Alignment](issue_front_camera_preview_alignment.md) - Keep popup preview orientation aligned with normalized saved photos
|
- [Front Camera Preview Alignment](issue_front_camera_preview_alignment.md) - Keep popup preview orientation aligned with normalized saved photos
|
||||||
- [iOS Native Photo Mirroring](issue_ios_native_photo_mirroring.md) - Do not flip iOS native-capture photos during normalization
|
- [iOS Native Photo Mirroring](issue_ios_native_photo_mirroring.md) - Do not flip iOS native-capture photos during normalization
|
||||||
- [iOS Native Camera Popup](issue_ios_native_camera_popup_control.md) - Inline-first on iOS; native activates only after inline fails (prior native-first seed was reverted)
|
- [iOS Native Camera Popup](issue_ios_native_camera_popup_control.md) - Inline-first on iOS; native activates only after inline fails (prior native-first seed was reverted)
|
||||||
|
- [iOS 16 Inline White Preview](issue_ios16_inline_camera_white_preview.md) - Safari iOS 16 white preview needs single mount plus explicit video readiness
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
name: ios16-inline-camera-white-preview
|
||||||
|
description: Safari iOS 16 inline preview can stay white when multiple simple-vue-camera instances mount and playback readiness is assumed too early
|
||||||
|
type: project
|
||||||
|
---
|
||||||
|
|
||||||
|
In `HomeView.vue`, Safari on iOS 16.x can show a white in-page camera preview when more than one `simple-vue-camera` instance is mounted for responsive layouts and the app treats `camera.start()` as sufficient proof that the preview is rendering.
|
||||||
|
|
||||||
|
**Why:** `simple-vue-camera` uses a hard-coded `id="video"` internally and does not explicitly call `video.play()` during `start()`. On mobile/xs, mounting both desktop and mobile camera components at once creates a fragile setup for Safari, where the active preview can remain white even though permission and stream startup succeeded.
|
||||||
|
|
||||||
|
**How to apply:** Keep only the active responsive camera instance mounted in `HomeView.vue`, and after `camera.start()` explicitly prepare/check the underlying video element (`playsinline`, `muted`, `play()`, non-zero dimensions, ready state). If the preview still does not become render-ready, remount once and then fall back to native capture.
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
"quasar": "^2.11.1",
|
"quasar": "^2.11.1",
|
||||||
"register-service-worker": "^1.7.2",
|
"register-service-worker": "^1.7.2",
|
||||||
"simple-vue-camera": "^1.1.3",
|
"simple-vue-camera": "^1.1.3",
|
||||||
|
"socket.io-client": "^4.8.3",
|
||||||
"vite-plugin-pwa": "^0.16.7",
|
"vite-plugin-pwa": "^0.16.7",
|
||||||
"vue": "^3.4.15",
|
"vue": "^3.4.15",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,12 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
import { useSocketStore } from '@/stores/socket'
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
useSocketStore()
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<router-view />
|
<router-view />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
7
src/api/socket.ts
Normal file
7
src/api/socket.ts
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
import env from "./index";
|
||||||
|
|
||||||
|
const socket = `${env.API_URI}/org-socket`;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
socket,
|
||||||
|
};
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
import leave from '@/api/api.checkin'
|
import leave from '@/api/api.checkin'
|
||||||
import history from '@/api/api.history'
|
import history from '@/api/api.history'
|
||||||
import message from '@/api/api.message'
|
import message from '@/api/api.message'
|
||||||
|
import socket from '@/api/socket'
|
||||||
|
|
||||||
const API = {
|
const API = {
|
||||||
/**leave */
|
/**leave */
|
||||||
|
|
@ -12,6 +13,7 @@ const API = {
|
||||||
...history,
|
...history,
|
||||||
/**message */
|
/**message */
|
||||||
...message,
|
...message,
|
||||||
|
...socket,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
||||||
|
|
@ -163,8 +163,19 @@ function reattachAndResizeMap(retry = 0) {
|
||||||
mapView.value.container = activeContainer
|
mapView.value.container = activeContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
mapView.value.resize()
|
// เรียก resize() อย่างปลอดภัยด้วยการตรวจสอบว่ามี method นี้หรือไม่
|
||||||
mapView.value.requestRender?.()
|
try {
|
||||||
|
if (typeof mapView.value.resize === 'function') {
|
||||||
|
mapView.value.resize()
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Map resize failed:', error)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof mapView.value.requestRender === 'function') {
|
||||||
|
mapView.value.requestRender?.()
|
||||||
|
}
|
||||||
|
|
||||||
mapView.value
|
mapView.value
|
||||||
.goTo(
|
.goTo(
|
||||||
{
|
{
|
||||||
|
|
@ -285,7 +296,11 @@ async function initializeMap() {
|
||||||
geometry: userPoint,
|
geometry: userPoint,
|
||||||
symbol: userSymbol,
|
symbol: userSymbol,
|
||||||
})
|
})
|
||||||
mapView.value.graphics.add(userGraphic)
|
|
||||||
|
// เพิ่มการตรวจสอบความปลอดภัยก่อนเข้าถึง graphics
|
||||||
|
if (mapView.value && mapView.value.graphics && !mapView.value.destroyed) {
|
||||||
|
mapView.value.graphics.add(userGraphic)
|
||||||
|
}
|
||||||
// Get POI place ยิงไปขอที่ server ของกทม.ก่อน
|
// Get POI place ยิงไปขอที่ server ของกทม.ก่อน
|
||||||
// await axios
|
// await axios
|
||||||
// .get(
|
// .get(
|
||||||
|
|
@ -381,12 +396,22 @@ async function initializeMap() {
|
||||||
geometry: poiPoint,
|
geometry: poiPoint,
|
||||||
symbol: poiSymbol,
|
symbol: poiSymbol,
|
||||||
})
|
})
|
||||||
mapView.value.graphics.add(poiGraphic)
|
|
||||||
// อัปเดตการแสดงผลให้แสดงทั้งตำแหน่งของผู้ใช้และ POI
|
// เพิ่มการตรวจสอบความปลอดภัยก่อนเข้าถึง graphics และ goTo
|
||||||
mapView.value.goTo({
|
if (mapView.value && !mapView.value.destroyed) {
|
||||||
target: [userPoint, poiPoint],
|
if (mapView.value.graphics) {
|
||||||
zoom: zoomMap.value,
|
mapView.value.graphics.add(poiGraphic)
|
||||||
})
|
}
|
||||||
|
// อัปเดตการแสดงผลให้แสดงทั้งตำแหน่งของผู้ใช้และ POI
|
||||||
|
if (typeof mapView.value.goTo === 'function') {
|
||||||
|
mapView.value.goTo({
|
||||||
|
target: [userPoint, poiPoint],
|
||||||
|
zoom: zoomMap.value,
|
||||||
|
}).catch(() => {
|
||||||
|
// Ignore goTo errors
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateLocation(latitude, longitude, poiPlaceName.value)
|
updateLocation(latitude, longitude, poiPlaceName.value)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
101
src/stores/socket.ts
Normal file
101
src/stores/socket.ts
Normal file
|
|
@ -0,0 +1,101 @@
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import config from '@/app.config'
|
||||||
|
import { getToken } from '@/plugins/auth'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { Notify } from 'quasar'
|
||||||
|
import { io, Socket } from 'socket.io-client'
|
||||||
|
interface sockeBackup {
|
||||||
|
message: string
|
||||||
|
success?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSocketStore = defineStore('socket', () => {
|
||||||
|
let socket: Socket
|
||||||
|
const notificationCounter = ref(0);
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
socket = io(new URL(config.API.socket).origin, {
|
||||||
|
auth: { token: await getToken() },
|
||||||
|
path: '/api/v1/org-socket',
|
||||||
|
})
|
||||||
|
|
||||||
|
socket.on('socket-notification', (payload) => {
|
||||||
|
let body: sockeBackup = JSON.parse(payload)
|
||||||
|
notificationCounter.value++
|
||||||
|
notifyStatus(body.message, body.success)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function notifyStatus(message: string, success?: boolean) {
|
||||||
|
Notify.create({
|
||||||
|
group: false,
|
||||||
|
type: success === undefined || success ? 'positive' : 'negative',
|
||||||
|
message: `${message}`,
|
||||||
|
position: 'top',
|
||||||
|
classes: 'custom-notification-top', // ใส่ class ที่เราสร้างไว้
|
||||||
|
timeout: success === undefined || success ? 3000 : 0,
|
||||||
|
actions:
|
||||||
|
success === undefined || success
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
icon: 'close',
|
||||||
|
color: 'white',
|
||||||
|
round: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
progress: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function fnStyleNotiOrg() {
|
||||||
|
if (document.getElementById('notify-link-style')) return
|
||||||
|
const style = document.createElement('style')
|
||||||
|
style.id = 'notify-link-style'
|
||||||
|
style.textContent = `
|
||||||
|
.notify-link {
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: #fff;
|
||||||
|
border: 1px solid #fff;
|
||||||
|
transition: all 0.3s;
|
||||||
|
cursor: pointer;
|
||||||
|
margin:0 0 0 5px;
|
||||||
|
}
|
||||||
|
.notify-link:hover {
|
||||||
|
background-color: #ffffff;
|
||||||
|
color: #21BA45;
|
||||||
|
}
|
||||||
|
`
|
||||||
|
document.head.appendChild(style)
|
||||||
|
}
|
||||||
|
;(window as any).resetOrgPage = (type: string) => {
|
||||||
|
localStorage.setItem('org_type', type)
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
function notifyStatusOrg(type: string, message: string, success?: boolean) {
|
||||||
|
fnStyleNotiOrg()
|
||||||
|
Notify.create({
|
||||||
|
message: `${message} <a href="#" onclick="window.resetOrgPage('${type}')" class="notify-link">${
|
||||||
|
type == 'draft' ? 'ไปยังโครงสร้างแบบร่าง' : 'ไปยังโครงสร้างปัจจุบัน'
|
||||||
|
}</a>`,
|
||||||
|
html: true,
|
||||||
|
group: false,
|
||||||
|
type: success === undefined || success ? 'positive' : 'negative',
|
||||||
|
position: 'top',
|
||||||
|
timeout: 0,
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
icon: 'close',
|
||||||
|
color: 'white',
|
||||||
|
round: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
init()
|
||||||
|
|
||||||
|
return { notificationCounter }
|
||||||
|
})
|
||||||
|
|
@ -69,30 +69,30 @@ div
|
||||||
$separator-color: #EDEDED !default
|
$separator-color: #EDEDED !default
|
||||||
|
|
||||||
.bg-teal-1
|
.bg-teal-1
|
||||||
background: #e0f2f1a6 !important
|
background: #e0f2f1a6 !important
|
||||||
|
|
||||||
.table_ellipsis
|
.table_ellipsis
|
||||||
max-width: 200px
|
max-width: 200px
|
||||||
white-space: nowrap
|
white-space: nowrap
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
|
|
||||||
.table_ellipsis:hover
|
.table_ellipsis:hover
|
||||||
word-wrap: break-word
|
word-wrap: break-word
|
||||||
overflow: visible
|
overflow: visible
|
||||||
white-space: normal
|
white-space: normal
|
||||||
|
|
||||||
.table_ellipsis2
|
.table_ellipsis2
|
||||||
max-width: 25vw
|
max-width: 25vw
|
||||||
white-space: nowrap
|
white-space: nowrap
|
||||||
overflow: hidden
|
overflow: hidden
|
||||||
text-overflow: ellipsis
|
text-overflow: ellipsis
|
||||||
|
|
||||||
.table_ellipsis2:hover
|
.table_ellipsis2:hover
|
||||||
word-wrap: break-word
|
word-wrap: break-word
|
||||||
overflow: visible
|
overflow: visible
|
||||||
white-space: normal
|
white-space: normal
|
||||||
transition: width 2s
|
transition: width 2s
|
||||||
|
|
||||||
$muti-tab: #87d4cc
|
$muti-tab: #87d4cc
|
||||||
.text-muti-tab
|
.text-muti-tab
|
||||||
|
|
@ -100,7 +100,6 @@ $muti-tab: #87d4cc
|
||||||
.bg-muti-tab
|
.bg-muti-tab
|
||||||
background: $muti-tab !important
|
background: $muti-tab !important
|
||||||
|
|
||||||
|
|
||||||
/* editor */
|
/* editor */
|
||||||
|
|
||||||
.q-editor
|
.q-editor
|
||||||
|
|
@ -109,26 +108,25 @@ $muti-tab: #87d4cc
|
||||||
font-weight: 400
|
font-weight: 400
|
||||||
|
|
||||||
.q-editor h1, .q-menu h1
|
.q-editor h1, .q-menu h1
|
||||||
font-size: 1.5rem
|
font-size: 1.5rem
|
||||||
line-height: 2rem
|
line-height: 2rem
|
||||||
font-weight: 400
|
font-weight: 400
|
||||||
margin-block-start: 0em
|
margin-block-start: 0em
|
||||||
margin-block-end: 0em
|
margin-block-end: 0em
|
||||||
|
|
||||||
.q-editor h2, .q-menu h2
|
.q-editor h2, .q-menu h2
|
||||||
font-size: 1.25rem
|
font-size: 1.25rem
|
||||||
line-height: 1.5rem
|
line-height: 1.5rem
|
||||||
font-weight: 400
|
font-weight: 400
|
||||||
margin-block-start: 0em
|
margin-block-start: 0em
|
||||||
margin-block-end: 0em
|
margin-block-end: 0em
|
||||||
|
|
||||||
|
|
||||||
.q-editor h3, .q-menu h3
|
.q-editor h3, .q-menu h3
|
||||||
font-size: 1.1rem
|
font-size: 1.1rem
|
||||||
line-height: 1.5rem
|
line-height: 1.5rem
|
||||||
font-weight: 400
|
font-weight: 400
|
||||||
margin-block-start: 0em
|
margin-block-start: 0em
|
||||||
margin-block-end: 0em
|
margin-block-end: 0em
|
||||||
|
|
||||||
.q-editor p, .q-menu p
|
.q-editor p, .q-menu p
|
||||||
margin: 0
|
margin: 0
|
||||||
|
|
@ -136,4 +134,7 @@ $muti-tab: #87d4cc
|
||||||
/* q-tree */
|
/* q-tree */
|
||||||
|
|
||||||
.q-tree
|
.q-tree
|
||||||
color: #c8d3db
|
color: #c8d3db
|
||||||
|
|
||||||
|
.custom-notification-top
|
||||||
|
margin-top: 180px !important
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,17 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, onMounted, watch, onBeforeUnmount, computed } from 'vue'
|
import {
|
||||||
|
ref,
|
||||||
|
reactive,
|
||||||
|
onMounted,
|
||||||
|
watch,
|
||||||
|
onBeforeUnmount,
|
||||||
|
computed,
|
||||||
|
nextTick,
|
||||||
|
} from 'vue'
|
||||||
import { useQuasar } from 'quasar'
|
import { useQuasar } from 'quasar'
|
||||||
import { format } from 'date-fns'
|
import { format } from 'date-fns'
|
||||||
import Camera from 'simple-vue-camera'
|
import Camera from 'simple-vue-camera'
|
||||||
|
import { storeToRefs } from 'pinia'
|
||||||
|
|
||||||
import config from '@/app.config'
|
import config from '@/app.config'
|
||||||
import http from '@/plugins/http'
|
import http from '@/plugins/http'
|
||||||
|
|
@ -10,6 +19,7 @@ import { useCounterMixin } from '@/stores/mixin'
|
||||||
import { usePermissions } from '@/composables/usePermissions'
|
import { usePermissions } from '@/composables/usePermissions'
|
||||||
import { usePrivacyStore } from '@/stores/privacy'
|
import { usePrivacyStore } from '@/stores/privacy'
|
||||||
import { usePositionKeycloakStore } from '@/stores/positionKeycloak'
|
import { usePositionKeycloakStore } from '@/stores/positionKeycloak'
|
||||||
|
import { useSocketStore } from '@/stores/socket'
|
||||||
|
|
||||||
import type { FormRef, OptionReason } from '@/interface/response/checkin'
|
import type { FormRef, OptionReason } from '@/interface/response/checkin'
|
||||||
|
|
||||||
|
|
@ -24,6 +34,8 @@ const {
|
||||||
syncPermissionStates,
|
syncPermissionStates,
|
||||||
requestCameraPermission,
|
requestCameraPermission,
|
||||||
} = usePermissions()
|
} = usePermissions()
|
||||||
|
const socketStore = useSocketStore()
|
||||||
|
const { notificationCounter } = storeToRefs(socketStore)
|
||||||
const privacyStore = usePrivacyStore()
|
const privacyStore = usePrivacyStore()
|
||||||
const positionKeycloakStore = usePositionKeycloakStore()
|
const positionKeycloakStore = usePositionKeycloakStore()
|
||||||
const MOCK_CHECK_DELAY_MS = 800
|
const MOCK_CHECK_DELAY_MS = 800
|
||||||
|
|
@ -187,6 +199,131 @@ function wait(ms: number) {
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getCameraVideoElement() {
|
||||||
|
return camera.value?.video
|
||||||
|
}
|
||||||
|
|
||||||
|
function prepareInlineCameraVideo(videoElement: HTMLVideoElement) {
|
||||||
|
videoElement.autoplay = true
|
||||||
|
videoElement.muted = true
|
||||||
|
videoElement.setAttribute('autoplay', '')
|
||||||
|
videoElement.setAttribute('muted', '')
|
||||||
|
videoElement.setAttribute('playsinline', '')
|
||||||
|
videoElement.setAttribute('webkit-playsinline', 'true')
|
||||||
|
}
|
||||||
|
|
||||||
|
function isInlineCameraPreviewReady(videoElement: HTMLVideoElement) {
|
||||||
|
return (
|
||||||
|
Boolean(videoElement.srcObject) &&
|
||||||
|
videoElement.videoWidth > 0 &&
|
||||||
|
videoElement.videoHeight > 0 &&
|
||||||
|
videoElement.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function waitForCameraInstance() {
|
||||||
|
for (let attempt = 0; attempt < 10; attempt += 1) {
|
||||||
|
await nextTick()
|
||||||
|
|
||||||
|
if (camera.value) {
|
||||||
|
return camera.value
|
||||||
|
}
|
||||||
|
|
||||||
|
await wait(50)
|
||||||
|
}
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stopInlineCamera() {
|
||||||
|
camera.value?.stop()
|
||||||
|
cameraIsOn.value = false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remountInlineCameraComponent() {
|
||||||
|
await stopInlineCamera()
|
||||||
|
cameraMountKey.value += 1
|
||||||
|
await nextTick()
|
||||||
|
await wait(INLINE_CAMERA_REMOUNT_DELAY_MS)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureInlineCameraPreviewReady() {
|
||||||
|
const deadline = Date.now() + INLINE_CAMERA_PREVIEW_TIMEOUT_MS
|
||||||
|
let lastPlaybackError: unknown = null
|
||||||
|
|
||||||
|
while (Date.now() < deadline) {
|
||||||
|
const videoElement = getCameraVideoElement()
|
||||||
|
|
||||||
|
if (videoElement) {
|
||||||
|
prepareInlineCameraVideo(videoElement)
|
||||||
|
|
||||||
|
if (isInlineCameraPreviewReady(videoElement)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (videoElement.srcObject) {
|
||||||
|
try {
|
||||||
|
await videoElement.play()
|
||||||
|
} catch (error) {
|
||||||
|
lastPlaybackError = error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
await wait(INLINE_CAMERA_PREVIEW_POLL_MS)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastPlaybackError instanceof Error) {
|
||||||
|
throw lastPlaybackError
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('Inline camera preview did not become ready in time')
|
||||||
|
}
|
||||||
|
|
||||||
|
async function syncActiveCameraDevices() {
|
||||||
|
const devices: any = await camera.value?.devices(['videoinput'])
|
||||||
|
if (!devices) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
availableCameras.value = devices
|
||||||
|
|
||||||
|
const activeId = camera.value?.currentDeviceID()
|
||||||
|
const activeIdx = activeId
|
||||||
|
? devices.findIndex((device: any) => device.deviceId === activeId)
|
||||||
|
: -1
|
||||||
|
currentCameraIndex.value = activeIdx >= 0 ? activeIdx : 0
|
||||||
|
currentCameraType.value = resolveCameraType(
|
||||||
|
devices[currentCameraIndex.value]?.label || '',
|
||||||
|
'front'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function startInlineCamera(recoveryAttempt = 0): Promise<void> {
|
||||||
|
const cameraInstance = await waitForCameraInstance()
|
||||||
|
|
||||||
|
if (!cameraInstance) {
|
||||||
|
throw new Error('Camera component is unavailable')
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
currentCameraType.value = 'front'
|
||||||
|
await cameraInstance.start()
|
||||||
|
await ensureInlineCameraPreviewReady()
|
||||||
|
await syncActiveCameraDevices()
|
||||||
|
cameraIsOn.value = true
|
||||||
|
} catch (error) {
|
||||||
|
await stopInlineCamera()
|
||||||
|
|
||||||
|
if (recoveryAttempt < MAX_INLINE_CAMERA_RECOVERY_ATTEMPTS) {
|
||||||
|
await remountInlineCameraComponent()
|
||||||
|
return startInlineCamera(recoveryAttempt + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function getDelayedFreshPosition() {
|
async function getDelayedFreshPosition() {
|
||||||
const firstPosition = await getCurrentPositionAsync({
|
const firstPosition = await getCurrentPositionAsync({
|
||||||
enableHighAccuracy: true,
|
enableHighAccuracy: true,
|
||||||
|
|
@ -252,6 +389,7 @@ const cameraIsOn = ref<boolean>(false)
|
||||||
const img = ref<any>(undefined)
|
const img = ref<any>(undefined)
|
||||||
const photoWidth = ref<number>(350)
|
const photoWidth = ref<number>(350)
|
||||||
const photoHeight = ref<number>(350)
|
const photoHeight = ref<number>(350)
|
||||||
|
const cameraMountKey = ref<number>(0)
|
||||||
const availableCameras = ref<any[]>([])
|
const availableCameras = ref<any[]>([])
|
||||||
const currentCameraIndex = ref<number>(0)
|
const currentCameraIndex = ref<number>(0)
|
||||||
const currentCameraType = ref<'front' | 'back' | 'unknown'>('unknown')
|
const currentCameraType = ref<'front' | 'back' | 'unknown'>('unknown')
|
||||||
|
|
@ -285,6 +423,10 @@ const centeredPreviewImageStyle = Object.freeze({
|
||||||
objectFit: 'cover',
|
objectFit: 'cover',
|
||||||
objectPosition: 'center center',
|
objectPosition: 'center center',
|
||||||
})
|
})
|
||||||
|
const INLINE_CAMERA_PREVIEW_TIMEOUT_MS = isIOSDevice ? 2500 : 1800
|
||||||
|
const INLINE_CAMERA_PREVIEW_POLL_MS = 120
|
||||||
|
const INLINE_CAMERA_REMOUNT_DELAY_MS = 120
|
||||||
|
const MAX_INLINE_CAMERA_RECOVERY_ATTEMPTS = 1
|
||||||
|
|
||||||
/** Ref for the hidden file input used as native camera fallback */
|
/** Ref for the hidden file input used as native camera fallback */
|
||||||
const nativePhotoInput = ref<HTMLInputElement | null>(null)
|
const nativePhotoInput = ref<HTMLInputElement | null>(null)
|
||||||
|
|
@ -413,10 +555,7 @@ async function assignSelectedPhoto(file: File) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function openNativePhotoCapture() {
|
function openNativePhotoCapture() {
|
||||||
if (cameraIsOn.value) {
|
void stopInlineCamera()
|
||||||
camera.value?.stop()
|
|
||||||
cameraIsOn.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nativePhotoInput.value) {
|
if (nativePhotoInput.value) {
|
||||||
nativePhotoInput.value.value = ''
|
nativePhotoInput.value.value = ''
|
||||||
|
|
@ -426,8 +565,7 @@ function openNativePhotoCapture() {
|
||||||
|
|
||||||
function enableNativePhotoCaptureFallback() {
|
function enableNativePhotoCaptureFallback() {
|
||||||
preferNativePhotoCapture.value = true
|
preferNativePhotoCapture.value = true
|
||||||
camera.value?.stop()
|
void stopInlineCamera()
|
||||||
cameraIsOn.value = false
|
|
||||||
clearSelectedPhoto()
|
clearSelectedPhoto()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -500,19 +638,18 @@ async function fetchCheckStatus() {
|
||||||
/** inQueue เป็น true */
|
/** inQueue เป็น true */
|
||||||
isDisabledCheckTime.value = true
|
isDisabledCheckTime.value = true
|
||||||
msgCheckTime.value = 'ระบบกำลังประมวลผล'
|
msgCheckTime.value = 'ระบบกำลังประมวลผล'
|
||||||
if (intervalId.value === undefined) {
|
// if (intervalId.value === undefined) {
|
||||||
intervalId.value = setInterval(async () => {
|
// intervalId.value = setInterval(async () => {
|
||||||
try {
|
// try {
|
||||||
await fetchCheckStatus()
|
// await fetchCheckStatus()
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
console.error('Error in interval fetchCheckStatus:', error)
|
// console.error('Error in interval fetchCheckStatus:', error)
|
||||||
// หยุด interval ถ้าเกิด error
|
// // หยุด interval ถ้าเกิด error
|
||||||
stopChecking()
|
// stopChecking()
|
||||||
}
|
// }
|
||||||
}, 3000)
|
// }, 3000)
|
||||||
console.log('startChecking called, intervalId:', intervalId.value)
|
// console.log('startChecking called, intervalId:', intervalId.value)
|
||||||
}
|
// }
|
||||||
// hideLoader()
|
|
||||||
} else {
|
} else {
|
||||||
/** inQueue เป็น false */
|
/** inQueue เป็น false */
|
||||||
isDisabledCheckTime.value = false
|
isDisabledCheckTime.value = false
|
||||||
|
|
@ -614,8 +751,7 @@ async function openCamera() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cameraIsOn.value) {
|
if (cameraIsOn.value) {
|
||||||
camera.value?.stop()
|
await stopInlineCamera()
|
||||||
cameraIsOn.value = false
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -645,26 +781,7 @@ async function openCamera() {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
currentCameraType.value = 'front'
|
await startInlineCamera()
|
||||||
|
|
||||||
// Keep the initial stream aligned with the Camera component's front-camera constraint.
|
|
||||||
await camera.value?.start()
|
|
||||||
const devices: any = await camera.value?.devices(['videoinput'])
|
|
||||||
if (devices) {
|
|
||||||
availableCameras.value = devices
|
|
||||||
|
|
||||||
// Avoid an extra stop/start cycle here; on iOS it can override the initial camera selection.
|
|
||||||
const activeId = camera.value?.currentDeviceID()
|
|
||||||
const activeIdx = activeId
|
|
||||||
? devices.findIndex((d: any) => d.deviceId === activeId)
|
|
||||||
: -1
|
|
||||||
currentCameraIndex.value = activeIdx >= 0 ? activeIdx : 0
|
|
||||||
currentCameraType.value = resolveCameraType(
|
|
||||||
devices[currentCameraIndex.value]?.label || '',
|
|
||||||
'front'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
cameraIsOn.value = true
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error opening camera:', error)
|
console.error('Error opening camera:', error)
|
||||||
|
|
||||||
|
|
@ -695,6 +812,7 @@ async function changeCamera(targetCameraType?: 'front' | 'back') {
|
||||||
targetCameraType ??
|
targetCameraType ??
|
||||||
(currentCameraType.value === 'back' ? 'back' : 'front')
|
(currentCameraType.value === 'back' ? 'back' : 'front')
|
||||||
await camera.value?.changeCamera(device.deviceId)
|
await camera.value?.changeCamera(device.deviceId)
|
||||||
|
await ensureInlineCameraPreviewReady()
|
||||||
currentCameraIndex.value = 0
|
currentCameraIndex.value = 0
|
||||||
currentCameraType.value = resolveCameraType(
|
currentCameraType.value = resolveCameraType(
|
||||||
device.label || '',
|
device.label || '',
|
||||||
|
|
@ -711,6 +829,7 @@ async function changeCamera(targetCameraType?: 'front' | 'back') {
|
||||||
if (matchingCameras.length > 0) {
|
if (matchingCameras.length > 0) {
|
||||||
const targetDevice = matchingCameras[0]
|
const targetDevice = matchingCameras[0]
|
||||||
await camera.value?.changeCamera(targetDevice.deviceId)
|
await camera.value?.changeCamera(targetDevice.deviceId)
|
||||||
|
await ensureInlineCameraPreviewReady()
|
||||||
currentCameraIndex.value = devices.indexOf(targetDevice)
|
currentCameraIndex.value = devices.indexOf(targetDevice)
|
||||||
currentCameraType.value = resolveCameraType(
|
currentCameraType.value = resolveCameraType(
|
||||||
targetDevice.label || '',
|
targetDevice.label || '',
|
||||||
|
|
@ -720,6 +839,7 @@ async function changeCamera(targetCameraType?: 'front' | 'back') {
|
||||||
const nextIndex = (currentCameraIndex.value + 1) % devices.length
|
const nextIndex = (currentCameraIndex.value + 1) % devices.length
|
||||||
const nextDevice = devices[nextIndex]
|
const nextDevice = devices[nextIndex]
|
||||||
await camera.value?.changeCamera(nextDevice.deviceId)
|
await camera.value?.changeCamera(nextDevice.deviceId)
|
||||||
|
await ensureInlineCameraPreviewReady()
|
||||||
currentCameraIndex.value = nextIndex
|
currentCameraIndex.value = nextIndex
|
||||||
currentCameraType.value = resolveCameraType(
|
currentCameraType.value = resolveCameraType(
|
||||||
nextDevice.label || '',
|
nextDevice.label || '',
|
||||||
|
|
@ -743,6 +863,7 @@ async function switchCamera() {
|
||||||
const fallbackType = currentCameraType.value === 'back' ? 'front' : 'back'
|
const fallbackType = currentCameraType.value === 'back' ? 'front' : 'back'
|
||||||
|
|
||||||
await camera.value?.changeCamera(targetDevice.deviceId)
|
await camera.value?.changeCamera(targetDevice.deviceId)
|
||||||
|
await ensureInlineCameraPreviewReady()
|
||||||
currentCameraIndex.value = targetIndex
|
currentCameraIndex.value = targetIndex
|
||||||
currentCameraType.value = resolveCameraType(
|
currentCameraType.value = resolveCameraType(
|
||||||
targetDevice.label || '',
|
targetDevice.label || '',
|
||||||
|
|
@ -781,7 +902,7 @@ async function capturePhoto() {
|
||||||
await assignSelectedPhoto(normalizedFile)
|
await assignSelectedPhoto(normalizedFile)
|
||||||
|
|
||||||
//แสดงรูป
|
//แสดงรูป
|
||||||
camera.value?.stop()
|
await stopInlineCamera()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error capturing photo:', error)
|
console.error('Error capturing photo:', error)
|
||||||
|
|
||||||
|
|
@ -803,7 +924,7 @@ async function refreshPhoto() {
|
||||||
openNativePhotoCapture()
|
openNativePhotoCapture()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await camera.value?.start()
|
await startInlineCamera()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error refreshing photo:', error)
|
console.error('Error refreshing photo:', error)
|
||||||
messageError($q, error, 'ไม่สามารถเปิดกล้องได้ กรุณาลองใหม่อีกครั้ง')
|
messageError($q, error, 'ไม่สามารถเปิดกล้องได้ กรุณาลองใหม่อีกครั้ง')
|
||||||
|
|
@ -1038,10 +1159,7 @@ const inQueue = ref<boolean>(false)
|
||||||
// ฟังก์ชันสำหรับรีเซ็ตรูปและหยุดกล้อง
|
// ฟังก์ชันสำหรับรีเซ็ตรูปและหยุดกล้อง
|
||||||
function resetCameraAndImage() {
|
function resetCameraAndImage() {
|
||||||
clearSelectedPhoto()
|
clearSelectedPhoto()
|
||||||
if (cameraIsOn.value && camera.value) {
|
void stopInlineCamera()
|
||||||
camera.value.stop()
|
|
||||||
cameraIsOn.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// เพิ่มฟังก์ชันสำหรับจัดการการปิดแอพในมือถือ
|
// เพิ่มฟังก์ชันสำหรับจัดการการปิดแอพในมือถือ
|
||||||
|
|
@ -1133,6 +1251,11 @@ watch(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** Watch notification counter on socket */
|
||||||
|
watch(notificationCounter, () => {
|
||||||
|
startChecking()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -1234,7 +1357,7 @@ watch(
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-xs-12 col-sm-4 gt-xs">
|
<div v-if="$q.screen.gt.xs" class="col-xs-12 col-sm-4">
|
||||||
<q-card
|
<q-card
|
||||||
:class="
|
:class="
|
||||||
$q.screen.xs ? 'card-container-xs' : 'card-container'
|
$q.screen.xs ? 'card-container-xs' : 'card-container'
|
||||||
|
|
@ -1257,6 +1380,7 @@ watch(
|
||||||
<div class="col-12 row items-center">
|
<div class="col-12 row items-center">
|
||||||
<!-- แสดงกล้องตอนกดถ่ายภาพ -->
|
<!-- แสดงกล้องตอนกดถ่ายภาพ -->
|
||||||
<Camera
|
<Camera
|
||||||
|
:key="`desktop-${cameraMountKey}`"
|
||||||
:resolution="{ width: photoWidth, height: photoHeight }"
|
:resolution="{ width: photoWidth, height: photoHeight }"
|
||||||
ref="camera"
|
ref="camera"
|
||||||
:class="['camera-preview']"
|
:class="['camera-preview']"
|
||||||
|
|
@ -1289,13 +1413,13 @@ watch(
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="cameraIsOn">
|
<div v-if="cameraIsOn && img == null">
|
||||||
<div
|
<div
|
||||||
v-if="$q.screen.gt.xs"
|
v-if="$q.screen.gt.xs"
|
||||||
class="absolute-bottom-right q-ma-md"
|
class="absolute-bottom-right q-ma-md"
|
||||||
>
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="availableCameras.length > 1 && img == null"
|
v-if="availableCameras.length > 1"
|
||||||
round
|
round
|
||||||
push
|
push
|
||||||
icon="flip_camera_ios"
|
icon="flip_camera_ios"
|
||||||
|
|
@ -1305,7 +1429,6 @@ watch(
|
||||||
@click="switchCamera"
|
@click="switchCamera"
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="img == null"
|
|
||||||
round
|
round
|
||||||
push
|
push
|
||||||
icon="photo_camera"
|
icon="photo_camera"
|
||||||
|
|
@ -1313,8 +1436,41 @@ watch(
|
||||||
color="positive"
|
color="positive"
|
||||||
@click="capturePhoto"
|
@click="capturePhoto"
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<div v-else>
|
||||||
|
<div
|
||||||
|
class="absolute-bottom text-subtitle2 text-center q-py-sm"
|
||||||
|
style="background: #00000021"
|
||||||
|
>
|
||||||
|
<q-btn
|
||||||
|
v-if="availableCameras.length > 1"
|
||||||
|
round
|
||||||
|
icon="flip_camera_ios"
|
||||||
|
size="16px"
|
||||||
|
style="background: #424242; color: white"
|
||||||
|
@click="switchCamera"
|
||||||
|
unelevated
|
||||||
|
class="q-mr-xs"
|
||||||
|
/>
|
||||||
|
<q-btn
|
||||||
|
round
|
||||||
|
icon="photo_camera"
|
||||||
|
size="18px"
|
||||||
|
style="background: #263238; color: white"
|
||||||
|
@click="capturePhoto"
|
||||||
|
unelevated
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Refresh button - shows when photo is captured regardless of camera state -->
|
||||||
|
<div v-if="img != null && !useNativePhotoCapture">
|
||||||
|
<div
|
||||||
|
v-if="$q.screen.gt.xs"
|
||||||
|
class="absolute-bottom-right q-ma-md"
|
||||||
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-else
|
|
||||||
round
|
round
|
||||||
push
|
push
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
|
|
@ -1329,31 +1485,12 @@ watch(
|
||||||
style="background: #00000021"
|
style="background: #00000021"
|
||||||
>
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="availableCameras.length > 1 && img == null"
|
|
||||||
round
|
|
||||||
icon="flip_camera_ios"
|
|
||||||
size="16px"
|
|
||||||
style="background: #424242; color: white"
|
|
||||||
@click="switchCamera"
|
|
||||||
unelevated
|
|
||||||
class="q-mr-xs"
|
|
||||||
/>
|
|
||||||
<q-btn
|
|
||||||
round
|
|
||||||
v-if="img == null"
|
|
||||||
icon="photo_camera"
|
|
||||||
size="18px"
|
|
||||||
style="background: #263238; color: white"
|
|
||||||
@click="capturePhoto"
|
|
||||||
unelevated
|
|
||||||
/>
|
|
||||||
<q-btn
|
|
||||||
v-else
|
|
||||||
round
|
round
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
size="18px"
|
size="18px"
|
||||||
style="background: #263238; color: white"
|
style="background: #263238; color: white"
|
||||||
@click="refreshPhoto"
|
@click="refreshPhoto"
|
||||||
|
unelevated
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -1388,6 +1525,7 @@ watch(
|
||||||
<div class="col-12 row items-center">
|
<div class="col-12 row items-center">
|
||||||
<!-- แสดงกล้องตอนกดถ่ายภาพ -->
|
<!-- แสดงกล้องตอนกดถ่ายภาพ -->
|
||||||
<Camera
|
<Camera
|
||||||
|
:key="`mobile-${cameraMountKey}`"
|
||||||
:resolution="{
|
:resolution="{
|
||||||
width: photoWidth,
|
width: photoWidth,
|
||||||
height: photoHeight,
|
height: photoHeight,
|
||||||
|
|
@ -1424,13 +1562,13 @@ watch(
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="cameraIsOn">
|
<div v-if="cameraIsOn && img == null">
|
||||||
<div
|
<div
|
||||||
class="absolute-bottom text-subtitle2 text-center q-py-sm"
|
class="absolute-bottom text-subtitle2 text-center q-py-sm"
|
||||||
style="background: #00000021"
|
style="background: #00000021"
|
||||||
>
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="availableCameras.length > 1 && img == null"
|
v-if="availableCameras.length > 1"
|
||||||
round
|
round
|
||||||
icon="flip_camera_ios"
|
icon="flip_camera_ios"
|
||||||
size="16px"
|
size="16px"
|
||||||
|
|
@ -1441,15 +1579,22 @@ watch(
|
||||||
/>
|
/>
|
||||||
<q-btn
|
<q-btn
|
||||||
round
|
round
|
||||||
v-if="img == null"
|
|
||||||
icon="photo_camera"
|
icon="photo_camera"
|
||||||
size="18px"
|
size="18px"
|
||||||
style="background: #263238; color: white"
|
style="background: #263238; color: white"
|
||||||
@click="capturePhoto"
|
@click="capturePhoto"
|
||||||
unelevated
|
unelevated
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Refresh button - shows when photo is captured regardless of camera state -->
|
||||||
|
<div v-if="img != null && !useNativePhotoCapture">
|
||||||
|
<div
|
||||||
|
class="absolute-bottom text-subtitle2 text-center q-py-sm"
|
||||||
|
style="background: #00000021"
|
||||||
|
>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-else
|
|
||||||
round
|
round
|
||||||
icon="refresh"
|
icon="refresh"
|
||||||
size="18px"
|
size="18px"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue