new url websocket
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Rama Priyanto 2026-04-07 16:53:35 +07:00
parent 2293a4e5d9
commit 1e163e3e29
2 changed files with 22 additions and 22 deletions

View File

@ -18,18 +18,10 @@ import Image from "next/image"
import { useEffect, useState } from "react" import { useEffect, useState } from "react"
import { socket } from "@/components/socket" import { socket } from "@/components/socket"
const dummy = [ interface historyType {
{ url: "/sample-1.jpg" }, img: string
{ url: "/sample-2.jpg" }, plate: string
{ url: "/sample-3.jpg" }, }
{ url: "/sample-4.jpg" },
{ url: "/sample-1.jpg" },
{ url: "/sample-2.jpg" },
{ url: "/sample-3.jpg" },
{ url: "/sample-4.jpg" },
{ url: "/sample-1.jpg" },
]
const stream_dummy = [ const stream_dummy = [
"/app/static/uploads/ds1.mp4", "/app/static/uploads/ds1.mp4",
"/app/static/uploads/ds2.mp4", "/app/static/uploads/ds2.mp4",
@ -43,7 +35,7 @@ export default function Etle() {
const [imageSrc, setImageSrc] = useState<string>("") const [imageSrc, setImageSrc] = useState<string>("")
const [plate, setPlate] = useState<string>("") const [plate, setPlate] = useState<string>("")
const [confidence, setConfidence] = useState<number | null>(null) const [confidence, setConfidence] = useState<number | null>(null)
const [history, setHistory] = useState<string[]>([]) const [history, setHistory] = useState<historyType[]>([])
const startDetection = (index: number) => { const startDetection = (index: number) => {
const stream = stream_dummy[index] const stream = stream_dummy[index]
@ -69,7 +61,7 @@ export default function Etle() {
socket.on("video_frame", (data) => { socket.on("video_frame", (data) => {
const thumb = `data:image/jpeg;base64,${data.frame}` const thumb = `data:image/jpeg;base64,${data.frame}`
setImageSrc(thumb) setImageSrc(thumb)
setHistory((prev) => [thumb, ...prev].slice(0, 20)) // setHistory((prev) => [thumb, ...prev].slice(0, 20))
}) })
socket.on("plate_detected", (data) => { socket.on("plate_detected", (data) => {
@ -77,7 +69,14 @@ export default function Etle() {
setConfidence(data.confidence ?? null) setConfidence(data.confidence ?? null)
const thumb = `data:image/jpeg;base64,${data.frame_thumb}` const thumb = `data:image/jpeg;base64,${data.frame_thumb}`
setHistory((prev) => [thumb, ...prev].slice(0, 20)) setHistory((prev) => {
// cek apakah plate sudah pernah ada
const exists = prev.some((item) => item.plate === data.plate_text)
if (exists) return prev // skip kalau duplicate
return [{ img: thumb, plate: data.plate_text }, ...prev]
})
}) })
// socket.on("detection_stopped", (data) => { // socket.on("detection_stopped", (data) => {
@ -139,7 +138,7 @@ export default function Etle() {
</p> </p>
</div> </div>
<Drawer direction="right"> <Drawer direction="right">
<DrawerTrigger asChild> <DrawerTrigger asChild title="">
<Button className="fixed top-1/2 right-0 h-20 w-6 -translate-y-1/2 cursor-pointer rounded-none rounded-l-md bg-white"> <Button className="fixed top-1/2 right-0 h-20 w-6 -translate-y-1/2 cursor-pointer rounded-none rounded-l-md bg-white">
<ChevronLeft /> <ChevronLeft />
</Button> </Button>
@ -152,19 +151,20 @@ export default function Etle() {
{history.map((item, index) => ( {history.map((item, index) => (
<div key={index} className="rounded-lg bg-white p-3 text-lg"> <div key={index} className="rounded-lg bg-white p-3 text-lg">
<Image <Image
src={item} src={item.img}
width={1280} width={1280}
height={960} height={960}
alt={"image" + index} alt={"image" + index}
className="rounded-lg" className="rounded-lg"
/> />
<p>{item.plate}</p>
</div> </div>
))} ))}
{history.map((img, index) => ( {/* {history.map((img, index) => (
<div key={index} className="rounded-lg bg-white p-3"> <div key={index} className="rounded-lg bg-white p-3">
<img src={img} className="rounded-lg" /> <img src={img.img} className="rounded-lg" />
</div> </div>
))} ))} */}
</div> </div>
</DrawerContent> </DrawerContent>
</Drawer> </Drawer>

View File

@ -1,7 +1,7 @@
import { io, Socket } from "socket.io-client" import { io, Socket } from "socket.io-client"
const URL = "https://plate.koronyo.online" // const URL = "https://plate.koronyo.online"
// const URL = "http://kubik.koroniyo.online:7272/" const URL = "https://plate-mtx.koronyo.online/"
export const socket: Socket = io(URL, { export const socket: Socket = io(URL, {
autoConnect: false, autoConnect: false,