-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (46 loc) · 1.56 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
var mongoose = require('mongoose');
var Q = require('q');
var _ = require('lodash');
var ChatUserMethods = require('./lib/methods/ChatUser');
var ChatMessageMethods = require('./lib/methods/ChatMessage');
var ChatRoomMethods = require('./lib/methods/ChatRoom');
var ChatzzMethods = require('./lib/methods/Chatzz');
var isInitialized = false;
var chatzzConfig = null;
var init = function(httpServer, config) {
if (isInitialized) {
return;
}
if (mongoose.connection.readyState !== 1) {
return console.log('valid mongoose instance is required by chatzz');
}
chatzzConfig = config || {};
ChatzzMethods.initChatzz(httpServer);
ChatUserMethods.initModel(chatzzConfig.chatUserModelName, chatzzConfig.userModelName);
ChatRoomMethods.initModel();
ChatMessageMethods.initModel(chatzzConfig.chatUserModelName);
isInitialized = true;
};
var getChatzzConfig = function() {
return chatzzConfig;
};
var getMethodsToExport = function() {
var methodsToExport = {
init: init,
getChatzzConfig: getChatzzConfig
};
var ignoreExports = ['initChatzz'];
_.forEach([ChatUserMethods, ChatMessageMethods], function(methodCollection) {
_.forEach(methodCollection, function(key, value) {
if (ignoreExports.indexOf(key) > -1) {
return;
}
if (methodsToExport[key]) {
console.log(key, 'already exists');
}
methodsToExport[key] = value;
});
});
return methodsToExport;
};
module.exports = getMethodsToExport();