devopvoid / webrtc-java

WebRTC for desktop platforms running Java
Apache License 2.0
248 stars 60 forks source link

Ununderstandible behaviour of data channel #112

Open stserakhau opened 1 year ago

stserakhau commented 1 year ago

Test scenario:

Chunk size 15kb. For 200 files (avg 5 parallel downloads)

  1. Open datachannel (line 1..5 below)
  2. Transmit 5Mb file (sending chunks via channel.send(RTCDataChannelBuffer))
  3. Close data channel (after receiving confirmation from receiver or by timeout (1 minute))

Result: after ~100 successfully downloaded files I see next behaviour

After executing line 1..5 channel change state immediately to CLOSING -> CLOSED. State of the peerConnection = 'connected'

1. RTCDataChannelInit init = new RTCDataChannelInit();
2. init.priority = RTCPriorityType.VERY_LOW;
3. init.ordered = true;
4. RTCDataChannel fileChannel = rtcClient.peerConnection.createDataChannel(channelName, init);
5. fileChannel.registerObserver(new FileDownloaderRTCDataChannelObserver(fileChannel, fileResourceId, downloadStream));
6. 
7. class FileDownloaderRTCDataChannelObserver implements RTCDataChannelObserver {
8. ...
9.         @Override
10.         public void onStateChange() {
11.             File fileToTransmit = downloadStream.getFile();
12.             RTCDataChannelState state = fileChannel.getState();
13.             switch (state) {
14.                 case OPEN -> {
15.                     log.info("File download channel opened: {}", fileChannel.getLabel());
16.                     .......
17.                 }
18.                 case CLOSED -> {
19.                     log.info("File download channel closed: {}", fileChannel.getLabel());
20.                     ...
21.                 }
22.             }
23.         }
24. ...
25. }

Expected behaviour: Channel should not closed after creation.

Additional context

  1. After reconnecting peer client (refresh page in browser) data channel beginning to work.
  2. Some strange on the Ethernet graphic in Task manager I see execution of the code below in debug mode
     RTCDataChannelBuffer channelBuffer = new RTCDataChannelBuffer(byteBuffer, true);
     channel.send(channelBuffer);

But I don't see the network traffic. states of peer connection = connected, channel = open (When file transmittion is active this line generates traffic 10-15 mbits)