[fix] Add stop function to ServerEvent js plugin#1133
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1133 +/- ##
=============================================
- Coverage 75.83% 75.77% -0.07%
- Complexity 2534 2538 +4
=============================================
Files 130 130
Lines 6221 6230 +9
=============================================
+ Hits 4718 4721 +3
- Misses 1503 1509 +6
Continue to review full report at Codecov.
|
|
The problem i mentioned, was related to browser locking when window unload event is trigger. ui/js/src/plugins/server-event.plugin.js Lines 32 to 34 in e6d496b but i think that the listener must be removed. this is an example of the code to reproduce the issue : View::addTo($app)
->setElement('footer')
->addClass('ui basic segment mini')
->set('footer');
$sse = jsSSE::addTo($app, ['showLoader' => false]);
$sse->set(function () use ($sse) {
$count = 0;
ignore_user_abort(true); // i think this must be added to the jsSSE class
while(!connection_aborted()) { // and this check too, obviously without the while
sleep(1);
$sse->send(new jsExpression('console.log('.$count.')'));
$count++;
}
});
$app->html->template->appendHTML('HEAD', '<script type="application/javascript">' . $sse->jsRender() . '</script>');This code without that change prevent the browser reload |
|
@ibelar , @abbadon1334 Travis is failing probably not due to this PR, but should be fixed to prevent false positives, can you look at it? |
restart the build and it worked, sometime travis drink beer on saturday, that's it. |
I know, but that is not a long term solution, there is probably some expected but not synchronized/event-based check. |
add option for beforeUnload event
|
I have update the pr. Will now check if connection need to be keepAlive. I have also add a function that you can use when user stop execution. |
…into fix/server-event-plugin
abbadon1334
left a comment
There was a problem hiding this comment.
LGTM except the call to exit() which is okish, but even if is already dead the interaction with the user, calling exit there will not trigger the beforeExit hook
src/jsSSE.php
Outdated
| /* | ||
| * Implements a class that can be mapped into arbitrary JavaScript expression. | ||
| */ | ||
| // Implements a class that can be mapped into arbitrary JavaScript expression. |
There was a problem hiding this comment.
Done! Let's merge this in so it get include in next release.
Allow stopping of SSE event.
More info on demos/sse.php