Package Exports
- ts-webcam
- ts-webcam/dist/ts-webcam.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ts-webcam) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ts-webcam
ไลบรารี TypeScript สำหรับจัดการการเข้าถึงเว็บแคมโดยใช้ MediaDevices API ช่วยให้สามารถเริ่มต้นและควบคุมสตรีมเว็บแคมในแอปพลิเคชันเว็บได้อย่างง่ายดาย
คุณสมบัติ
- รองรับการกำหนดค่าแบบ Type-safe ด้วย TypeScript interfaces
- รองรับความละเอียดหลายระดับพร้อมการ fallback
- มีฟีเจอร์กระจกและหมุนอัตโนมัติ
- สามารถกำหนด preview element ได้
- มี callback functions สำหรับเหตุการณ์ต่างๆ
- มีเมธอดพื้นฐานครบถ้วน
การติดตั้ง
npm install ts-webcam
การใช้งาน
ตัวอย่างพื้นฐาน
import { Webcam } from "ts-webcam";
// สร้าง instance ของ Webcam
const webcam = new Webcam({
audio: true,
device: "your-device-id", // ไม่จำเป็น: ระบุ device ID เฉพาะ
resolution: ["1280x720", "640x480"], // ความละเอียดที่ต้องการ
fallbackResolution: "640x480", // ความละเอียดสำรอง
mirror: true, // เปิดโหมดกระจก
autoRotation: true, // หมุนอัตโนมัติตามการวางอุปกรณ์
previewElement: document.getElementById("preview") as HTMLVideoElement, // element สำหรับแสดงผล
onStart: () => console.log("เริ่มใช้งานเว็บแคมสำเร็จ"),
onError: (error) => console.error("เกิดข้อผิดพลาด:", error),
});
// เริ่มใช้งานเว็บแคม
webcam.start();
// หยุดการใช้งานเว็บแคม
webcam.stop();
ตัวอย่างการใช้งานเมธอดเพิ่มเติม
// ตรวจสอบสถานะการทำงาน
console.log("กำลังทำงาน:", webcam.isActive());
// ดูความละเอียดปัจจุบัน
const resolution = webcam.getCurrentResolution();
console.log("ความละเอียด:", resolution);
// อัปเดตการตั้งค่า
webcam.updateConfig({ mirror: true });
ข้อกำหนดระบบ
- เบราว์เซอร์ที่รองรับ MediaDevices API (Chrome, Firefox, Edge, Safari)
- TypeScript (ถ้าใช้ในโปรเจค TypeScript)
License
MIT License
การสนับสนุน
หากพบปัญหาหรือต้องการเสนอฟีเจอร์ใหม่ สามารถสร้าง issue ได้ที่ GitHub repository