Skip to content

.disconnect() should provide a callback #9

@chadxz

Description

@chadxz

when calling .disconnect(), you're performing a socket.end() but providing no callback for when the socket is completely closed. You could do this by listening to the 'close' event, i.e.

AsteriskAmi.prototype.disconnect = function(callback){
  this.reconnect = false;
  this.socket.on('close', function () {
    callback();
  });
  this.socket.end(this.generateSocketData({Action: 'Logoff'}));
}

You shouldn't need to remove the close listener on the socket because the socket should be destroyed when the connection is closed.

Sorry I'm lazy and didn't do a PR because this was just a tangential thought while reviewing someone's code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions