Node module for projectrtp the RTP server. This, as well as projectrtp, is work in progress.
There is also a utility class for SDP manipulation which uses the sdp-transform library for parsing and generating.
const projectrtp = require( "babble-projectrtp" )
const rtp = new projectrtp()
This will start a server listening. RTP servers then can connect to us so that we can distribute work to them.
A channel opens a stream between the ProjectRTP server and the UAC (or UAS).
rtp.channel( remote )
.then( ch => {
// Do something this the channel. Perhaps display info about it.
console.log( ch )
} )
ch.destroy()
.then( () => { console.log( "Channel destroyed" ) })
Mix 1 + n channels together.
A simple echo RTP back to other end.
ch.echo()
Play a sound 'soup' to the other end. See projectrtp for more information.
ch.play( {
"loop": true,
"files": [
{ "wav": "ringing.wav", "loop": 6 },
{ "wav": "youare.wav" },
{ "wav": "first.wav" },
{ "wav": "inline.wav" }
]
} )
Can take options as per projectrtp: file = - filename to save as
In seconds up to MA max size (5 seconds?), default is 1 second RMS power is calculated from each packet then averaged using a moving average filter. poweraverageduration = moving average window to average power over
must have started for this to kick in - if left out will just start startabovepower =
When to finish - if it falls below this amount finishbelowpower =
used in conjunction with finishbelowpower - used in conjusnction with power thresholds i.e. power below finishbelowpower before this number of mS has passed minduration = < int > mSeconds
Must be above minduration and sets a limit on the size of recording maxduration = < int > mSeconds
ch.record( {
"file": "testfile.wav"
} )
Or a more complex setup where speech is required to pass over to a processor (like speech recognition).
ch.record( {
"file": "testfile.wav",
"startabovepower": 250,
"finishbelowpower": 200,
"minduration": 2000,
"maxduration": 15000,
"poweraverageduration": 1
} )
Example with using drachtio. See separate instructions for starting an RTP server.
const Srf = require( "drachtio-srf" )
const parseuri = require( "drachtio-srf" ).parseUri
const config = require( "config" )
const projectrtp = require( "babble-projectrtp" )
const srf = new Srf()
srf.connect( config.drachtio )
const rtp = new projectrtp()
srf.invite( ( req, res ) => {
res.send( 180 )
let parsedaor = parseuri( req.msg.uri )
let remote = rtp.sdpgen( req.msg.body )
// Grab a channel
rtp.channel( remote )
.then( ch => {
let local = rtp.sdpgen()
.include( "pcmu pcma" )
.from( remote )
.setchannel( ch )
const dlg = srf.createUAS( req, res, {
localSdp: local.toString()
} )
.then( ( dlg ) => {
switch( parsedaor.user ) {
case "3":
ch.play( { "loop": true, "files": [ { "wav": "uksounds.wav" } ] } )
break
default:
ch.echo()
}
dlg.on( "destroy", () => {
ch.destroy()
.then( () => { console.log( "Channel destroyed" ) } )
console.log( "Call ended" )
} )
} )
.catch( ( err ) => {
console.log( err )
} )
} )
} )
- More intelligent routing to pass calls off to multiple RTP servers for scalability. It only currently supports single server.
- Mix more than 2 channels (conference).
- Support video (pass through)
- Lots!