Initial commit

This commit is contained in:
2025-11-17 15:04:27 +07:00
parent fb23922d31
commit a14562cfe0
14 changed files with 640 additions and 6673 deletions

View File

@@ -1,6 +1,7 @@
package websocket
import (
"api-service/pkg/logger"
"time"
)
@@ -108,6 +109,64 @@ func (b *Broadcaster) BroadcastMessage(messageType string, data interface{}) {
}
}
// BroadcastQris godoc
// @Summary Broadcast a QRIS-related WebSocket message
// @Description Creates and broadcasts a WebSocket message with the specified type and data for QRIS operations
// @Tags WebSocket QRIS
// @Accept json
// @Produce json
// @Param messageType path string true "Type of the QRIS message to broadcast"
// @Param data body interface{} true "QRIS data payload for the message"
// @Success 200 {object} map[string]string "QRIS message successfully queued for broadcast"
// @Failure 500 {object} map[string]string "Failed to queue QRIS message (queue full)"
// @Router /api/v1/ws/broadcast/qris [post]
func (b *Broadcaster) BroadcastQris(messageType string, data interface{}) {
msg := NewWebSocketMessage(MessageType(messageType), data, "", "")
select {
case b.hub.messageQueue <- msg:
default:
// Antrian penuh, abaikan pesan
logger.Error("Message queue full, dropping message")
}
// Show posdevice if present
// if m, ok := data.(map[string]interface{}); ok {
// fmt.Println("BroadcastQris called with IP display: ", m["posdevice"])
// }
//tabel m_deviceqris
//kolom posdevice dari nama lokasi jadi ip display
//kolom ip dari ip simrs
}
// BroadcastCheck godoc
// @Summary Broadcast a WebSocket message
// @Description Creates and broadcasts a WebSocket message with the specified type and data
// @Tags WebSocket QRIS
// @Accept json
// @Produce json
// @Param messageType path string true "Type of the message to broadcast"
// @Param data body interface{} true "Data payload for the message"
// @Success 200 {object} map[string]string "Message successfully queued for broadcast"
// @Failure 500 {object} map[string]string "Failed to queue message (queue full)"
// @Router /api/v1/ws/broadcast/check [post]
func (b *Broadcaster) BroadcastCheck(messageType string, data interface{}) {
msg := NewWebSocketMessage(MessageType(messageType), data, "", "")
select {
case b.hub.messageQueue <- msg:
default:
// Antrian penuh, abaikan pesan
logger.Error("Message queue full, dropping message")
}
// Show posdevice if present
// if m, ok := data.(map[string]interface{}); ok {
// fmt.Println("BroadcastCheck called with IP display: ", m["posdevice"])
// }
}
// BroadcastToRoom mengirim pesan ke ruangan tertentu
func (b *Broadcaster) BroadcastToRoom(room string, messageType string, data interface{}) {
msg := NewWebSocketMessage(