Files
dumpsterChat/internal/gateway/events.go
T
hobokenchicken 8ee0ce657f Phase 2 backend: LiveKit voice integration
Backend:
- internal/voice/client.go: LiveKit token generation, room management, participant listing
- internal/voice/handlers.go: POST /voice/token, GET /voice/rooms/{roomID}/participants
- internal/gateway/events.go: added VOICE_JOIN, VOICE_LEAVE, VOICE_MUTE, VOICE_DEAFEN events
- cmd/server/main.go: wired voice client and routes under /api/v1/voice
- Docker: livekit.yaml config verified

Frontend deps:
- Added livekit-client and @livekit/components-react packages
2026-06-28 16:21:16 -04:00

55 lines
1.4 KiB
Go

package gateway
import "encoding/json"
// Event type constants.
const (
EventMessageCreate = "MESSAGE_CREATE"
EventMessageUpdate = "MESSAGE_UPDATE"
EventMessageDelete = "MESSAGE_DELETE"
EventChannelCreate = "CHANNEL_CREATE"
EventChannelUpdate = "CHANNEL_UPDATE"
EventChannelDelete = "CHANNEL_DELETE"
EventMemberAdd = "SERVER_MEMBER_ADD"
EventMemberRemove = "SERVER_MEMBER_REMOVE"
EventPresenceUpdate = "PRESENCE_UPDATE"
EventTypingStart = "TYPING_START"
EventVoiceJoin = "VOICE_JOIN"
EventVoiceLeave = "VOICE_LEAVE"
EventVoiceMute = "VOICE_MUTE"
EventVoiceDeafen = "VOICE_DEAFEN"
)
// Event represents a WebSocket event sent to clients.
type Event struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
// MarshalJSON implements custom JSON marshaling for Event.
func (e Event) MarshalJSON() ([]byte, error) {
type eventAlias struct {
Type string `json:"type"`
Data interface{} `json:"data,omitempty"`
}
return json.Marshal(eventAlias{
Type: e.Type,
Data: e.Data,
})
}
// UnmarshalJSON implements custom JSON unmarshaling for Event.
func (e *Event) UnmarshalJSON(data []byte) error {
type eventAlias struct {
Type string `json:"type"`
Data json.RawMessage `json:"data,omitempty"`
}
var raw eventAlias
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
e.Type = raw.Type
e.Data = raw.Data
return nil
}