@@ -19,11 +19,11 @@ import (
1919const KEEPALIVE_TIMEOUT_SECONDS = 10
2020
2121type WebSocketServer struct {
22- ServerId string // Int representing the ID of the server
23- //ConnectionUrl string // Server's url for people to connect to. Used for messaging in reconnect testing
24- DebugEnabled bool // Display debug messages ; --debug
25- StrictMode bool // Force stricter production-like qualities; --strict
26- Upgrader websocket.Upgrader
22+ ServerId string // Int representing the ID of the server
23+ DebugEnabled bool // Display debug messages; --debug
24+ StrictMode bool // Force stricter production-like qualities ; --strict
25+
26+ Upgrader websocket.Upgrader
2727
2828 Clients * util.List [Client ] // All connected clients
2929 muClients sync.Mutex // Mutex for WebSocketServer.Clients
@@ -428,6 +428,7 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
428428 }
429429
430430 // Check for subscriptions when running with --require-subscription
431+ subscriptionCreatedAtTimestamp := "" // Used below if in strict mode
431432 if ws .StrictMode {
432433 found := false
433434 for _ , clientSubscriptions := range ws .Subscriptions {
@@ -438,6 +439,7 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
438439 for _ , sub := range clientSubscriptions {
439440 if sub .SessionClientName == client .clientName && sub .Type == eventObj .Subscription .Type && sub .Version == eventObj .Subscription .Version {
440441 found = true
442+ subscriptionCreatedAtTimestamp = sub .CreatedAt
441443 }
442444 }
443445 }
@@ -450,6 +452,16 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
450452 // Change payload's subscription.transport.session_id to contain the correct Session ID
451453 eventObj .Subscription .Transport .SessionID = fmt .Sprintf ("%v_%v" , ws .ServerId , client .clientName )
452454
455+ // Change payload's subscription.created_at to contain the correct timestamp -- https://github.com/twitchdev/twitch-cli/issues/264
456+ if ws .StrictMode {
457+ // When running WITH --require-subscription, created_at will be set to the time the subscription was created using the mock EventSub REST endpoint
458+ eventObj .Subscription .CreatedAt = subscriptionCreatedAtTimestamp
459+ } else {
460+ // When running WITHOUT --require-subscription, created_at will be set to the time the client connected
461+ // This is because without --require-subscription the server "grants" access to all event subscriptions at the moment the client is connected
462+ eventObj .Subscription .CreatedAt = client .ConnectedAtTimestamp
463+ }
464+
453465 // Build notification message
454466 notificationMsg , err := json .Marshal (
455467 NotificationMessage {
0 commit comments