@eweser/db
Version:
eweser-db core database
22 lines (20 loc) • 546 B
text/typescript
import type { Database } from '../../index.js';
/** pings the matrix server and sets the result to db.online. emits an event on change */
export const checkServerConnection = async (db: Database) => {
const success = await db.pingServer();
if (success) {
if (db.online) {
return;
}
db.debug('Server is online');
db.online = true;
db.emit('onlineChange', true);
} else {
if (!db.online) {
return;
}
db.error('Server is offline');
db.online = false;
db.emit('onlineChange', false);
}
};