GithubHelp home page GithubHelp logo

avoylenko / rtpengine-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from drachtio/rtpengine-client

0.0 1.0 0.0 349 KB

nodejs client for accessing rtpengine via ng protocol

License: MIT License

JavaScript 100.00%

rtpengine-client's Introduction

rtpengine-client Build Status NPM version Coverage Status

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

Usage

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

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

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

rtpengine-client's People

Contributors

davehorton avatar danjenkins avatar avoylenko avatar emilianop11 avatar jeremy-j-ackso avatar letspkt avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.