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-registrar

v1.5.1

Published

A simple registrar for use with drachtio sip server

Downloads

42

Readme

A simple SIP Registrar to be used with the drachtio SIP middleware server. The server maintains all registered endpoints by domain. Each endpoint is polled using SIP OPTIONS.

Usage

const Srf = require( "drachtio-srf" )
const Registrar = require( "babble-drachtio-registrar" )
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}` )
} )



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 re-register 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": ( 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 ) )
  }
} )


r.on( "register", ( reg ) => {
  console.log( "register" )
  console.log( reg )
} )

r.on( "unregister", ( reg ) => {
  console.log( "unregister" )
  console.log( reg )
} )

An example config file to be used with this example (config/default.json)

{
  "drachtio": {
    "host": "127.0.0.1",
    "port": 9022,
    "secret": "cymru"
  },
  "directory": {
    "com": {
      "babblevoice": {
        "bling": {
          "1000": { "secret": "<yourpassword>", "display": "Kermit" },
          "1001": { "secret": "<yourpassword>", "display": "Piggy" }
        }
      }
    }
  }
}

Our registrar then makes available registered endpoints.

r.realms()
r.users( "bling.babblevoice.com" )
r.user( "bling.babblevoice.com", "1000" )
// or
r.user( "[email protected]" )

In this example, we create a control web server to expose registration information.

let handlers = { 'PUT': {}, 'POST': {}, 'DELETE': {}, 'GET': {} }

handlers.GET.reg = (  pathparts, req, res, body  ) =>
{
  res.writeHead( 200, { "Content-Type": "application/json" } )

  if( 1 == pathparts.length ) {
    res.write( JSON.stringify( r.realms() ) )
  }
  else if( 2 == pathparts.length ){
    res.write( JSON.stringify( r.users( pathparts[ 1 ] ) ) )
  }
  else if( 3 == pathparts.length ){
    res.write( JSON.stringify( r.user( pathparts[ 1 ], pathparts[ 2 ] ) ) )
  }

  res.end()
}

const httpserver = http.createServer( ( req, res ) =>
{
  let body = ""
  req.on( "data", ( chunk ) =>
  {
    body += chunk.toString()
  } )

  req.on( "end", () => {
    var urlparts = url.parse( req.url )
    /* Remove the leading '/' */
    var path = urlparts.path.substr( 1 )
    var pathparts = path.split( '/' )

    if( req.method in handlers && pathparts[ 0 ] in handlers[ req.method ] )
    {
      try {
        handlers[ req.method ][ pathparts[ 0 ] ]( pathparts, req, res, body )
      }
      catch( err ) {
        res.writeHead( 500, { "Content-Type": "application/json" } )
        res.write( `{ "error": "${err.message}" }` )
        res.end()
      }
    }
    else
    {
      console.log( "Unknown method " + req.method + ":" + url )
      res.writeHead( 404, { "Content-Length": "0" } )
      res.end()
    }
  } )
} )



httpserver.on( "clientError", ( err, socket ) => {
  if ( err.code === "ECONNRESET" || !socket.writable ) {
    return
  }

  socket.end( "HTTP/1.1 400 Bad Request\r\n\r\n" )
} )


httpserver.listen( 9000, "127.0.0.1" )