Skip to content

Commit

Permalink
[IMP] Adds a Status (200) field to Me and Presence response for consi…
Browse files Browse the repository at this point in the history
…stency

NOTE that we also send a Response with 200 in the case of a response to
a Presence request with the status flag set to false. In this case, we
don't gather the presence statuses on the brokers, but we need to send
an empty response instead of just nil. This will allow for an RPC call
on Presence. See the SDKs (Go in particular).
  • Loading branch information
Florimond committed Sep 25, 2024
1 parent 74e6649 commit 098bae4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/service/me/me.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ func (s *Service) OnRequest(c service.Conn, payload []byte) (service.Response, b
}

return &Response{
ID: c.ID(),
Links: links,
Status: 200,
ID: c.ID(),
Links: links,
}, true
}
1 change: 1 addition & 0 deletions internal/service/me/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package me
// Response represents a response for the 'me' request.
type Response struct {
Request uint16 `json:"req,omitempty"` // The corresponding request ID.
Status int `json:"status"` // The status of the response
ID string `json:"id"` // The private ID of the connection.
Links map[string]string `json:"links,omitempty"` // The set of pre-defined channels.
}
Expand Down
5 changes: 4 additions & 1 deletion internal/service/presence/presence.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ func (s *Service) OnRequest(c service.Conn, payload []byte) (service.Response, b
// Gather local & cluster presence
who = append(who, s.getAllPresence(ssid)...)
return &Response{
Status: 200,
Time: now,
Event: EventTypeStatus,
Channel: msg.Channel,
Who: who,
}, true
}

return nil, true
return &Response{
Status: 200,
}, true
}

// OnHTTP occurs when a new HTTP presence request is received.
Expand Down
1 change: 1 addition & 0 deletions internal/service/presence/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
// Response represents a state notification.
type Response struct {
Request uint16 `json:"req,omitempty"` // The corresponding request ID.
Status int `json:"status"` // The status of the response
Time int64 `json:"time"` // The UNIX timestamp.
Event EventType `json:"event"` // The event, must be "status", "subscribe" or "unsubscribe".
Channel string `json:"channel"` // The target channel for the notification.
Expand Down

0 comments on commit 098bae4

Please sign in to comment.