add support for multiple rtpengines

This commit is contained in:
Dave Horton
2020-02-17 09:23:52 -05:00
parent 75946e89a4
commit fa60d8a3be
2 changed files with 84 additions and 9 deletions
+12 -9
View File
@@ -1,6 +1,4 @@
const Emitter = require('events');
const Client = require('rtpengine-client').Client ;
const rtpengine = new Client();
const {getAppserver, isWSS, makeRtpEngineOpts} = require('./utils');
const {forwardInDialogRequests} = require('drachtio-fn-b2b-sugar');
const {parseUri, SipError} = require('drachtio-srf');
@@ -13,17 +11,22 @@ class CallSession extends Emitter {
this.res = res;
this.srf = req.srf;
this.logger = logger.child({callId: req.get('Call-ID')});
// TODO: we always using the first rtpengine here
// we should be load balancing, and doing some form of health checking
this.offer = rtpengine.offer.bind(rtpengine, this.srf.locals.rtpEngines[0]);
this.answer = rtpengine.answer.bind(rtpengine, this.srf.locals.rtpEngines[0]);
this.del = rtpengine.delete.bind(rtpengine, this.srf.locals.rtpEngines[0]);
}
async connect() {
const getRtpEngine = require('./rtpengine')(this.logger);
const engine = getRtpEngine();
if (!engine) {
this.logger.info('No available rtpengines, rejecting call!');
return this.res.send(480);
}
const {offer, answer, del} = engine;
this.offer = offer;
this.answer = answer;
this.del = del;
this.rtpEngineOpts = makeRtpEngineOpts(this.req, isWSS(this.req), false);
this.rtpEngineResource = {destroy: this.del.bind(rtpengine, this.rtpEngineOpts.common)};
this.rtpEngineResource = {destroy: this.del.bind(null, this.rtpEngineOpts.common)};
const obj = parseUri(this.req.uri);
const appServer = getAppserver(this.srf);
let proxy, host, uri;