Skip to content

Commit

Permalink
Merge 1fdfbe4 into 8eb6a15
Browse files Browse the repository at this point in the history
  • Loading branch information
XVincentX committed Jul 10, 2018
2 parents 8eb6a15 + 1fdfbe4 commit 64e6609
Show file tree
Hide file tree
Showing 7 changed files with 1,821 additions and 330 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: node_js
node_js:
- "6"
- "5"
- "4"
- "8"
- "10"
os:
- linux
- osx
- windows
script: npm run coverage
# Send coverage data to Coveralls
after_script: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
after_script: cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
148 changes: 74 additions & 74 deletions lib/AmiConnection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Created by Alex Voronyansky <belirafon@gmail.com>
* Created by Alex Voronyansky <belirafon@gmail.com>
* Date: 26.04.2016
* Time: 13:47
*/
Expand All @@ -12,90 +12,90 @@ const AmiEventsStream = require('asterisk-ami-events-stream');
/**
* Ami Connection
*/
class AmiConnection extends EventEmitter{
class AmiConnection extends EventEmitter {

constructor(socket){
super();
constructor(socket) {
super();

Object.assign(this, {
_isConnected: true,
_socket: socket,
_amiDataStream: new AmiEventsStream(),
_lastWroteData: null
});
Object.assign(this, {
_isConnected: true,
_socket: socket,
_amiDataStream: new AmiEventsStream(),
_lastWroteData: null
});

this._socket
.on('error', error => this.emit('error', error))
.on('close', () => this.close());
this._socket
.on('error', error => this.emit('error', error))
.on('close', () => this.close());

this._socket.pipe(this._amiDataStream)
.on('amiEvent', event => this.emit('event', event))
.on('amiResponse', response => this.emit('response', response))
.on('data', chunk => this.emit('data', chunk))
.on('error', error => this.emit('error', error));
}
this._socket.pipe(this._amiDataStream)
.on('amiEvent', event => this.emit('event', event))
.on('amiResponse', response => this.emit('response', response))
.on('data', chunk => this.emit('data', chunk))
.on('error', error => this.emit('error', error));
}

/**
*
* @returns {AmiConnection}
*/
close(){
this._isConnected = false;
this.emit('close');
if(this._socket){
this._socket.unpipe(this._amiDataStream);
this._socket
.removeAllListeners('end')
.removeAllListeners('close')
.removeAllListeners('errorLog')
.destroy();
}
return this;
/**
*
* @returns {AmiConnection}
*/
close() {
this._isConnected = false;
this.emit('close');
if (this._socket) {
this._socket.unpipe(this._amiDataStream);
this._socket
.removeAllListeners('end')
.removeAllListeners('close')
.removeAllListeners('errorLog')
.destroy();
}
return this;
}

/**
*
* @param message
*/
write(message){
let messageStr = typeof message === 'string' ?
amiUtils.fromString(message) : amiUtils.fromObject(message);
/**
*
* @param message
*/
write(message) {
let messageStr = typeof message === 'string' ?
amiUtils.fromString(message) : amiUtils.fromObject(message);

this._lastWroteData = message;
return this._socket.write(messageStr);
}
this._lastWroteData = message;
return this._socket.write(messageStr);
}

/**
*
* @returns {boolean}
*/
get isConnected(){
return this._isConnected;
}
/**
*
* @returns {boolean}
*/
get isConnected() {
return this._isConnected;
}

/**
*
* @returns {null}
*/
get lastEvent(){
return this._amiDataStream ? this._amiDataStream.lastEvent : null;
}
/**
*
* @returns {null}
*/
get lastEvent() {
return this._amiDataStream ? this._amiDataStream.lastEvent : null;
}

/**
*
* @returns {null}
*/
get lastResponse(){
return this._amiDataStream ? this._amiDataStream.lastResponse : null;
}
/**
*
* @returns {null}
*/
get lastResponse() {
return this._amiDataStream ? this._amiDataStream.lastResponse : null;
}

/**
*
* @returns {*}
*/
get lastWroteData(){
return this._lastWroteData;
}
/**
*
* @returns {*}
*/
get lastWroteData() {
return this._lastWroteData;
}
}

module.exports = AmiConnection;
module.exports = AmiConnection;
14 changes: 7 additions & 7 deletions lib/errors/AmiAuthError.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/**
* Asterisk authorization errorLog
*/
class AmiAuthError extends Error{
class AmiAuthError extends Error {

constructor(message){
super(message);
this.message = message;
this.name = 'AmiAuthError';
}
constructor(message) {
super(message);
this.message = message;
this.name = 'AmiAuthError';
}
}

module.exports = AmiAuthError;
module.exports = AmiAuthError;
Loading

0 comments on commit 64e6609

Please sign in to comment.