webrtc: check datachannel label for ping/pong

This commit is contained in:
Kamil Trzciński 2025-07-04 18:06:04 +02:00
parent 520350ed67
commit 400e036ea2
2 changed files with 10 additions and 6 deletions

View File

@ -775,9 +775,11 @@
}); });
rtcPeerConnection.addEventListener('datachannel', function(e) { rtcPeerConnection.addEventListener('datachannel', function(e) {
const dc = e.channel; const dc = e.channel;
if (dc.label === 'keepalive') {
dc.addEventListener('message', function(e) { dc.addEventListener('message', function(e) {
dc.send('pong'); dc.send('pong');
}); });
}
}); });
rtcPeerConnection.addTransceiver('video', { direction: 'recvonly' }); rtcPeerConnection.addTransceiver('video', { direction: 'recvonly' });
//pc.addTransceiver('audio', {direction: 'recvonly'}); //pc.addTransceiver('audio', {direction: 'recvonly'});

View File

@ -77,9 +77,11 @@
pc.addEventListener('datachannel', function(e) { pc.addEventListener('datachannel', function(e) {
const dc = e.channel; const dc = e.channel;
if (dc.label === 'keepalive') {
dc.addEventListener('message', function(e) { dc.addEventListener('message', function(e) {
dc.send('pong'); dc.send('pong');
}); });
}
}); });
pc.remote_pc_id = request.id; pc.remote_pc_id = request.id;