bigbluebutton-Github/labs/bbb-callback/app.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

var request = require('request'),
2013-06-13 07:49:32 +08:00
redis = require("redis"),
subscriber = redis.createClient(),
client = redis.createClient();
2013-06-08 04:47:18 +08:00
2013-06-13 07:49:32 +08:00
subscriber.on("subscribe", function (channel, count) {
console.log("subscribed to " + channel);
2013-06-08 04:47:18 +08:00
});
2013-06-13 07:49:32 +08:00
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);
}
2013-07-12 03:20:11 +08:00
if (properties != undefined){
client.lrange("meeting:" + properties.meetingID + ":subscriptions", 0, -1, function(error,reply){
reply.forEach(function (sid, index) {
2013-11-04 23:30:26 +08:00
console.log("subscriber id = " + sid);
client.hgetall("meeting:" + properties.meetingID + ":subscription:" + sid, function(err,rep){
2013-07-12 03:20:11 +08:00
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) {
2013-11-04 23:30:26 +08:00
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) + "]");
}
});
2013-06-13 07:49:32 +08:00
}
});
});
});
}
2013-06-08 04:47:18 +08:00
2013-06-13 07:49:32 +08:00
});
2013-06-08 04:47:18 +08:00
2013-11-04 23:30:26 +08:00
subscriber.subscribe("bigbluebutton:webhook_events");