This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtpengine
executable file
·88 lines (77 loc) · 2.6 KB
/
rtpengine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env node
"use strict";
var Rtpengine = require("commander");
var Bluebird = require("bluebird");
var Client = require("../lib/Client");
var _ = require("lodash");
var pkg = require("../package.json");
Rtpengine
.version(pkg.version)
.option("-H, --host <ip address>", "host rtpengine is running on", _.identity)
.option("-P, --port <port>", "port rtpengine is listening on", parseInt)
.option("-T, --timeout <milliseconds>", "number of milliseconds to wait before retrying a request", parseInt)
.option("-R, --retries <count>", "number of times to retry a request", parseInt);
function createClient () {
return Client.create(_.pick(Rtpengine, "port", "host", "retries", "timeout"));
}
Rtpengine
.command("ping")
.description("ping an rtpengine instance")
.action(function () {
Bluebird.using(createClient(), function (client) {
return client
.ping()
.then(function (result) {
console.log(JSON.stringify(result, null, " "));
});
});
});
Rtpengine
.command("list")
.option("-l, --limit <limit>", "limit the number of calls to return", parseInt, 32)
.description("list calls")
.action(function (options) {
Bluebird.using(createClient(), function (client) {
return client
.list(_.pick(options, "limit"))
.get("calls")
.then(function (calls) {
console.log(JSON.stringify(calls, null, " "));
});
});
});
Rtpengine
.command("query <callId>")
.option("-f, --from-tag <from-tag>", "from tag associated with a call leg")
.option("-t, --to-tag <to-tag>", "to tag associated with a call leg")
.description("search for calls")
.action(function (callId, options) {
options = _.merge(options, { callId : callId });
Bluebird.using(createClient(), function (client) {
options = _.merge(options, { callId : callId });
return client
.query(_.pick(options, "callId", "fromTag", "toTag"))
.then(function (result) {
console.log(JSON.stringify(result, null, " "));
});
});
});
Rtpengine
.command("delete <callId> <fromTag>")
.option("-t, --to-tag <to-tag>", "to tag associated with a call leg")
.option("-f, --via-tag <via-tag>", "via tag associated with a call leg")
.description("delete a call")
.action(function (callId, fromTag, options) {
Bluebird.using(createClient(), function (client) {
options = _.merge(options, { callId : callId, fromTag : fromTag });
return client
.delete(_.pick(options, "callId", "fromTag", "toTag", "viaTag"))
.then(function (result) {
console.log(JSON.stringify(result, null, " "));
});
});
});
Rtpengine.parse(process.argv);
if (!process.argv.slice(2).length) {
Rtpengine.outputHelp();
}