This repository was archived by the owner on Jan 17, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
60 lines (55 loc) · 1.75 KB
/
util.js
File metadata and controls
60 lines (55 loc) · 1.75 KB
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
/**
* Helper functions
* @constructor
*/
var config = require('./config');
module.exports = function Util() {
return {
/**
* Concat some chatobject params to get a roomname
* @param chatobject
* @returns {*}
*/
getRoomNameFromChatobject: function (chatobject) {
var append = '';
// Private messages rooms.
if (chatobject.pm_userid !== undefined) {
// Ending up with same room naming.
append += '_pm_';
if(chatobject.pm_userid > chatobject.userid){
append += chatobject.pm_userid + '_' + chatobject.userid;
}else{
append += chatobject.userid + '_' + chatobject.pm_userid;
}
}
return chatobject.broadcastkey + chatobject.room + append;
},
/**
* Check if the client has a valid token / shared secret
* Also we checking if the hostname are matching
*
* @param token
* @param hostname
* @returns {*}
*/
validToken: function (token, hostname) {
if (config.servers[token] !== undefined) {
if (config.servers[token].hostname !== hostname) {
return {
error : 'hostname_incorrect',
status: false
};
}
return {
status : true,
namespace: config.servers[token].namespace,
callback: config.servers[token].callback
};
}
return {
error : 'wrong_token',
status: false
};
}
};
}