Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add push preferences to relay connect frames

[email protected]16f9dbc70962
diff --git a/docs/release-control/v6/internal/subsystems/relay-runtime.md b/docs/release-control/v6/internal/subsystems/relay-runtime.md
index 67fa0f0c9f..1243010a76 100644
--- a/docs/release-control/v6/internal/subsystems/relay-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/relay-runtime.md
@@ -21,6 +21,10 @@ Own the desktop and mobile relay runtimes, their persisted relay state
boundaries, the server-owned mobile relay capability boundary, and the
canonical reconnect, encryption, protocol, proxy, and relay-trust behavior
for Pulse instance bridging.
+Mobile CONNECT frames may carry explicit push preferences for critical,
+warning, approval, and fix-result notifications. The relay protocol preserves
+each boolean so server-side delivery can enforce the paired device's choices;
+legacy clients omit the entire preferences object and remain wire-compatible.
The generated mobile push vocabulary includes
`external_probe_offline` for a Pulse instance that is still connected while
diff --git a/internal/relay/protocol.go b/internal/relay/protocol.go
index c4dc33facb..af1afdc58a 100644
--- a/internal/relay/protocol.go
+++ b/internal/relay/protocol.go
@@ -149,10 +149,18 @@ type RegisterAckPayload struct {
// ConnectPayload is sent by the app in CONNECT frames.
type ConnectPayload struct {
- InstanceID string `json:"instance_id"`
- AuthToken string `json:"auth_token"`
- DeviceToken string `json:"device_token,omitempty"` // push notification device token (mobile apps only)
- Platform string `json:"platform,omitempty"` // "ios" or "android" (mobile apps only)
+ InstanceID string `json:"instance_id"`
+ AuthToken string `json:"auth_token"`
+ DeviceToken string `json:"device_token,omitempty"` // push notification device token (mobile apps only)
+ Platform string `json:"platform,omitempty"` // "ios" or "android" (mobile apps only)
+ NotificationPreferences *PushNotificationPreferences `json:"notification_preferences,omitempty"` // server-enforced delivery preferences
+}
+
+type PushNotificationPreferences struct {
+ CriticalEnabled bool `json:"critical_enabled"`
+ WarningEnabled bool `json:"warning_enabled"`
+ ApprovalEnabled bool `json:"approval_enabled"`
+ FixResultEnabled bool `json:"fix_result_enabled"`
}
// ConnectAckPayload is sent by the relay in CONNECT_ACK frames.
diff --git a/internal/relay/protocol_test.go b/internal/relay/protocol_test.go
index 0939a7992f..59a12d2396 100644
--- a/internal/relay/protocol_test.go
+++ b/internal/relay/protocol_test.go
@@ -122,6 +122,12 @@ func TestControlFrameRoundTrip(t *testing.T) {
AuthToken: "auth-token-xyz",
DeviceToken: "device-token-123",
Platform: "ios",
+ NotificationPreferences: &PushNotificationPreferences{
+ CriticalEnabled: true,
+ WarningEnabled: false,
+ ApprovalEnabled: true,
+ FixResultEnabled: false,
+ },
}
frame, err := NewControlFrame(FrameConnect, 0, orig)
if err != nil {
@@ -155,6 +161,23 @@ func TestControlFrameRoundTrip(t *testing.T) {
if got.Platform != orig.Platform {
t.Errorf("Platform: got %q, want %q", got.Platform, orig.Platform)
}
+ if got.NotificationPreferences == nil {
+ t.Fatal("NotificationPreferences was omitted from CONNECT round trip")
+ }
+ if *got.NotificationPreferences != *orig.NotificationPreferences {
+ t.Errorf("NotificationPreferences: got %#v, want %#v", got.NotificationPreferences, orig.NotificationPreferences)
+ }
+
+ legacyFrame, err := NewControlFrame(FrameConnect, 0, ConnectPayload{
+ InstanceID: "relay_legacy",
+ AuthToken: "legacy-auth",
+ })
+ if err != nil {
+ t.Fatalf("NewControlFrame(legacy CONNECT) error = %v", err)
+ }
+ if bytes.Contains(legacyFrame.Payload, []byte("notification_preferences")) {
+ t.Fatalf("legacy CONNECT unexpectedly serialized notification preferences: %s", legacyFrame.Payload)
+ }
})
t.Run("channel open payload", func(t *testing.T) {