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

asterisk-ami-ts

v0.1.0

Published

Typescript conversion of asterisk-ami library.

Downloads

3

Readme

ASTERISK-AMI-TS

Typescript conversion of asterisk-ami library.

Credit: I'm grateful to the original library asterisk-ami. This library is just near one to one mapping conversion to Typescript of asterisk-ami.

ESM

import { AsteriskAmi } from 'asterisk-ami-ts'
import type { Asterisk } from 'asterisk-ami-ts'

const options: Asterisk.Options = {
	host: 'hostname',
	username: 'username',
	password: 'secret',
}

const ami = new AsteriskAmi(options)
ami.on('ami_data', (data) => console.log('AMI DATA', data))
ami.connect(() => ami.send({ action: 'Ping' }))
ami.send({ action: 'Ping' })

CJS

const { AsteriskAmi } = require('asterisk-ami-ts')

/** @type {import('asterisk-ami-ts').Asterisk.Options} */
const options = {
	host: 'hostname',
	username: 'username',
	password: 'secret',
}

const ami = new AsteriskAmi(options)
ami.on('ami_data', (data) => console.log('AMI DATA', data))
ami.connect(() => ami.send({ action: 'Ping' }))
ami.send({ action: 'Ping' })

Events

NOTE: AMI events are typed.

(AMI Data) These give you AMI specific information

  • ami_login Called when logging into the ami, no data passed back
  • ami_data Called for each event we get back from the AMI, with an object being returned

(net socket events) Use these events to determine the status of the socket connection, as if the socket is disconnected, you would need to add your .on('close') events again, this was a bug in the previous version of asterisk-ami, use these new events instead which will always be called, even if the connection has died and been reconnected.

  • ami_socket_drain
  • ami_socket_error
  • ami_socket_timeout
  • ami_socket_end
  • ami_socket_close
  • ami_socket_unwritable
export namespace Asterisk {
	export type Event =
		| 'ami_login'
		| 'ami_data'
		| 'ami_socket_drain'
		| 'ami_socket_error'
		| 'ami_socket_timeout'
		| 'ami_socket_end'
		| 'ami_socket_close'
		| 'ami_socket_unwritable'
}

Methods

export declare class AsteriskAmi {
	constructor(options?: Asterisk.Options)
	debug(...logs: any): void
	on(event: Asterisk.Event, event_cb: (...payload: any[]) => void): void
	send<P>(payload: P, send_cb?: (error?: Error) => void): void
	disconnect(): void
	destroy(): void
	connect(connect_cb: () => void, data_cb: (data: Buffer) => void): void
}

Options

export namespace Asterisk {
	export interface Options {
		port?: number // Port number for Asterisk AMI, default: `5038`
		host: string // Host of Asterisk, default: `localhost`
		username: string // Username of Asterisk AMI user, default: `username`
		password: string // Password of Asterisk AMI user, default: `password`
		enable_debug?: boolean // Do you want debugging output to the screen, default: `false`
		reconnect?: boolean // Do you want the ami to reconnect if the connection is dropped, default: `false`
		reconnect_after?: number // How long to wait to reconnect, in milliseconds, default: `3000`
		events?: Asterisk.Event | boolean // Do we want to receive AMI events, default: `true`
		ami_encoding?: BufferEncoding // Socket encoding method, default: `ascii`
	}
}

License

asterisk-ami-ts is licensed under the MIT license.