Skip to content

Commit f69efcb

Browse files
authored
Merge pull request #9 from sipcapture/feature_backpressure
Feature backpressure
2 parents ff95e4b + 5f6ba47 commit f69efcb

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/connectionManager.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ const connectionManager = {
6666
close(socket, error) {
6767
if (error) {
6868
console.error('Connection closed with error:', error);
69+
connectionManager.establishConnection(connectionManager.mediator);
6970
} else {
7071
if (connectionManager.debug) console.log('Connection closed gracefully');
72+
connectionManager.establishConnection(connectionManager.mediator);
7173
}
7274
},
7375
drain(socket) {
74-
if (connectionManager.debug) console.log('Socket buffer drained');
76+
if (connectionManager.debug) console.log('!!! Socket buffer drained');
7577
},
7678
error(socket, error) {
7779
console.error('Socket error:', error);
@@ -82,14 +84,20 @@ const connectionManager = {
8284
}, // connection failed
8385
end(socket) {
8486
if (connectionManager.debug) console.log('Connection ended by server');
87+
connectionManager.establishConnection(connectionManager.mediator);
8588
}, // connection closed by server
8689
timeout(socket) {
8790
if (connectionManager.debug) console.log('Connection timed out');
91+
connectionManager.establishConnection(connectionManager.mediator);
8892
}, // connection timed out
8993
},
9094
});
9195
connectionManager.sendData = (data) => {
92-
connectionManager.socket.write(data);
96+
let success = connectionManager.socket.write(data);
97+
if (connectionManager.debug) console.log(`Data sent over TCP: ${success}`);
98+
if (!success) {
99+
console.log('TCP socket buffer full, waiting for drain event');
100+
}
93101
};
94102
if (connectionManager.debug) console.log(`Ready to send data over TCP.`);
95103
return true;

src/hepModule.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ const hepModule = {
100100

101101
return hepJs.encapsulate(inviteRaw.join(''), rcinfo)
102102
},
103-
/* TODO: Add 403, Add RTCP, Check bad calls, reduce CPS to 50, increase duration to 240 */
104103
/**
105104
* Generate a 407 Proxy Authentication Required
106105
* @param {string} seq

src/sessionModule.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const sessionModule = {
138138
sessionModule.sessions.push(session);
139139
},
140140
advanceSessions: () => {
141-
console.log("Current Sessions in Progress:", sessionModule.sessions.length);
141+
if (sessionModule.debug) console.log("Current Sessions in Progress:", sessionModule.sessions.length);
142142
if (sessionModule.sessions.length === 0) {
143143
sessionModule.mediator.send({type: "noSessions"});
144144
} else if (sessionModule.sessions.length > 0) {
@@ -150,7 +150,7 @@ const sessionModule = {
150150
session.mediaInfo.rtpstart = Date.now();
151151
session.mediaInfo.lastReport = Math.floor(Date.now() / 1000);
152152
}
153-
session.duration = session.duration + 200; // increment duration by 20 ms
153+
session.duration = session.duration + 200; // increment duration by 200 ms
154154
// console.log("checking: ", session.previous, Date.now(), session.previous - Date.now(), session.duration, session.targetDuration);
155155
/* Handle Media */
156156
if (session.duration >= session.targetDuration) {

0 commit comments

Comments
 (0)