# rtpengine-client

> node client for rtpengine daemon

Latest version **0.4.12** (published 2023-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install rtpengine-client
pnpm add rtpengine-client
yarn add rtpengine-client
bun add rtpengine-client
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.12 |
| Published | 2023-07-06 |
| First published | 2017-08-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/rtpengine-client) |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 42.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Dave Horton |
| Maintainers | beachdog |
| Keywords | rtpengine |

## Links

- npm: https://www.npmjs.com/package/rtpengine-client
- Repository: https://github.com/davehorton/rtpengine-client
- Homepage: https://github.com/davehorton/rtpengine-client#readme
- Issues: https://github.com/davehorton/rtpengine-client/issues
- npm.io page: https://npm.io/package/rtpengine-client

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^7.4.4
- [bencode](https://npm.io/package/bencode.md) ^2.0.3
- [uuid-random](https://npm.io/package/uuid-random.md) ^1.3.2

## Recent versions

- 0.4.12 (latest) — 2023-07-06
- 0.4.11 — 2022-12-28
- 0.4.10 — 2022-12-20
- 0.3.9 — 2022-10-22
- 0.3.8 — 2022-10-22
- 0.3.7 — 2022-09-27
- 0.3.6 — 2022-09-22
- 0.3.5 — 2022-09-22
- 0.3.4 — 2022-08-25
- 0.3.3 — 2022-08-02
- 0.3.2 — 2022-01-21
- 0.3.1 — 2022-01-21
- 0.3.0 — 2022-01-11
- 0.2.1 — 2021-11-09
- 0.2.0 — 2021-03-12
- … 11 more at https://npm.io/package/rtpengine-client/versions

## README

# rtpengine-client [![Build Status](https://travis-ci.org/davehorton/rtpengine-client.svg?branch=master)](http://travis-ci.org/davehorton/rtpengine-client) [![NPM version](https://badge.fury.io/js/rtpengine-client.svg)](http://badge.fury.io/js/rtpengine-client) [![Coverage Status](https://coveralls.io/repos/github/davehorton/rtpengine-client/badge.svg?branch=master)](https://coveralls.io/github/davehorton/rtpengine-client?branch=master)

A Promises-based nodejs client for accessing rtpengine via ng protocol

## Usage

```js
const Client = require('rtpengine-client').Client;
const client = new Client();

client.ping(22222, '39.194.250.246')
  .then((res) => {
    console.log(`received ${JSON.stringify(res)}`); // {result: 'pong'}
  })
  .catch((err) => {
    console.log(`Error: ${err}`);
  });
```

## Constructing a client
```js
client = new Client();  // listen on any port and default address
// or..
client = new Client(9055);    // listen on a specific port
// or..
client = new Client(9055, '192.168.1.10'); // listen on a specific port and address
// or..
client = new Client({port: 9055, host: '192.168.1.10'}); // listen on a specific port and address
// or..
client = new Client({timeout: 1500}); // wait a max of 1500 ms for each command reply, throw error on timeout
// or..
client = new Client({rejectOnFailure: true});
// reject promise on any command if response from rtpengine has error
// default behavior is to resolve with any response from rtpengine, even errors
```

## Websocket support

```js
const client = new Client('ws://<IP>:8080');

client.on('listening', () => {
  client.statistics()
    .then((res) => {
      console.log('received data', res);
    })
    .catch((err) => {
      console.log(`Error: ${err}`);
    });
});
```

## Making requests
The ng request verbs (`ping`, `offer`, `answer`, `delete`, `query`, `start recording`, `stop recording`, `block DTMF`, `unblock DTMF`, `block media`, `unblock media`) are available as methods on the `client` object.  The sytax for each is the same:
+ the destination of the request comes first, either as `port, host` or `{port, host}`
+ following that, if any options are required for the request, those come next in an object.

The function call returns a promise that is resolved when the response is received.

Function names are as follows:

| ng verb          | function name    |
|------------------|------------------|
|ping              | ping             |
|offer             | offer            |
|answer            | answer           |
|delete            | delete           |
|query             | query            |
|start recording   | startRecording   |
|stop recording    | stopRecording    |
|block DTMF        | blockDTMF        |
|unblock DTMF      | unblockDTMF      |
|play DTMF         | playDTMF         |
|block media       | blockMedia       |
|unblock media     | unblockMedia     |
|silence media     | silenceMedia     |
|unsilence media   | unsilenceMedia   |
|start forwarding  | startForwarding  |
|stop forwarding   | stopForwarding   |
|play media        | playMedia        |
|stop media        | stopMedia        |
|statistics        | statistics       |
|publish           | publish          |
|subscribe request | subscribeRequest |
|subscribe answer  | subscribeAnswer  |
|unsubscribe       | unsubscribe      |

For instance
```
client.offer(22222, '35.195.250.243', {
  'sdp': ..
  'call-id': ..
  'from-tag': ..
})
  .then((res) => {
    console.log(res); // { "result": "ok", "sdp": "v=0\r\no=..." }
  })
  .catch((err) => {

  });

// or..
client.offer({port: 22222, host: '35.195.250.243}, {
  'sdp': ..
  'call-id': ..
  'from-tag': ..
}) // ...etc
```

---
_Source: https://npm.io/package/rtpengine-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
