2020-12-20 08:15:58 +01:00
|
|
|
'use strict';
|
|
|
|
|
2011-12-04 16:33:56 +01:00
|
|
|
/**
|
2019-04-16 00:34:29 +02:00
|
|
|
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
2011-12-04 16:33:56 +01:00
|
|
|
* 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;
|
2012-01-16 06:37:47 +01:00
|
|
|
|
2020-12-20 08:15:58 +01:00
|
|
|
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 = {
|
2020-12-20 08:15:58 +01:00
|
|
|
init: () => {
|
2020-11-23 19:24:19 +01:00
|
|
|
$('button#forcereconnect').click(() => {
|
2011-05-19 23:27:17 +02:00
|
|
|
window.location.reload();
|
2011-03-26 14:10:41 +01:00
|
|
|
});
|
|
|
|
},
|
2020-12-20 08:15:58 +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
|
|
|
};
|
2012-07-13 08:23:22 +02:00
|
|
|
padmodals.showModal('connected');
|
2013-02-14 00:44:20 +01:00
|
|
|
padmodals.hideOverlay();
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +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
|
|
|
};
|
2019-04-16 00:34:29 +02:00
|
|
|
|
2012-07-13 08:23:22 +02:00
|
|
|
padmodals.showModal('reconnecting');
|
2013-02-14 00:44:20 +01:00
|
|
|
padmodals.showOverlay();
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
disconnected: (msg) => {
|
|
|
|
if (status.what === 'disconnected') return;
|
2019-04-16 00:34:29 +02:00
|
|
|
|
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
|
|
|
};
|
2020-09-13 05:51:32 +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.
|
2012-07-13 08:23:22 +02:00
|
|
|
k = 'disconnected';
|
2011-03-26 14:10:41 +01:00
|
|
|
}
|
2013-10-10 21:11:15 +02:00
|
|
|
|
2012-07-13 08:23:22 +02:00
|
|
|
padmodals.showModal(k);
|
2013-02-14 00:44:20 +01:00
|
|
|
padmodals.showOverlay();
|
2011-03-26 14:10:41 +01:00
|
|
|
},
|
2020-12-20 08:15:58 +01:00
|
|
|
isFullyConnected: () => status.what === 'connected',
|
|
|
|
getStatus: () => status,
|
2011-03-26 14:10:41 +01:00
|
|
|
};
|
|
|
|
return self;
|
2020-12-20 08:15:58 +01:00
|
|
|
})();
|
2012-01-16 02:23:48 +01:00
|
|
|
|
|
|
|
exports.padconnectionstatus = padconnectionstatus;
|