@@ -124,23 +124,12 @@ public function jsonp($callback, $data = [], $status = 200, array $headers = [],
124
124
*
125
125
* @param \Closure $callback
126
126
* @param array $headers
127
- * @param string $as
128
- * @param string|null $startStreamWith
129
- * @param string|null $endStreamWith
127
+ * @param string $endStreamWith
130
128
* @return \Symfony\Component\HttpFoundation\StreamedResponse
131
129
*/
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> ' )
133
131
{
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 ) {
144
133
foreach ($ callback () as $ message ) {
145
134
if (connection_aborted ()) {
146
135
break ;
@@ -150,22 +139,20 @@ public function eventStream(Closure $callback, array $headers = [], string $as =
150
139
$ message = Js::encode ($ message );
151
140
}
152
141
153
- echo "event: $ as \n" ;
142
+ echo "event: update \n" ;
154
143
echo 'data: ' .$ message ;
155
144
echo "\n\n" ;
156
145
157
146
ob_flush ();
158
147
flush ();
159
148
}
160
149
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" ;
165
153
166
- ob_flush ();
167
- flush ();
168
- }
154
+ ob_flush ();
155
+ flush ();
169
156
}, 200 , array_merge ($ headers , [
170
157
'Content-Type ' => 'text/event-stream ' ,
171
158
'Cache-Control ' => 'no-cache ' ,
0 commit comments