Skip to content

Commit

Permalink
Corrected missing connected_at and disconnected_at timestamps on /eve…
Browse files Browse the repository at this point in the history
…ntsub/subscriptions
  • Loading branch information
Xemdo committed Apr 11, 2023
1 parent 4a59142 commit 403aa18
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
7 changes: 5 additions & 2 deletions internal/events/websocket/mock_server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,10 @@ func subscriptionPageHandlerGet(w http.ResponseWriter, r *http.Request) {
Condition: subscription.Conditions,
CreatedAt: subscription.CreatedAt,
Transport: SubscriptionTransport{
Method: "websocket",
SessionID: fmt.Sprintf("%v_%v", server.ServerId, clientName),
Method: "websocket",
SessionID: fmt.Sprintf("%v_%v", server.ServerId, clientName),
ConnectedAt: subscription.ClientConnectedAt,
DisconnectedAt: subscription.ClientDisconnectedAt,
},
Cost: 0,
})
Expand Down Expand Up @@ -379,6 +381,7 @@ func subscriptionPageHandlerPost(w http.ResponseWriter, r *http.Request) {
Status: STATUS_ENABLED, // https://dev.twitch.tv/docs/api/reference/#get-eventsub-subscriptions
SessionClientName: clientName,
Conditions: body.Condition,
ClientConnectedAt: client.ConnectedAtTimestamp,
}

var subs []Subscription
Expand Down
2 changes: 2 additions & 0 deletions internal/events/websocket/mock_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ func (ws *WebSocketServer) handleClientConnectionClose(client *Client, closeReas
for i := range subscriptions {
if subscriptions[i].Status == STATUS_ENABLED {
subscriptions[i].Status = getStatusFromCloseMessage(closeReason)
subscriptions[i].ClientConnectedAt = ""
subscriptions[i].ClientDisconnectedAt = time.Now().UTC().Format(time.RFC3339Nano)
}
}
ws.Subscriptions[client.clientName] = subscriptions
Expand Down
10 changes: 7 additions & 3 deletions internal/events/websocket/mock_server/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ type Subscription struct {
Status string // Status of the subscription
SessionClientName string // Client name of the session this is associated with.

ClientConnectedAt string // Time client connected
ClientDisconnectedAt string // Time client disconnected

Conditions models.EventsubCondition // Values of the subscription's condition object
}

Expand Down Expand Up @@ -71,9 +74,10 @@ type SubscriptionGetSuccessResponse struct {

// Cross-usage
type SubscriptionTransport struct {
Method string `json:"method"`
SessionID string `json:"session_id"`
ConnectedAt string `json:"connected_at,omitempty"`
Method string `json:"method"`
SessionID string `json:"session_id"`
ConnectedAt string `json:"connected_at,omitempty"`
DisconnectedAt string `json:"disconnected_at,omitempty"`
}

// Cross-usage
Expand Down

0 comments on commit 403aa18

Please sign in to comment.