neko/internal/websocket/handler/send.go

35 lines
899 B
Go
Raw Normal View History

2021-01-29 03:56:50 +13:00
package handler
import (
"demodesk/neko/internal/types"
"demodesk/neko/internal/types/event"
2021-02-15 02:40:17 +13:00
"demodesk/neko/internal/types/message"
2021-01-29 03:56:50 +13:00
)
func (h *MessageHandlerCtx) sendUnicast(session types.Session, payload *message.SendUnicast) error {
receiver, ok := h.sessions.Get(payload.Receiver)
if !ok {
2021-03-14 11:27:28 +13:00
h.logger.Debug().Str("session_id", session.ID()).Msg("receiver session ID not found")
2021-01-29 03:56:50 +13:00
return nil
}
return receiver.Send(message.SendUnicast{
Event: event.SEND_UNICAST,
Sender: session.ID(),
Receiver: receiver.ID(),
Subject: payload.Subject,
Body: payload.Body,
})
}
func (h *MessageHandlerCtx) sendBroadcast(session types.Session, payload *message.SendBroadcast) error {
h.sessions.Broadcast(message.SendBroadcast{
2021-02-15 02:40:17 +13:00
Event: event.SEND_BROADCAST,
Sender: session.ID(),
Subject: payload.Subject,
Body: payload.Body,
}, []string{session.ID()})
2021-03-16 22:53:03 +13:00
2021-01-29 03:56:50 +13:00
return nil
}