In order to help simplify the code, all of the logic for manipulating file data is done inside the FileManager . Each connection with people listed on the screen has its own FileManager which deals with setting up a local file for sending over the wire, or piecing together file data sent from a remote partner.



The reason we need all of this code to break up the file into chunks and control how much data is sent at a time is because the underlying RTCDataChannel has a limit on the size of individual messages. The DataChannel is also not entirely reliable yet, so some file chunks might get lost when trying to send them, in which case we have to resend them. That's why we're following a request/response model for file chunks: the receiver knows how many chunks are needed to build the file, then requests groups of chunks at a time from the file owner.



Once the receiver actually has all of the file chunks, their FileManager just sticks them into a Blob and uses an objectURL to download the file from the browser.



Please browse through the code as well if you need more information about how file data is handled and how the request/response system works.