3 var env = require('gitter-web-env');
4 var logger = env.logger;
5 var errorReporter = env.errorReporter;
6 var liveCollectionEvents = require('gitter-web-live-collection-events');
8 // This is a bit crazy, but we need to get around node circular references
10 events: './live-collection-events',
11 chats: './live-collection-chats',
12 rooms: './live-collection-rooms',
13 roomSecurityDescriptors: './live-collection-room-security-descriptors',
14 groupSecurityDescriptors: './live-collection-group-security-descriptors',
15 roomMembers: './live-collection-room-members',
16 users: './live-collection-users',
17 userGroups: './live-collection-user-groups',
18 groupMembers: './live-collection-group-members'
25 var installed = false;
27 if (installed) return;
30 Object.keys(handlers).forEach(function(category) {
31 var handlerModuleName = handlers[category];
32 var emitter = liveCollectionEvents[category];
36 'No event emitted defined for ' +
38 '. gitter-web-live-collection-events probably needs updating.'
42 // Don't load the library until install is called otherwise
43 // we'll introduce circular references
44 var lib = require(handlerModuleName); // Load the handler
46 Object.keys(lib).forEach(function(eventName) {
47 emitter.on(eventName, function() {
48 var possiblePromise = lib[eventName].apply(lib, arguments);
50 /* Some unimplemented methods don't return anything */
51 if (possiblePromise) {
52 possiblePromise.catch(function(err) {
53 logger.error('live-collection handler failed: ' + err, { exception: err });
56 { live_collection_handler: 'failed' },
57 { module: 'live-collection' }