From 098bae4e0b36fc47ff931c3e695d925dc8472984 Mon Sep 17 00:00:00 2001 From: Florimond Husquinet Date: Tue, 24 Sep 2024 19:43:12 +0200 Subject: [PATCH] [IMP] Adds a Status (200) field to Me and Presence response for consistency 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). --- internal/service/me/me.go | 5 +++-- internal/service/me/requests.go | 1 + internal/service/presence/presence.go | 5 ++++- internal/service/presence/requests.go | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/service/me/me.go b/internal/service/me/me.go index 7883f2aa..19a707a6 100644 --- a/internal/service/me/me.go +++ b/internal/service/me/me.go @@ -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 } diff --git a/internal/service/me/requests.go b/internal/service/me/requests.go index 5cfa13a2..21a78b02 100644 --- a/internal/service/me/requests.go +++ b/internal/service/me/requests.go @@ -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. } diff --git a/internal/service/presence/presence.go b/internal/service/presence/presence.go index 71979ed6..09a5dcb5 100644 --- a/internal/service/presence/presence.go +++ b/internal/service/presence/presence.go @@ -90,6 +90,7 @@ 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, @@ -97,7 +98,9 @@ func (s *Service) OnRequest(c service.Conn, payload []byte) (service.Response, b }, true } - return nil, true + return &Response{ + Status: 200, + }, true } // OnHTTP occurs when a new HTTP presence request is received. diff --git a/internal/service/presence/requests.go b/internal/service/presence/requests.go index aae52a89..bcd94382 100644 --- a/internal/service/presence/requests.go +++ b/internal/service/presence/requests.go @@ -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.