-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnode_helper.js
More file actions
28 lines (25 loc) · 912 Bytes
/
node_helper.js
File metadata and controls
28 lines (25 loc) · 912 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
27
28
const NodeHelper = require('node_helper');
const fetch = require('node-fetch');
const { URLSearchParams } = require('url');
module.exports = NodeHelper.create({
start: function() {
console.log('Starting node_helper for module [' + this.name + ']');
},
sendOffer: function(payload) {
console.log(`Offer requested for ${payload.identifier}`);
fetch(payload.url, {
method: 'POST',
body: new URLSearchParams({ data: payload.sdp })
})
.then(response => response.text())
.then(response_data => this.sendSocketNotification(`ANSWER_${payload.identifier}`, response_data))
.catch(error=>{
console.error(error);
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'OFFER') {
this.sendOffer(payload);
}
}
});