working state

This commit is contained in:
cottongin
2026-02-07 12:37:21 -05:00
parent 1e0cb63b1c
commit fd42ac0e7c
3 changed files with 56 additions and 37 deletions

View File

@@ -129,8 +129,19 @@ func (m *Manager) startWebSocketClient(messageCallback func(string)) error {
// Get EnableRoomCodeImage setting from config (defaults to false) // Get EnableRoomCodeImage setting from config (defaults to false)
enableRoomCodeImage := m.config.Viper().GetBool("jackbox.EnableRoomCodeImage") enableRoomCodeImage := m.config.Viper().GetBool("jackbox.EnableRoomCodeImage")
// Get configurable delays for room code broadcast
imageDelay := time.Duration(m.config.Viper().GetInt("jackbox.RoomCodeImageDelay")) * time.Second
plaintextDelay := time.Duration(m.config.Viper().GetInt("jackbox.RoomCodePlaintextDelay")) * time.Second
if plaintextDelay == 0 {
plaintextDelay = 29 * time.Second // default
}
m.log.Infof("Room code delays: imageDelay=%v, plaintextDelay=%v (raw config: image=%d, plaintext=%d)",
imageDelay, plaintextDelay,
m.config.Viper().GetInt("jackbox.RoomCodeImageDelay"),
m.config.Viper().GetInt("jackbox.RoomCodePlaintextDelay"))
// Create WebSocket client (pass the API client for vote tracking) // Create WebSocket client (pass the API client for vote tracking)
m.wsClient = NewWebSocketClient(apiURL, token, wrappedCallback, m.client, enableRoomCodeImage, m.log) m.wsClient = NewWebSocketClient(apiURL, token, wrappedCallback, m.client, enableRoomCodeImage, imageDelay, plaintextDelay, m.log)
// Connect to WebSocket // Connect to WebSocket
if err := m.wsClient.Connect(); err != nil { if err := m.wsClient.Connect(); err != nil {

View File

@@ -305,7 +305,7 @@ func GenerateRoomCodeImage(roomCode, gameTitle string) ([]byte, error) {
} }
// Animation parameters // Animation parameters
initialPauseFrames := 25 // Initial pause before animation starts (2.5 seconds at 10fps) initialPauseFrames := 1 // Initial pause before animation starts (2.5 seconds at 10fps)
fadeFrames := 10 // Number of frames for fade-in (1 second at 10fps) fadeFrames := 10 // Number of frames for fade-in (1 second at 10fps)
pauseFrames := 30 // Frames to pause between characters (3 seconds at 10fps) pauseFrames := 30 // Frames to pause between characters (3 seconds at 10fps)
frameDelay := 10 // 10/100 second = 0.1s per frame (10 fps) frameDelay := 10 // 10/100 second = 0.1s per frame (10 fps)

View File

@@ -26,6 +26,8 @@ type WebSocketClient struct {
authenticated bool authenticated bool
subscribedSession int subscribedSession int
enableRoomCodeImage bool // Whether to upload room code images to Kosmi enableRoomCodeImage bool // Whether to upload room code images to Kosmi
roomCodeImageDelay time.Duration // Delay before sending image announcement
roomCodePlaintextDelay time.Duration // Delay before sending plaintext room code
} }
// WebSocket message types // WebSocket message types
@@ -67,13 +69,15 @@ type GameAddedData struct {
} }
// NewWebSocketClient creates a new WebSocket client // NewWebSocketClient creates a new WebSocket client
func NewWebSocketClient(apiURL, token string, messageCallback func(string), apiClient *Client, enableRoomCodeImage bool, log *logrus.Entry) *WebSocketClient { func NewWebSocketClient(apiURL, token string, messageCallback func(string), apiClient *Client, enableRoomCodeImage bool, roomCodeImageDelay, roomCodePlaintextDelay time.Duration, log *logrus.Entry) *WebSocketClient {
return &WebSocketClient{ return &WebSocketClient{
apiURL: apiURL, apiURL: apiURL,
token: token, token: token,
messageCallback: messageCallback, messageCallback: messageCallback,
apiClient: apiClient, apiClient: apiClient,
enableRoomCodeImage: enableRoomCodeImage, enableRoomCodeImage: enableRoomCodeImage,
roomCodeImageDelay: roomCodeImageDelay,
roomCodePlaintextDelay: roomCodePlaintextDelay,
log: log, log: log,
reconnectDelay: 1 * time.Second, reconnectDelay: 1 * time.Second,
maxReconnect: 30 * time.Second, maxReconnect: 30 * time.Second,
@@ -360,6 +364,10 @@ func (c *WebSocketClient) broadcastWithRoomCodeImage(message, gameTitle, roomCod
c.log.Infof("✅ Step 2 complete: Uploaded to %s", imageURL) c.log.Infof("✅ Step 2 complete: Uploaded to %s", imageURL)
// Now that upload succeeded, send the full announcement with the message and URL // Now that upload succeeded, send the full announcement with the message and URL
if c.roomCodeImageDelay > 0 {
c.log.Infof("⏳ Step 3: Waiting %v before broadcasting game announcement...", c.roomCodeImageDelay)
time.Sleep(c.roomCodeImageDelay)
}
c.log.Infof("📢 Step 3: Broadcasting game announcement with URL...") c.log.Infof("📢 Step 3: Broadcasting game announcement with URL...")
fullMessage := fmt.Sprintf("%s %s", message, imageURL) fullMessage := fmt.Sprintf("%s %s", message, imageURL)
if c.messageCallback != nil { if c.messageCallback != nil {
@@ -369,17 +377,18 @@ func (c *WebSocketClient) broadcastWithRoomCodeImage(message, gameTitle, roomCod
c.log.Error("❌ Step 3 failed: messageCallback is nil") c.log.Error("❌ Step 3 failed: messageCallback is nil")
} }
// Send the plaintext room code after 19 seconds (to sync with animation completion) // Send the plaintext room code after configured delay (to sync with animation completion)
// Capture callback and logger in closure // Capture callback and logger in closure
callback := c.messageCallback callback := c.messageCallback
logger := c.log logger := c.log
plainRoomCode := roomCode // Capture room code for plain text message plainRoomCode := roomCode // Capture room code for plain text message
plaintextDelay := c.roomCodePlaintextDelay
c.log.Infof("⏰ Step 4: Starting 19-second timer goroutine for plaintext room code...") c.log.Infof("⏰ Step 4: Starting %v timer goroutine for plaintext room code...", plaintextDelay)
go func() { go func() {
logger.Infof("⏰ [Goroutine started] Waiting 19 seconds before sending plaintext room code: %s", plainRoomCode) logger.Infof("⏰ [Goroutine started] Waiting %v before sending plaintext room code: %s", plaintextDelay, plainRoomCode)
time.Sleep(19 * time.Second) time.Sleep(plaintextDelay)
logger.Infof("⏰ [19 seconds elapsed] Now sending plaintext room code...") logger.Infof("⏰ [%v elapsed] Now sending plaintext room code...", plaintextDelay)
if callback != nil { if callback != nil {
// Send just the room code in plaintext (for easy copy/paste) // Send just the room code in plaintext (for easy copy/paste)
@@ -392,7 +401,7 @@ func (c *WebSocketClient) broadcastWithRoomCodeImage(message, gameTitle, roomCod
} }
}() }()
c.log.Infof("✅ Step 4 complete: Goroutine launched, will fire in 19 seconds") c.log.Infof("✅ Step 4 complete: Goroutine launched, will fire in %v", plaintextDelay)
} }
// handleSessionEnded processes session.ended events // handleSessionEnded processes session.ended events
@@ -545,4 +554,3 @@ func (c *WebSocketClient) IsSubscribed() bool {
defer c.mu.Unlock() defer c.mu.Unlock()
return c.subscribedSession > 0 return c.subscribedSession > 0
} }