drachtio / drachtio-srf

drachtio signaling resource framework
https://drachtio.org
MIT License
170 stars 60 forks source link

middleware for dialog events #30

Open byoungdale opened 5 years ago

byoungdale commented 5 years ago

I am working on a 'REFER' handler and was going to see about making it middleware, but there is no middleware handling for dialog events. So, the middleware could only be used on out of dialog REFER messages. Would adding something like the srf.use method to the dialog class be worthwhile? Or, since it's easy, just stick to using the REFER handler in the dialog.on callback?

I am picturing something like this:

const referHandler = require('refer-handler-middleware');

srf.createB2BUA(req, res, transferor, {localSdpB: req.body})
        .then(({uac, uas}) => {
          console.log('call connected');

          uas.use('refer', referHandler);

        })
        .catch((error) => {
          console.error(`Error: ${error}`);
        });
davehorton commented 5 years ago

That sounds pretty useful...I will look into this.