Skip to content

Commit 2414fd4

Browse files
author
cloudwebrtc
committed
Add keepalive for webapp.
1 parent e115cca commit 2414fd4

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

server/Server.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ export default class CallHandler {
271271
});
272272
}
273273
break;
274+
case 'keepalive':
275+
client_self.send(JSON.stringify({type:'keepalive', data:{}}));
276+
break;
274277
default:
275278
console.log("Unhandled message: " + message.type);
276279
}

src/Signaling.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class Signaling extends events.EventEmitter {
1616
this.url = url;
1717
this.name = name;
1818
this.local_stream;
19+
this.keepalive_cnt = 0;
1920

2021
RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.msRTCPeerConnection;
2122
RTCSessionDescription = window.RTCSessionDescription || window.mozRTCSessionDescription || window.webkitRTCSessionDescription || window.msRTCSessionDescription;
@@ -38,6 +39,7 @@ export default class Signaling extends events.EventEmitter {
3839
id: this.self_id,
3940
}
4041
this.send(message);
42+
this.wsKeepaliveTimeoutId = setInterval(this.keepAlive, 12000);
4143
};
4244

4345
this.socket.onmessage = (e) => {
@@ -71,6 +73,9 @@ export default class Signaling extends events.EventEmitter {
7173
case 'bye':
7274
this.onBye(parsedMessage);
7375
break;
76+
case 'keepalive':
77+
console.log('keepalive response!');
78+
break;
7479
default:
7580
console.error('Unrecognized message', parsedMessage);
7681
}
@@ -85,6 +90,11 @@ export default class Signaling extends events.EventEmitter {
8590
}
8691
}
8792

93+
keepAlive = () => {
94+
this.send({ type: 'keepalive', data: {} });
95+
console.log('Sent keepalive ' + ++this.keepalive_cnt + ' times!');
96+
}
97+
8898
getLocalStream = (type) => {
8999
return new Promise((pResolve, pReject) => {
90100
var constraints = { audio: true, video: (type === 'video') ? { width: 1280, height: 720 } : false };

0 commit comments

Comments
 (0)