Skip to content

Commit

Permalink
fixed bug with ActionID generation for keep-alive actions
Browse files Browse the repository at this point in the history
tests updated
added new tests for keep-alive
  • Loading branch information
BelirafoN authored and BelirafoN committed May 10, 2016
1 parent 7a96315 commit 759b17f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/AmiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class AmiClient extends EventEmitter{
_keepAliveBit(){
this._kaTimer = setTimeout(() => {
if(this._options.keepAlive && this._connection && this.isConnected){
this._kaActionId = this._genActionId('--auth_');
this._kaActionId = this._genActionId(this._specPrefix);
this._connection.write({
Action: 'Ping',
ActionID: this._kaActionId
Expand Down
45 changes: 44 additions & 1 deletion test/amiClientTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ describe('Ami Client internal functionality', function(){
Hangup: 1
};
client.option('eventFilter', eventNames);
console.log(typeof client.option('eventFilter'));
assert.ok(client.option('eventFilter') instanceof Set);
assert.deepEqual(
Array.from(client.option('eventFilter')),
Expand Down Expand Up @@ -619,5 +618,49 @@ describe('Ami Client internal functionality', function(){

});

describe('Keep-alive', function(){

beforeEach(done => {
client = new AmiClient({});
server = new AmiTestServer(serverOptions);
server.listen({port: socketOptions.port}).then(done);
});

it('keep-alive is disabled', done => {
client.connect(USERNAME, SECRET, {port: socketOptions.port}).then(() => {
let clientEventsStream = server.getAuthClients()[0]._eventStream,
timeout = setTimeout(() => {
clientEventsStream.removeAllListeners('amiAction');
done();
}, 2000);

clientEventsStream.on('amiAction', action => {
if(action.Action === 'Ping'){
clearTimeout(timeout);
}
});
});
});

it('keep-alive is enabled', done => {
client = new AmiClient({
keepAlive: true,
keepAliveDelay: 100
});
client.connect(USERNAME, SECRET, {port: socketOptions.port}).then(() => {
let clientEventsStream = server.getAuthClients()[0]._eventStream;
clientEventsStream.on('amiAction', action => {
console.log(action);
if(action.Action === 'Ping'){
assert.ok(action.ActionID.startsWith('--spec_'));
clientEventsStream.removeAllListeners('amiAction');
done();
}
});
});
});

});

});

0 comments on commit 759b17f

Please sign in to comment.