npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@babblevoice/babble-drachtio-callmanager

v3.5.8

Published

Call processing to create a PBX

Downloads

254

Readme

babble-drachtio-callmanager

Provide simplified interface to handle calls with drachtio. This project pulls together all of the required components for a scalable PBX. A registrar, RTP engine.

This project interfaces with babble-projectrtp.


const Srf = require( "drachtio-srf" )
const Registrar = require( "babble-drachtio-registrar" )
const CallManager = require( "babble-drachtio-callmanager" )
const config = require( "config" )

const srf = new Srf()
srf.connect( config.drachtio )

srf.on( "connect", ( err, hostport ) => {
  console.log( `Connected to a drachtio server listening on: ${hostport}` )
} )

/* A simple example of looking up a password in our config */
function passwordLookup( username, realm, callback ) {
  realm = realm.split( "." ).reverse().join( "." )
  let key = "directory." + realm + "." + username
  if( !config.has( key ) ) {
    return callback( null, false )
  }

  key += ".secret"
  return callback( null, config.get( key ) )
}

const r = new Registrar( {
  "srf": srf,
  //"optionsping": 30, /* Seconds between our OPTIONs packet to registered client - controls the stale flag */
  "regping": 30, /* Number of seconds we force the client to reregister without requiring reauth - controls the stale flag */
  "staletime": 180, /* number of seconds we consider a client stale if we don't hear a response from an OPTIONS or REGISTER ping */
  "expires": 3600, /* default expires */
  "minexpires": 3600, /* Force the client with 423 to extend expires to this amount - conflicts with regping */
  "userlookup": passwordLookup,
  "forcerport": true /* when sending invite - request rport */
} )


const cm = new CallManager( {
  "srf": srf,
  "registrar": r,
  "userlookup": passwordLookup
} )

cm.on( "call", async ( c ) => {

} )

When call manager presents a new call it passes a call object as part of it. The original req and res from Drachtio are members of this object. The call object also has the following methods.

CallManager takes an options object as part of its construction. srf and a passwordLookup function are required. Options for codecs and transcoding can also be supplied:

{
  "srf": srf,
  "userlookup": passwordLookup,
  "preferedcodecs": "pcmu pcma 2833",
  "transcode": true
}

auth

Forces the client to authenticate. Returns a promise.

ring

Sends back 180 (ringing).

busy

Ends the call with busy.

answer

Answers the call (creates a dialog) and opens the required channel. Returns a promise.

audio

Returns the audio channel.

hangup( cause )

Ends the call (or cancels).

waitforevents( regex, timeout = 30000mS )

Waits for telephone events (DTMF). We pass a regular expression in to match the entered digits. In the example below, 2 digits (any in the DTMF range) are required followed by the hash key.

If the user dials 123456 = it will not trigger as there is no '#' at the end. If they dial 1234567# then it will return with e = 67#

var e = await call.waitforevents( /[0-9A-D\*#]{2}#/ )
console.log( "waited and got " + e )

waitforhangup

Returns a promise which is resolved when the call object is hungup. Useful if you wish to further actions when a child call has hung up.

Events

Events are published to either a global event emitter and a call specific one. This allows us to pass events back to a presences system (global) or for a call script to handle an event for that call.

To subscribe to call specific events:

cm.on( "call", async ( c ) => {
  c.on( "call.destroyed", ( call ) => {
    /* clean up */
  } )
} )

Examples

Authorise the call, sending ringing then answer. Once answered, echo RTP data back to the client.

cm.on( "call", async ( c ) => {

  await call.auth()
  call.ring()
  await call.answer()

  call.channels.audio.echo()
} )

An example for prompting and waiting for DTMF (auto attendant).

No auth or need to send ringing, we answer and when answered, we play a file then wait for caller to enter input.

cm.on( "call", async ( c ) => {

  await call.answer()

  call.channels.audio.play( { "files": [ { "wav": "pleasedialoneforsalesandtwofortech.wav" } ] } )

  var e = await call.waitforevents( /[0-1]/ )
  console.log( "waited and got " + e )
} )

JSDoc

jsdoc -r -p lib/

Development

I use to develop locally other modules against this module

npm link projectrtp npm link babble-drachtio-registrar npm link babble-drachtio-auth

References

  • SIP: Session Initiation Protocol RFC 3261
  • The Session Initiation Protocol (SIP) Refer Method RFC 3515
  • Session Initiation Protocol (SIP) Call Control - Transfer RFC 5589
  • Session Timers in the Session Initiation Protocol (SIP) RFC 4028
  • Session Initiation Protocol Service Examples RFC 5359
  • HTTP Authentication: Basic and Digest Access Authentication RFC 2617
  • SIP Digest examples draft-smith-sipping-auth-examples-01
  • Extended Secure RTP Profile for Real-time Transport Control Protocol (RTCP)-Based Feedback (RTP/SAVPF) RFC 5124
  • Source-Specific Media Attributes in the Session Description Protocol (SDP)RFC 5576
  • Cross Session Stream Identification in the Session Description Protocol (msid in SDP) draft-ietf-mmusic-msid-00

Need to look at

  • A Framework for Conferencing with the Session Initiation Protocol (SIP) RFC 4353