Closed anhphamtien closed 4 months ago
SOLVED
In my case, I want trigger event 'close' when server is down without _pollAgain
so I add the else condition
_pollAgain(time, allowZero) {
if (time > 0 || allowZero) {
this._logDebug(`[EventSource] Will open new connection in ${time} ms.`);
this._pollTimer = setTimeout(() => {
this.open();
}, time);
}
// custom code
else {
this.dispatch('close', { type: 'close' });
}
}
The only time react-native-sse will emit a close
event is when the client closes the connection, i.e. by calling es.close()
.
When the server closes the connection, the client just automatically reopens it (unless you set pollingInterval
to 0). No close
event gets emitted in this case.
In other words, what you are seeing is the expected behavior and in line with the SSE protocol. SSE connections are not really meant to be closed by the server. They normally just stay open until the client closes them.
package.jgon
use
Log