Files
main.tsmain
What you'll learn
- Write an interceptor for a gateway that reads the socket, the payload and the event name through context.switchToWs()
- Bind an interceptor to a gateway with @UseInterceptors(), and know it runs around each message, not around the connection
- Keep per-connection state in a provider with scope: Scope.REQUEST, which Nest 12 creates for each connection, with the socket injected as REQUEST
- Know that a gateway that injects such a provider becomes per-connection too
Press Run tests to start the app. Its log appears here.Graded endpoints
Her connection gets its own shortlist
And so does his
The shortlist knows its owner from the socket injected as REQUEST
The same connection, the same shortlist
Another connection, another shortlist: Bob's has only Luna
The handler's refusal is still an answer, so the interceptor records it
His connection, and the shortlist made for it, are gone
A new connection
A new connection starts with a new, empty shortlist
The interceptor recorded every message after its handler answered: the sender's name from the handshake and the event's name
The previous request for the log is in it now
run the tests first
Frames
Run the tests first.