Skip to content

Commit

Permalink
Merge pull request #16 from mconf/handle-crlf
Browse files Browse the repository at this point in the history
[tcp] Handle double CRLF keep alive ping with pong and don't pass it to the parser
  • Loading branch information
prlanzarin authored Oct 10, 2019
2 parents 8071576 + 34d905c commit 29db9c7
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/TransportTCP.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,26 @@ Transport.prototype = {
let pendingSegments;
var messages = [], transaction;

// CRLFCRLF keep-alive request, send CRLF response
if (dataString == '\r\n\r\n' || dataString == '\n\r\n\r') {
this.logger.log('received TCP message with CRLFCRLF Keep Alive ping');
if (socket) {
return socket.write('\r\n', (e) => {
if (e) {
this.logger.warn(`unable to send keep-alive pong due to ${e}`);
}
if (this.ua.configuration.traceSip === true) {
this.logger.log('sent TCP Keep Alive pong');
}
});
} else {
this.logger.warn(`unable to send keep-alive pong because there is no socket`);
return;
}
}

// CRLF Keep Alive response from server. Ignore it.
if(dataString === '\r\n') {
if(dataString === '\r\n' || dataString == '\n\r') {
SIP.Timers.clearTimeout(this.keepAliveTimeout);
this.keepAliveTimeout = null;

Expand Down

0 comments on commit 29db9c7

Please sign in to comment.