Skip to content

Commit 83dfc24

Browse files
authored
Revert "[11.x] Enhance eventStream to Support Custom Events and Start Message…" (#54714)
This reverts commit cc1a3e8.
1 parent e0704ca commit 83dfc24

File tree

1 file changed

+9
-22
lines changed

1 file changed

+9
-22
lines changed

src/Illuminate/Routing/ResponseFactory.php

+9-22
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,12 @@ public function jsonp($callback, $data = [], $status = 200, array $headers = [],
124124
*
125125
* @param \Closure $callback
126126
* @param array $headers
127-
* @param string $as
128-
* @param string|null $startStreamWith
129-
* @param string|null $endStreamWith
127+
* @param string $endStreamWith
130128
* @return \Symfony\Component\HttpFoundation\StreamedResponse
131129
*/
132-
public function eventStream(Closure $callback, array $headers = [], string $as = 'update', ?string $startStreamWith = null, ?string $endStreamWith = '</stream>')
130+
public function eventStream(Closure $callback, array $headers = [], string $endStreamWith = '</stream>')
133131
{
134-
return $this->stream(function () use ($callback, $as, $startStreamWith, $endStreamWith) {
135-
if (filled($startStreamWith)) {
136-
echo "event: $as\n";
137-
echo 'data: '.$startStreamWith;
138-
echo "\n\n";
139-
140-
ob_flush();
141-
flush();
142-
}
143-
132+
return $this->stream(function () use ($callback, $endStreamWith) {
144133
foreach ($callback() as $message) {
145134
if (connection_aborted()) {
146135
break;
@@ -150,22 +139,20 @@ public function eventStream(Closure $callback, array $headers = [], string $as =
150139
$message = Js::encode($message);
151140
}
152141

153-
echo "event: $as\n";
142+
echo "event: update\n";
154143
echo 'data: '.$message;
155144
echo "\n\n";
156145

157146
ob_flush();
158147
flush();
159148
}
160149

161-
if (filled($endStreamWith)) {
162-
echo "event: $as\n";
163-
echo 'data: '.$endStreamWith;
164-
echo "\n\n";
150+
echo "event: update\n";
151+
echo 'data: '.$endStreamWith;
152+
echo "\n\n";
165153

166-
ob_flush();
167-
flush();
168-
}
154+
ob_flush();
155+
flush();
169156
}, 200, array_merge($headers, [
170157
'Content-Type' => 'text/event-stream',
171158
'Cache-Control' => 'no-cache',

0 commit comments

Comments
 (0)