Skip to content

[11.x] Enhance eventStream to Support Custom Events and Start Messages#54695

Merged
taylorotwell merged 5 commits into
laravel:11.xfrom
devhammed:feat-add-support-for-custom-event-stream-name-and-optional-event-stream-start-and-end-tokens
Feb 19, 2025
Merged

[11.x] Enhance eventStream to Support Custom Events and Start Messages#54695
taylorotwell merged 5 commits into
laravel:11.xfrom
devhammed:feat-add-support-for-custom-event-stream-name-and-optional-event-stream-start-and-end-tokens

Conversation

@devhammed

@devhammed devhammed commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

[11.x] Enhance eventStream to Support Custom Events and Start Messages

Summary

⚠️ BREAKING CHANGE: This PR changes the eventStream method in ResponseFactory by allowing customization of:

  • Event Name ($as) – Previously hardcoded as "update", now configurable.
  • Start Stream Message ($startStreamWith) – Optional message sent before streaming begins.
  • End Stream Message ($endStreamWith) – Now optional instead of required.

Why This Change?

  • More Flexible SSE Handling: Developers can now specify custom event names, making it easier to differentiate between different types of SSE messages and also they can now decide if they want start/end messages.
  • Improved Client Communication: Some clients expect an initial message when connecting. The $startStreamWith parameter allows for this.

Implementation Details

The method signature now includes:

public function eventStream(
    Closure $callback, 
    array $headers = [], 
    string $as = 'update', 
    ?string $startStreamWith = '<stream>', 
    ?string $endStreamWith = '</stream>'
) {}

Docs PR: laravel/docs#10180

@rodrigopedra

rodrigopedra commented Feb 19, 2025

Copy link
Copy Markdown
Contributor

Backward Compatible: Defaults maintain previous behaviour, ensuring no breaking changes.

Changing a public method signature, either by changing its arguments' defaults, or by adding an entirely new parameter, which also changes the arguments order, is a breaking change.

Of course, as this so newly released, maybe it can be tolerated. But nonetheless, it is a breaking change.

@devhammed

Copy link
Copy Markdown
Contributor Author

Backward Compatible: Defaults maintain previous behaviour, ensuring no breaking changes.

Changing a public method signature, either by changing its arguments' default, or by adding an entirely new parameter, which also changes the arguments order, is a breaking change.

Of course, as this so newly released, maybe it can be tolerated. But nonetheless, it is a breaking change.

Thanks for the feedback, I have updated the description to point this out and you are correct, I didn't count it as a breaking change because it was newly released...

@taylorotwell taylorotwell merged commit cc1a3e8 into laravel:11.x Feb 19, 2025
@devhammed devhammed deleted the feat-add-support-for-custom-event-stream-name-and-optional-event-stream-start-and-end-tokens branch February 19, 2025 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants