htmx icon indicating copy to clipboard operation
htmx copied to clipboard

Add events to WebSocket extension

Open Renerick opened this issue 3 years ago • 1 comments

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:wsOpen raised when websocket is connected to the remote endpoint
  • htmx:wsClose raised when websocket connection is closed normally
  • htmx:wsError raised when websocket onerror event is raised
  • htmx:wsMessage raised when websocket has received a message before any processing starts
  • htmx:wsAfterMessage raised when message processing has been completed
  • htmx:wsConfigMessage raised during message building pipeline as a way to modify message content from JS akin to htmx:configRequest
  • htmx:wsBeforeSend raised right before sending message to remote endpoint
  • htmx:wsAfterSend raised 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

Renerick avatar Oct 31 '22 08:10 Renerick

This issue continues from #699

Renerick avatar Oct 31 '22 10:10 Renerick