Skip to content

Commit 403aa18

Browse files
committed
Corrected missing connected_at and disconnected_at timestamps on /eventsub/subscriptions
1 parent 4a59142 commit 403aa18

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

internal/events/websocket/mock_server/manager.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,10 @@ func subscriptionPageHandlerGet(w http.ResponseWriter, r *http.Request) {
272272
Condition: subscription.Conditions,
273273
CreatedAt: subscription.CreatedAt,
274274
Transport: SubscriptionTransport{
275-
Method: "websocket",
276-
SessionID: fmt.Sprintf("%v_%v", server.ServerId, clientName),
275+
Method: "websocket",
276+
SessionID: fmt.Sprintf("%v_%v", server.ServerId, clientName),
277+
ConnectedAt: subscription.ClientConnectedAt,
278+
DisconnectedAt: subscription.ClientDisconnectedAt,
277279
},
278280
Cost: 0,
279281
})
@@ -379,6 +381,7 @@ func subscriptionPageHandlerPost(w http.ResponseWriter, r *http.Request) {
379381
Status: STATUS_ENABLED, // https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions
380382
SessionClientName: clientName,
381383
Conditions: body.Condition,
384+
ClientConnectedAt: client.ConnectedAtTimestamp,
382385
}
383386

384387
var subs []Subscription

internal/events/websocket/mock_server/server.go

+2
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,8 @@ func (ws *WebSocketServer) handleClientConnectionClose(client *Client, closeReas
491491
for i := range subscriptions {
492492
if subscriptions[i].Status == STATUS_ENABLED {
493493
subscriptions[i].Status = getStatusFromCloseMessage(closeReason)
494+
subscriptions[i].ClientConnectedAt = ""
495+
subscriptions[i].ClientDisconnectedAt = time.Now().UTC().Format(time.RFC3339Nano)
494496
}
495497
}
496498
ws.Subscriptions[client.clientName] = subscriptions

internal/events/websocket/mock_server/subscription.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ type Subscription struct {
1111
Status string // Status of the subscription
1212
SessionClientName string // Client name of the session this is associated with.
1313

14+
ClientConnectedAt string // Time client connected
15+
ClientDisconnectedAt string // Time client disconnected
16+
1417
Conditions models.EventsubCondition // Values of the subscription's condition object
1518
}
1619

@@ -71,9 +74,10 @@ type SubscriptionGetSuccessResponse struct {
7174

7275
// Cross-usage
7376
type SubscriptionTransport struct {
74-
Method string `json:"method"`
75-
SessionID string `json:"session_id"`
76-
ConnectedAt string `json:"connected_at,omitempty"`
77+
Method string `json:"method"`
78+
SessionID string `json:"session_id"`
79+
ConnectedAt string `json:"connected_at,omitempty"`
80+
DisconnectedAt string `json:"disconnected_at,omitempty"`
7781
}
7882

7983
// Cross-usage

0 commit comments

Comments
 (0)