I am using libdatachannel library and i want to send file content to answerer.
I have dataChannel but when i sending file content via datachannel, i got error "Message size exceeds limit". i don't know how to split into chunks my message.(setting maxMessageSize is not option because file size changes according to offerer and answerer is browser)
I tried simply;
void sendfile2Content(std::shared_ptr<rtc::DataChannel> dc, const std::map<std::wstring, std::wstring>& files)
{
nlohmann::json msg
{
{"Message_Type", "File"},
{"FileName_to_Contents", files}
};
dc->send(msg.dump());
}
When i call the function i got std::logic_error(Message size exceeds limit).
How to send message to peer when message size over the message size limit?
SCTP (the protocol used by WebRTC datachannels) limits the size of messages to 16kB, and while there exist protocol extensions to send larger messages, they have serious problems, such as not being interoperable between implementations and causing head-of-line blocking. Thus, you should structure your code to limit messages to 16kB.
In order to implement file transfer over datachannels, you need to manually split your data into 16kB chunks at the sender, and reassemble the chunks at the receiver. Since the datachannel API predates promises, you will also need to wait for the
onbufferedamountlowcallback in order to avoid overwhelming the socket buffer.There's an example in the WebRTC samples, and there's an implementation using promises in the Galene sources (disclaimer, I am the author).