mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Client now has three send channels: - sendHigh (64 slots): DMs, mentions — drained first by writePump - send (256 slots): chat messages, reactions — drained second - sendLow (64 slots): typing, presence — drained last, dropped on overflow writePump drains high-priority messages before checking normal/low. PubSub gains PublishHigh/PublishLow alongside existing Publish. EmitEvents routes events by priority: - High: SequencedDMEvent, UserTargetedEvent - Normal: ChannelEvent, VoiceChannelEvent - Low: ExcludeSenderEvent (typing), PresenceEvent Slow clients get typing/presence dropped first (sendLowMsg silently drops), then disconnect on normal buffer overflow, ensuring DMs are never lost to typing indicator backpressure. https://claude.ai/code/session_01CBFF3r84ywkJRWwuqw8zD8
48 lines
1.7 KiB
Go
48 lines
1.7 KiB
Go
package ws
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
)
|
|
|
|
// EmitEvents routes typed events to the appropriate broadcast methods.
|
|
// Called from readPump goroutines after a V2 handler returns.
|
|
//
|
|
// CRITICAL ordering: SequencedDMEvent MUST be checked before ChannelEvent
|
|
// because DM events implement both interfaces. The SequencedDMEvent path
|
|
// calls sendSequencedToUsers which preserves the seqMu serialization guarantee.
|
|
//
|
|
// VoiceChannelEvent MUST be checked before ExcludeSenderEvent because voice
|
|
// events implement a superset of ExcludeSender semantics but target by voice
|
|
// channel membership rather than channel focus.
|
|
func (h *Hub) EmitEvents(events []Event) {
|
|
for _, ev := range events {
|
|
switch e := ev.(type) {
|
|
case SequencedDMEvent:
|
|
// High priority: DMs are time-sensitive.
|
|
h.sendSequencedToUsersHigh(e.ChannelID(), e.ParticipantIDs(), e.Payload())
|
|
case VoiceChannelGuardedEvent:
|
|
h.sendToUserIfInVoiceChannel(e.VoiceChannelID(), e.TargetUserID(), e.Payload())
|
|
case VoiceChannelEvent:
|
|
h.sendToVoiceChannelExcept(e.VoiceChannelID(), e.ExcludeUserID(), e.Payload())
|
|
case ExcludeSenderEvent:
|
|
// Low priority: typing indicators are ephemeral.
|
|
h.broadcastExcludeLow(e.ChannelID(), e.ExcludeUserID(), e.Payload())
|
|
case UserTargetedEvent:
|
|
// High priority: targeted events (DM opens, mentions).
|
|
h.SendToUserHigh(e.TargetUserID(), e.Payload())
|
|
case BroadcastAllEvent:
|
|
// Check concrete type: presence is low-priority, others are normal.
|
|
if _, isPresence := ev.(PresenceEvent); isPresence {
|
|
h.BroadcastToAllLow(e.Payload())
|
|
} else {
|
|
h.BroadcastToAll(e.Payload())
|
|
}
|
|
case ChannelEvent:
|
|
h.BroadcastToChannel(e.ChannelID(), e.Payload())
|
|
default:
|
|
slog.Warn("EmitEvents: unknown event type", "type", fmt.Sprintf("%T", ev))
|
|
}
|
|
}
|
|
}
|