Merge pull request #228 from strukturag/send-to-session

Send directly to local session with disconnected client.
This commit is contained in:
Joachim Bauch 2022-04-11 17:00:58 +02:00 committed by GitHub
commit ef8d5ff628
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

29
hub.go
View file

@ -1253,7 +1253,7 @@ func (h *Hub) processMessageMsg(client *Client, message *ClientMessage) {
return return
} }
var recipient *Client var recipient *ClientSession
var subject string var subject string
var clientData *MessageClientMessageData var clientData *MessageClientMessageData
var serverRecipient *MessageClientMessageRecipient var serverRecipient *MessageClientMessageRecipient
@ -1299,15 +1299,18 @@ func (h *Hub) processMessageMsg(client *Client, message *ClientMessage) {
subject = "session." + msg.Recipient.SessionId subject = "session." + msg.Recipient.SessionId
h.mu.RLock() h.mu.RLock()
recipient = h.clients[data.Sid] sess, found := h.sessions[data.Sid]
if recipient == nil { if found {
if sess, ok := sess.(*ClientSession); ok {
recipient = sess
}
// Send to client connection for virtual sessions. // Send to client connection for virtual sessions.
sess := h.sessions[data.Sid] if sess.ClientType() == HelloClientTypeVirtual {
if sess != nil && sess.ClientType() == HelloClientTypeVirtual {
virtualSession := sess.(*VirtualSession) virtualSession := sess.(*VirtualSession)
clientSession := virtualSession.Session() clientSession := virtualSession.Session()
subject = "session." + clientSession.PublicId() subject = "session." + clientSession.PublicId()
recipient = clientSession.GetClient() recipient = clientSession
// The client should see his session id as recipient. // The client should see his session id as recipient.
serverRecipient = &MessageClientMessageRecipient{ serverRecipient = &MessageClientMessageRecipient{
Type: "session", Type: "session",
@ -1391,15 +1394,11 @@ func (h *Hub) processMessageMsg(client *Client, message *ClientMessage) {
return return
} }
if recipientSession := recipient.GetSession(); recipientSession != nil { msg.Recipient.SessionId = session.PublicId()
msg.Recipient.SessionId = session.PublicId() // It may take some time for the publisher (which is the current
// It may take some time for the publisher (which is the current // client) to start his stream, so we must not block the active
// client) to start his stream, so we must not block the active // goroutine.
// goroutine. go h.processMcuMessage(session, recipient, message, msg, clientData)
go h.processMcuMessage(session, recipientSession, message, msg, clientData)
} else { // nolint
// Client is not connected yet.
}
return return
} }
recipient.SendMessage(response) recipient.SendMessage(response)