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

useful-wind

v7.9.0

Published

A Promise-friendly, middleware-based framework for FreeSwitch call-handling

Downloads

48

Readme

A Promise-friendly, middleware-based framework for FreeSwitch call-handling

This framework is based on the esl Node.js Event Socket interface.

It consists of two objects:

  • the call-server provides a high-level interface to a middle-ware based route; look in the example folder for a complete, working example;
  • the router is the lower-level machinery; it works similarly to a Sinatra-based middleware router: each middleware is called in turn for a given call.

Router

Router = require 'useful-wind/router'

The router is initialized with a single parameter which is made available inside the middleware as this.cfg.

cfg = {my_db_name:'foo'}
router = new Router cfg

Each middleware is called once for each FreeSwitch call; middleware functions are called inside a Promise chain, using a specific context which is described in the next section.

router.session (object)

The router's session object is used to initialize the middlewares' session object.

router.session.db = new PouchDB cfg.db_name, cfg.db_options

router.use (function or object)

Appends the middleware to the list of middleware used by this router.

The argument might be a function, or an object with the fields include and (for debugging purposes) name.

debug

This module uses debug and the prefix useful-wind. Use DEBUG='useful-wind:*' or a similar pattern to debug the module (including errors in middleware code).

Middleware context

Middleware functions are called using the following context (which means the this object has the following properties). This context is also available as the first and only argument to middleware functions.

cfg

The object that was passed to the constructor for the router. A shortcut to this.router.cfg.

router

A reference to the router object.

session

Middleware should store call-related data inside the session object:

router.use ->
  @session.from_number = @source.replace /^+/, ''

router.use ->

    if @destination is '123'
      @action 'bridge', 'sofia/profile/[email protected]'
    else

      @session.db.get "number:#{destination}"
      .then (doc) ->

router.session is used to initialize session at the start of each call, before any middleware is processed.

data

The data provided by FreeSwitch over the Event Socket.

A shortcut for this.call.data.

source

The FreeSwitch Caller-ID-Number.

Your application may modify source if you'd like, but the value is not sent back to FreeSwitch. Use the FreeSwitch set or export commands to do that.

destination

The FreeSwitch Destination-Number.

Your application may modify destination if you'd like, but the value is not sent back to FreeSwitch. Use the FreeSwitch set or export commands to do that.

req.variable (function)

Return a reference to a (read-only) FreeSwitch variable:

router.use ->
  if @req.variable('direction')
    console.log 'direction is present'

req.header (function)

Return a reference to the incoming SIP header:

router.use ->
  if @req.header('p-charge-info')
    console.log 'P-Charge-Info is present'

action (function)

A shortcut for call.command. Send a command to FreeSwitch.

router.use ->
  @action 'set', 't38_passthru=true'
  .then ->
    @action 'bridge', 'sofia/profile/[email protected]'