pad.libre-service.eu-etherpad/src/static/js/pad_connectionstatus.js

93 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
/**
* This code is mostly from the old Etherpad. Please help us to comment this code.
* This helps other people to understand this code better and helps them to improve it.
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
*/
2011-03-26 14:10:41 +01:00
/**
* Copyright 2009 Google Inc.
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* http://www.apache.org/licenses/LICENSE-2.0
2011-07-07 19:59:34 +02:00
*
2011-03-26 14:10:41 +01:00
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS-IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2020-11-23 19:24:19 +01:00
const padmodals = require('./pad_modals').padmodals;
const padconnectionstatus = (() => {
2020-11-23 19:24:19 +01:00
let status = {
what: 'connecting',
2011-07-07 19:59:34 +02:00
};
2011-03-26 14:10:41 +01:00
2020-11-23 19:24:19 +01:00
const self = {
init: () => {
2020-11-23 19:24:19 +01:00
$('button#forcereconnect').click(() => {
window.location.reload();
2011-03-26 14:10:41 +01:00
});
},
connected: () => {
2011-07-07 19:59:34 +02:00
status = {
2020-11-23 19:24:19 +01:00
what: 'connected',
2011-07-07 19:59:34 +02:00
};
padmodals.showModal('connected');
padmodals.hideOverlay();
2011-03-26 14:10:41 +01:00
},
reconnecting: () => {
2011-07-07 19:59:34 +02:00
status = {
2020-11-23 19:24:19 +01:00
what: 'reconnecting',
2011-07-07 19:59:34 +02:00
};
padmodals.showModal('reconnecting');
padmodals.showOverlay();
2011-03-26 14:10:41 +01:00
},
disconnected: (msg) => {
if (status.what === 'disconnected') return;
2011-07-07 19:59:34 +02:00
status = {
what: 'disconnected',
2020-11-23 19:24:19 +01:00
why: msg,
2011-07-07 19:59:34 +02:00
};
// These message IDs correspond to localized strings that are presented to the user. If a new
// message ID is added here then a new div must be added to src/templates/pad.html and the
// corresponding l10n IDs must be added to the language files in src/locales.
const knownReasons = [
'badChangeset',
'corruptPad',
'deleted',
'disconnected',
'initsocketfail',
'looping',
'rateLimited',
'rejected',
'slowcommit',
'unauth',
'userdup',
];
let k = String(msg);
if (knownReasons.indexOf(k) === -1) {
// Fall back to a generic message.
k = 'disconnected';
2011-03-26 14:10:41 +01:00
}
padmodals.showModal(k);
padmodals.showOverlay();
2011-03-26 14:10:41 +01:00
},
isFullyConnected: () => status.what === 'connected',
getStatus: () => status,
2011-03-26 14:10:41 +01:00
};
return self;
})();
exports.padconnectionstatus = padconnectionstatus;