bigbluebutton-Github/labs/bbb-callback/app.js
2013-11-04 07:30:26 -08:00

52 lines
1.7 KiB
JavaScript
Executable File

var request = require('request'),
redis = require("redis"),
subscriber = redis.createClient(),
client = redis.createClient();
subscriber.on("subscribe", function (channel, count) {
console.log("subscribed to " + channel);
});
subscriber.on("message", function (channel, message) {
var properties;
try {
properties = JSON.parse(message);
} catch (e) {
// An error has occured, handle it, by e.g. logging it
console.log(e);
}
if (properties != undefined){
client.lrange("meeting:" + properties.meetingID + ":subscriptions", 0, -1, function(error,reply){
reply.forEach(function (sid, index) {
console.log("subscriber id = " + sid);
client.hgetall("meeting:" + properties.meetingID + ":subscription:" + sid, function(err,rep){
if (rep.active == "true") {
properties.meetingID = rep.externalMeetingID;
var post_options = {
uri: rep.callbackURL,
method: 'POST',
json: properties
};
request(post_options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log("Error calling url: [" + post_options.uri + "]")
console.log("Error: [" + JSON.stringify(error) + "]");
console.log("Response: [" + JSON.stringify(response) + "]");
} else {
console.log("Passed calling url: [" + post_options.uri + "]")
console.log("Response: [" + JSON.stringify(response) + "]");
}
});
}
});
});
});
}
});
subscriber.subscribe("bigbluebutton:webhook_events");