-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
121 lines (105 loc) · 3.95 KB
/
main.go
File metadata and controls
121 lines (105 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Mezon WebRTC Bot - OPTIMIZED REAL-TIME FACE DETECTION
// Key optimizations:
// - Detect on scaled-down images (320px wide)
// - Reduced samplebuilder latency (maxLate: 128)
// - Better JPEG quality control (90)
// - Faster capture interval (1s)
// - Persistent ffmpeg process option (commented, can enable)
package main
import (
"fmt"
"log"
"mezon-checkin-bot/internal/api"
"mezon-checkin-bot/internal/audio"
"mezon-checkin-bot/internal/client"
"mezon-checkin-bot/models"
"os"
"os/signal"
"strconv"
"syscall"
"time"
"mezon-checkin-bot/internal/webrtc"
)
// ============================================================
// MAIN
// ============================================================
func main() {
fmt.Println("╔════════════════════════════════════════════════════╗")
fmt.Println("║ Mezon WebRTC Bot - OPTIMIZED FACE DETECTION ║")
fmt.Println("║ 🚀 Performance improvements: ║")
fmt.Println("║ - Detect on scaled images (320px) ║")
fmt.Println("║ - Reduced latency (maxLate: 128) ║")
fmt.Println("║ - Faster capture interval (1s) ║")
fmt.Println("║ - Controlled JPEG quality (90) ║")
fmt.Println("╚════════════════════════════════════════════════════╝")
botID := os.Getenv("BOT_ID")
botToken := os.Getenv("BOT_TOKEN")
host := os.Getenv("MEZON_HOST")
if host == "" {
host = "gw.mezon.ai"
}
port := os.Getenv("MEZON_PORT")
if port == "" {
port = "443"
}
useSSL := true
if os.Getenv("MEZON_USE_SSL") == "false" {
useSSL = false
}
botIDInt, err := strconv.ParseInt(botID, 10, 64)
config := models.Config{
BotID: botIDInt,
BotToken: botToken,
Host: host,
Port: port,
UseSSL: useSSL,
}
log.Printf("📋 Bot ID: %d", config.BotID)
apiClient := api.NewAPIClient(30 * time.Second)
client := client.NewMezonClient(config)
defer client.Close() // IMPORTANT: Always defer Close()
// Khởi tạo location config
locationConfig := &webrtc.LocationConfig{
Enabled: true,
OfficesFilePath: "config/offices.json", // Đường dẫn tương đối từ thư mục chạy
}
faceConfig := &models.FaceRecognitionConfig{
Enabled: true,
MinFaceSize: 80,
JPEGQuality: 90, // High quality JPEG (range: 1-100)
}
audioConfig := audio.AudioConfig{
WelcomeAudioPath: "./audio/welcome.ogg",
CheckinSuccessPath: "./audio/checkin-success.ogg",
CheckinFailPath: "./audio/checkin-failed.ogg",
Enabled: true,
}
if err := client.Login(); err != nil {
log.Fatalf("❌ Failed to login: %v", err)
}
webrtcManager, err := webrtc.NewWebRTCManager(client, "./image-captures", faceConfig, audioConfig, locationConfig, apiClient)
if err != nil {
log.Fatalf("❌ Failed to create WebRTC manager: %v", err)
}
log.Println("\n✅ Bot started with OPTIMIZED FACE DETECTION!")
log.Println("📞 Waiting for calls...")
log.Println("🎯 Optimizations:")
log.Println(" ✅ VP8 video capture")
log.Println(" ⚡ Fast face detection on scaled images (320px)")
log.Println(" ⚡ Reduced latency (maxLate: 128 vs 512)")
log.Println(" ⚡ Faster capture interval (1s vs 2s)")
log.Println(" ⚡ Faster PLI requests (1s vs 2s)")
log.Println(" ✅ High quality JPEG encoding (quality: 90)")
log.Println(" ✅ Sends expanded square images when face detected")
log.Println(" ✅ Sequential API submission (max 5 attempts)")
log.Printf(" - API: %s", models.APICheckIn)
log.Printf(" - Min face size: %dpx", faceConfig.MinFaceSize)
log.Println(" Press Ctrl+C to stop")
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
<-sigCh
log.Println("\n⚠️ Shutting down...")
webrtcManager.CloseAll()
client.Close()
log.Println("✅ Done!")
}