mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 16:06:16 -04:00
socket.io: Reconnect if the server disconnects
This will make the pages gracefully handle HTTP server restart events, which happen whenever a plugin is installed or uninstalled via the `/admin/plugins` page.
This commit is contained in:
parent
303964c51e
commit
9f7d42185d
4 changed files with 36 additions and 8 deletions
|
@ -4,6 +4,11 @@
|
||||||
|
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
const socket = socketio.connect('..', '/pluginfw/installer');
|
const socket = socketio.connect('..', '/pluginfw/installer');
|
||||||
|
socket.on('disconnect', (reason) => {
|
||||||
|
// The socket.io client will automatically try to reconnect for all reasons other than "io
|
||||||
|
// server disconnect".
|
||||||
|
if (reason === 'io server disconnect') socket.connect();
|
||||||
|
});
|
||||||
|
|
||||||
const search = (searchTerm, limit) => {
|
const search = (searchTerm, limit) => {
|
||||||
if (search.searchTerm !== searchTerm) {
|
if (search.searchTerm !== searchTerm) {
|
||||||
|
@ -253,10 +258,12 @@ $(document).ready(() => {
|
||||||
search.results = [];
|
search.results = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
// init
|
socket.on('connect', () => {
|
||||||
updateHandlers();
|
updateHandlers();
|
||||||
socket.emit('getInstalled');
|
socket.emit('getInstalled');
|
||||||
search('');
|
search.searchTerm = null;
|
||||||
|
search($('#search-query').val());
|
||||||
|
});
|
||||||
|
|
||||||
// check for updates every 5mins
|
// check for updates every 5mins
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
|
|
@ -5,6 +5,16 @@
|
||||||
$(document).ready(() => {
|
$(document).ready(() => {
|
||||||
const socket = socketio.connect('..', '/settings');
|
const socket = socketio.connect('..', '/settings');
|
||||||
|
|
||||||
|
socket.on('connect', () => {
|
||||||
|
socket.emit('load');
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('disconnect', (reason) => {
|
||||||
|
// The socket.io client will automatically try to reconnect for all reasons other than "io
|
||||||
|
// server disconnect".
|
||||||
|
if (reason === 'io server disconnect') socket.connect();
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('settings', (settings) => {
|
socket.on('settings', (settings) => {
|
||||||
/* Check whether the settings.json is authorized to be viewed */
|
/* Check whether the settings.json is authorized to be viewed */
|
||||||
if (settings.results === 'NOT_ALLOWED') {
|
if (settings.results === 'NOT_ALLOWED') {
|
||||||
|
@ -46,8 +56,6 @@ $(document).ready(() => {
|
||||||
$('#response').text(progress);
|
$('#response').text(progress);
|
||||||
$('#response').fadeOut('slow');
|
$('#response').fadeOut('slow');
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.emit('load'); // Load the JSON from the server
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -238,15 +238,25 @@ const handshake = () => {
|
||||||
sendClientReady(receivedClientVars);
|
sendClientReady(receivedClientVars);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('reconnecting', () => {
|
const socketReconnecting = () => {
|
||||||
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
||||||
if (pad.collabClient != null) {
|
if (pad.collabClient != null) {
|
||||||
pad.collabClient.setStateIdle();
|
pad.collabClient.setStateIdle();
|
||||||
pad.collabClient.setIsPendingRevision(true);
|
pad.collabClient.setIsPendingRevision(true);
|
||||||
pad.collabClient.setChannelState('RECONNECTING');
|
pad.collabClient.setChannelState('RECONNECTING');
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
socket.on('disconnect', (reason) => {
|
||||||
|
// The socket.io client will automatically try to reconnect for all reasons other than "io
|
||||||
|
// server disconnect".
|
||||||
|
if (reason !== 'io server disconnect') return;
|
||||||
|
socketReconnecting();
|
||||||
|
socket.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('reconnecting', socketReconnecting);
|
||||||
|
|
||||||
socket.on('reconnect_failed', (error) => {
|
socket.on('reconnect_failed', (error) => {
|
||||||
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
// pad.collabClient might be null if the hanshake failed (or it never got that far).
|
||||||
if (pad.collabClient != null) {
|
if (pad.collabClient != null) {
|
||||||
|
|
|
@ -59,8 +59,11 @@ const init = () => {
|
||||||
sendSocketMsg('CLIENT_READY', {});
|
sendSocketMsg('CLIENT_READY', {});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', (reason) => {
|
||||||
BroadcastSlider.showReconnectUI();
|
BroadcastSlider.showReconnectUI();
|
||||||
|
// The socket.io client will automatically try to reconnect for all reasons other than "io
|
||||||
|
// server disconnect".
|
||||||
|
if (reason === 'io server disconnect') socket.connect();
|
||||||
});
|
});
|
||||||
|
|
||||||
// route the incoming messages
|
// route the incoming messages
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue