How to use drachtio-srf - 8 common examples

To help you get started, we’ve selected a few drachtio-srf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davehorton / drachtio-rtpengine-webrtcproxy / lib / subscriber.js View on Github external
srf.subscribe((req, res) => {

      this.logger.info(`UAC subscribing: ${req.protocol}/${req.source_address}:${req.source_port}`) ;

      // only registered users are allowed to subscribe
      const from = req.getParsedHeader('from') ;
      const fromUser = parseUri(from.uri).user ;
      const callid = req.get('Call-Id');

      if (!registrar.hasUser(fromUser)) {
        this.logger.fino(`invalid/unknown user ${fromUser} attempting to subscribe`) ;
        return res.send(503);
      }

      // check if we have a call-id / cseq that we used previously on a 401-challenged SUBSCRIBE
      const headers = {} ;
      const obj = registrar.getNextCallIdAndCSeq(callid) ;
      if (obj) {
        Object.assign(headers, obj) ;
        registrar.removeTransaction(callid) ;
      }
      else {
        Object.assign(headers, {'CSeq': '1 INVITE'}) ;
github davehorton / drachtio-siprec-recording-server / lib / payload-parser.js View on Github external
if (arr) {
                const uri = parseUri(arr[1]);
                const user = uri.user || 'anonymous';
                opts.caller.aor = `sip:${user}@${uri.host}`;
              }
              const dname = r1[1].trim();
              const arr2 = /"(.*)"/.exec(dname);
              if (arr2) opts.caller.name = arr2[1];
              else opts.caller.name = dname;
            }
            // callee
            r1 = /^(.*)(/.exec(r1[2]);
              if (arr) {
                const uri = parseUri(arr[1]);
                opts.callee.aor = `sip:${uri.user}@${uri.host}`;
              }
              const dname = r1[1].trim();
              const arr2 = /"(.*)"/.exec(dname);
              if (arr2) opts.callee.name = arr2[1];
              else opts.callee.name = dname;
            }
            debug(`opts.caller from callData: ${JSON.stringify(opts.caller)}`);
            debug(`opts.callee from callData: ${JSON.stringify(opts.callee)}`);
          }

          if (opts.caller.aor && 0 !== opts.caller.aor.indexOf('sip:')) {
            opts.caller.aor = 'sip:' + opts.caller.aor;
          }
          if (opts.callee.aor && 0 !== opts.callee.aor.indexOf('sip:')) {
            opts.callee.aor = 'sip:' + opts.callee.aor;
github davehorton / drachtio-rtpengine-webrtcproxy / lib / register.js View on Github external
srf.register(mw, (req, res) => {
      const callid = req.get('Call-Id');

      debug(`UAC registering: ${req.protocol}/${req.source_address}:${req.source_port} with uri ${req.uri}`) ;

      if (!isValidRegister(req)) {
        this.logger.info(`invalid register request: ${req.get('Call-Id')} ${req.get('CSeq')}`) ;
        return res.send(503);
      }
      const instanceId = req.registration.contact[0].params['+sip.instance'] ;
      const regId = req.registration.contact[0].params['reg-id'] ;
      const uri = parseUri(req.uri) ;
      const headers = {} ;

      // check if we have a call-id / cseq that we are using for this transaction
      const obj = registrar.getNextCallIdAndCSeq(callid) ;
      if (obj) {
        Object.assign(headers, obj) ;
      }
      else {
        Object.assign(headers, {'CSeq': '1 REGISTER'}) ;
      }

      ['from', 'to', 'authorization', 'supported', 'allow', 'user-agent'].forEach((hdr) => {
        if (req.has(hdr)) headers[hdr] = req.get(hdr) ;
      }) ;

      const uacContact = req.getParsedHeader('Contact') ;
github davehorton / drachtio-rtpengine-webrtcproxy / lib / register.js View on Github external
// check if we have a call-id / cseq that we are using for this transaction
      const obj = registrar.getNextCallIdAndCSeq(callid) ;
      if (obj) {
        Object.assign(headers, obj) ;
      }
      else {
        Object.assign(headers, {'CSeq': '1 REGISTER'}) ;
      }

      ['from', 'to', 'authorization', 'supported', 'allow', 'user-agent'].forEach((hdr) => {
        if (req.has(hdr)) headers[hdr] = req.get(hdr) ;
      }) ;

      const uacContact = req.getParsedHeader('Contact') ;
      const from = req.getParsedHeader('From') ;
      const user = parseUri(from.uri).user ;

      // NB: drachtio server will replace 'localhost' appropriately
      headers.contact = `;expires=${req.registration.expires}` ;

      srf.request({
        uri: req.uri,
        method: req.method,
        headers
      }, (err, request) => {
        if (err) {
          return this.logger.info(`Error forwarding register to ${uri.host}: ${err}`);
        }
        request.on('response', (response) => {
          const headers = {} ;
          ['www-authenticate'].forEach((hdr) => {
            if (response.has(hdr)) headers[hdr] = response.get(hdr);
github davehorton / drachtio-rtpengine-webrtcproxy / lib / call-processor.js View on Github external
srf.invite((req, res) => {
      this.logger.info(
        `received invite from ${req.protocol}/${req.source_address}:${req.uri} with request uri ${req.uri}`);

      // determine whether this is a call from or to a webrtc client
      const callid = req.get('Call-Id');
      const from = req.getParsedHeader('From');
      let remoteUri = req.uri ;
      let direction = 'outbound' ;
      const parsedUri = parseUri(req.uri);
      const user = parsedUri.user ;
      const trunk = parsedUri.host;
      const rtpEngineIdentifyingDetails = {
        'call-id': callid,
        'from-tag': from.params.tag,
      } ;

      const voipProviderFacingProxyCharacteristics = {
        'transport protocol': 'RTP/AVP',
        'DTLS': 'off',
        'SDES': 'off',
        'ICE': 'remove',
        'rtcp-mux': ['demux']
      };
      const webrtcFacingProxyCharacteristics = {
        'ICE': 'force',
github davehorton / drachtio-rtpengine-webrtcproxy / lib / call-processor.js View on Github external
const parseUri = require('drachtio-srf').parseUri ;
const SipError = require('drachtio-srf').SipError;
const config = require('config');
const debug = require('debug')('drachtio-rtpengine-webrtcproxy') ;

class CallProcessor {

  /**
   * creates an instance of the call processor.  this is intended to be a singleton instance.
   * you call the 'start' method to kick it off
   */
  constructor(logger) {
    this._logger = logger;

    // we need to track these only so we can fixup REFER messages for attended transfer
    this.calls = new Map() ;
  }
github davehorton / drachtio-siprec-recording-server / lib / payload-parser.js View on Github external
if (opts.caller.aor) {
            let user;
            const uri = parseUri(opts.caller.aor);
            if (uri) user = uri.user;
            else {
              const arr = /sip:(.*)@/.exec(opts.caller.aor);
              if (arr) {
                user = arr[1];
              }
            }
            debug(`parsed user ${user} from caller aor ${opts.caller.aor}`);
            opts.caller.number = user;
          }
          if (opts.callee.aor) {
            let user;
            const uri = parseUri(opts.callee.aor);
            if (uri) user = uri.user;
            else {
              const arr = /sip:(.*)@/.exec(opts.callee.aor);
              if (arr) {
                user = arr[1];
              }
            }
            debug(`parsed user ${user} from callee aor ${opts.callee.aor}`);
            opts.callee.number = user;
          }
          opts.recordingSessionId = opts.recordingData[`${prefix}recording`][`${prefix}session`][0].$.session_id;
        } 
      }
      catch (err) {
        console.log(`Error parsing ${err}`);
        reject(err);
github davehorton / drachtio-rtpengine-webrtcproxy / lib / subscriber.js View on Github external
const parseUri = require('drachtio-srf').parseUri ;
const SipError = require('drachtio-srf').SipError;

class Subscriber {

  constructor(logger) {
    this._logger = logger;
  }

  get logger() {
    return this._logger;
  }

  start(srf, registrar) {
    srf.subscribe((req, res) => {

      this.logger.info(`UAC subscribing: ${req.protocol}/${req.source_address}:${req.source_port}`) ;

drachtio-srf

drachtio signaling resource framework

MIT
Latest version published 6 months ago

Package Health Score

65 / 100
Full package analysis

Popular drachtio-srf functions

Similar packages