@@ -19,11 +19,11 @@ import (
19
19
const KEEPALIVE_TIMEOUT_SECONDS = 10
20
20
21
21
type 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
27
27
28
28
Clients * util.List [Client ] // All connected clients
29
29
muClients sync.Mutex // Mutex for WebSocketServer.Clients
@@ -428,6 +428,7 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
428
428
}
429
429
430
430
// Check for subscriptions when running with --require-subscription
431
+ subscriptionCreatedAtTimestamp := "" // Used below if in strict mode
431
432
if ws .StrictMode {
432
433
found := false
433
434
for _ , clientSubscriptions := range ws .Subscriptions {
@@ -438,6 +439,7 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
438
439
for _ , sub := range clientSubscriptions {
439
440
if sub .SessionClientName == client .clientName && sub .Type == eventObj .Subscription .Type && sub .Version == eventObj .Subscription .Version {
440
441
found = true
442
+ subscriptionCreatedAtTimestamp = sub .CreatedAt
441
443
}
442
444
}
443
445
}
@@ -450,6 +452,16 @@ func (ws *WebSocketServer) HandleRPCEventSubForwarding(eventsubBody string, clie
450
452
// Change payload's subscription.transport.session_id to contain the correct Session ID
451
453
eventObj .Subscription .Transport .SessionID = fmt .Sprintf ("%v_%v" , ws .ServerId , client .clientName )
452
454
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
+
453
465
// Build notification message
454
466
notificationMsg , err := json .Marshal (
455
467
NotificationMessage {
0 commit comments