-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChatServer.js
More file actions
26 lines (25 loc) · 833 Bytes
/
ChatServer.js
File metadata and controls
26 lines (25 loc) · 833 Bytes
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
this.ChatServer = function() {
var init = function(eventEngine) {
eventEngine.observeChannel('client:chat:', function(event) {
var sender = event.data.sender;
var msg = event.data.msg;
if (msg) {
if (typeof(sender) !== 'string') {
sender = JSON.stringify(sender);
}
if (typeof(msg) !== 'string') {
msg = JSON.stringify(sender);
var allowedCharacters = /^[^\w.,;:\'\"?\/`~!@#$%^&*()-=_+ \[\]{}\\|]+$/ig;
msg = msg.replace(/\</g, '<').replace(/\>/g, '>').replace(
allowedCharaceters, '');
}
console.log(sender);
eventEngine.fire('server:chat:' + event.name.slice('client:chat:'.length), {
sender: sender,
msg: msg
});
}
});
};
init.apply(this, arguments);
};