htmx
htmx copied to clipboard
Add events to WebSocket extension
Current implementation of websockets provides no event support for events which really limits possible use-cases for the extension. There already were PRs (#1099, #435), that could be covered by events just fine
This issue tracks the effort to implement a number of events, covering all major steps of websockets lifecycle and message processing.
Namely, the following events are proposed:
-
htmx:wsOpenraised when websocket is connected to the remote endpoint -
htmx:wsCloseraised when websocket connection is closed normally -
htmx:wsErrorraised when websocket onerror event is raised -
htmx:wsMessageraised when websocket has received a message before any processing starts -
htmx:wsAfterMessageraised when message processing has been completed -
htmx:wsConfigMessageraised during message building pipeline as a way to modify message content from JS akin tohtmx:configRequest -
htmx:wsBeforeSendraised right before sending message to remote endpoint -
htmx:wsAfterSendraised after message has been sent
The events must also provide a way to interact with underlying websocket in case event handler needs to send some message from JS
This issue continues from #699