-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
endpoint.js
55 lines (49 loc) · 1.46 KB
/
endpoint.js
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
const test = require('blue-tape') ;
//const test = require('tape').test ;
const Srf = require('drachtio-srf') ;
const Mrf = require('..') ;
const config = require('config') ;
const clearRequire = require('clear-module');
const async = require('async');
const Endpoint = require('../lib/endpoint');
const EP_FILE = '/tmp/endpoint_record.wav';
const EP_FILE2 = '/tmp/endpoint_record2.wav';
// connect the 2 apps to their drachtio servers
function connect(agents) {
return new Promise((resolve, reject) => {
async.each(agents, (agent, callback) => {
agent.once('connect', (err, hostport) => {
callback(err) ;
}) ;
}, (err) => {
if (err) { return reject(err); }
resolve() ;
});
});
}
// disconnect the 2 apps
function disconnect(agents) {
agents.forEach((app) => {app.disconnect();}) ;
clearRequire('./../app');
}
test('MediaServer#createEndpoint create idle endpoint using callback', (t) => {
t.timeoutAfter(60000);
const srf = new Srf();
srf.connect(config.get('drachtio')) ;
const mrf = new Mrf(srf) ;
return connect([srf])
.then(() => {
return mrf.connect(config.get('asterisk'));
})
.then((mediaserver) => {
return mediaserver.createEndpoint((err, endpoint) => {
if (err) throw err;
else {
t.ok(endpoint instanceof Endpoint, 'created endpoint');
endpoint.destroy() ;
mediaserver.disconnect() ;
}
disconnect([srf]);
});
});
}) ;