3.5.8 • Published 15 days ago

@babblevoice/babble-drachtio-callmanager v3.5.8

Weekly downloads
-
License
MIT
Repository
github
Last release
15 days ago

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
3.5.8

15 days ago

3.5.7

24 days ago

3.5.6

26 days ago

3.5.3

30 days ago

3.5.5

30 days ago

3.5.4

30 days ago

3.5.2

2 months ago

3.5.1

2 months ago

3.5.0

2 months ago

3.4.1

2 months ago

3.4.0

3 months ago

3.3.6

3 months ago

3.3.5

3 months ago

3.3.4

3 months ago

3.3.3

4 months ago

3.3.2

4 months ago

3.3.1

5 months ago

3.3.0

5 months ago

3.2.0

5 months ago

3.1.0

5 months ago

3.0.0

5 months ago

2.3.28

6 months ago

2.3.27

6 months ago

2.3.24

6 months ago

2.3.23

6 months ago

2.3.26

6 months ago

2.3.25

6 months ago

2.3.22

6 months ago

2.3.21

6 months ago

2.2.3

10 months ago

2.2.2

10 months ago

2.2.5

8 months ago

2.2.4

8 months ago

2.2.7

8 months ago

2.2.6

8 months ago

2.3.20

7 months ago

2.3.8

7 months ago

2.3.7

7 months ago

2.3.9

7 months ago

2.3.0

8 months ago

2.3.2

8 months ago

2.3.1

8 months ago

2.3.4

8 months ago

2.3.3

8 months ago

2.3.6

8 months ago

2.3.5

8 months ago

2.3.17

7 months ago

2.3.16

7 months ago

2.3.19

7 months ago

2.3.18

7 months ago

2.3.13

7 months ago

2.3.12

7 months ago

2.3.15

7 months ago

2.3.14

7 months ago

2.3.11

7 months ago

2.3.10

7 months ago

2.2.1

10 months ago

2.0.3

11 months ago

2.2.0

11 months ago

2.1.2

11 months ago

2.1.1

11 months ago

2.1.0

11 months ago

2.0.2

12 months ago

2.0.1

1 year ago

1.6.17

1 year ago

1.6.16

1 year ago

1.6.18

1 year ago

1.6.15

1 year ago

1.6.14

2 years ago

1.6.4

2 years ago

1.6.9

2 years ago

1.6.11

2 years ago

1.6.8

2 years ago

1.6.10

2 years ago

1.6.7

2 years ago

1.6.13

2 years ago

1.6.6

2 years ago

1.6.12

2 years ago

1.6.5

2 years ago

1.6.3

2 years ago

1.6.2

2 years ago

1.5.3

2 years ago

1.6.1

2 years ago

1.5.2

2 years ago

1.6.0

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago