3 const env
= require('gitter-web-env');
4 const logger
= env
.logger
;
5 const config
= env
.config
;
6 const errorReporter
= env
.errorReporter
;
7 const obfuscateToken
= require('gitter-web-github').obfuscateToken
;
9 const matrixBridge
= require('./lib/matrix-bridge');
10 const GitterBridge
= require('./lib/gitter-bridge');
11 const MatrixUtils
= require('./lib/matrix-utils');
13 const bridgePortFromConfig
= config
.get('matrix:bridge:applicationServicePort');
14 const hsToken
= config
.get('matrix:bridge:hsToken');
15 const asToken
= config
.get('matrix:bridge:asToken');
17 // Ensures the bridge bot user is registered and updates its profile info.
18 async
function ensureCorrectMatrixBridgeUserProfile() {
20 const matrixUtils
= new MatrixUtils(matrixBridge
);
21 await matrixUtils
.ensureCorrectMatrixBridgeUserProfile();
23 logger
.error(`Failed to update the bridge user profile`, {
26 errorReporter(err
, { operation
: 'matrixBridge.install' }, { module
: 'matrix-bridge-install' });
30 const gitterBridge
= new GitterBridge(matrixBridge
);
32 async
function install(bridgePort
= bridgePortFromConfig
) {
33 if (!bridgePort
|| !hsToken
|| !asToken
) {
35 `No (bridgePort=${bridgePort}, hsToken=${obfuscateToken(hsToken)}, asToken=${obfuscateToken(
37 )}) specified for Matrix bridge so we won't start it up`
42 await matrixBridge
.run(bridgePort
);
43 logger
.info(`Matrix bridge listening on port ${bridgePort}`);
45 await gitterBridge
.start();
47 // Fire and forget this (no need to hold up the process by awaiting it)
48 ensureCorrectMatrixBridgeUserProfile();
50 return async
function stop() {
51 await matrixBridge
.close();
52 await gitterBridge
.stop();
56 module
.exports
= install
;