forked from Atlantis-Software/node-turn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatePermission.js
37 lines (31 loc) · 952 Bytes
/
createPermission.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
var createPermission = function(server) {
var self = this;
this.server = server;
this.server.on('create_permission', function(msg, reply) {
self.createPermission(msg, reply);
});
};
createPermission.prototype.createPermission = function(msg, reply) {
var xorPeerAddresses = msg.getAttributes('xor-peer-address');
if (xorPeerAddresses.length === 0) {
return reply.reject(400, 'Bad Request');
}
var badRequest = false;
var permissions = [];
xorPeerAddresses.forEach(function(xorPeerAddress) {
if (!xorPeerAddress.address) {
badRequest = true;
}
permissions.push(xorPeerAddress.address);
});
if (badRequest) {
return reply.reject(400, 'Bad Request');
}
permissions.forEach(function(address) {
msg.allocation.permit(address);
});
reply.addAttribute('software', this.server.software);
reply.addAttribute('message-integrity');
reply.resolve();
};
module.exports = createPermission;