Table of Contents

sendFile()

wrtc.sendFile() sends a file to a remote user. It attempts to use a data channel, but if no such can be found or created then over RTCgate/SIP signaling channel (websocket).

While file transfer over data channel is fairly quick, transfer over the RTCgate/SIP signaling channel (websocket) has very low bandwidth resulting in slow transfers. However the first time opening of a data channel can also take several seconds. Therefore unless a data channel already has been established sendFile() always sends small (less than 512 KB) files over RTCgate/SIP signaling channel.

Arguments

wrtc.sendFile(name, file, to, callobj)

Usage

Usually you supply arguments name, file and to to wrtc.sendFile(). If you are already in call with the person you want to send file to then you should also supply the call object of that call, so that sendFile() can attempt to send data much faster over data channel.

If you already are in a call with someone and that is the only ongoing call then you might leave out the to argument, resulting in file being transferred over the only RTCgate connection being available. This usage is however not recommended, you should always specify argument to.

Returns

Nothing.

Events

While the file is transmitted both sides will receive wrtc.onFileProgress() events at regular intervals (after every 6 KB of file has been transmitted).

When file transfer has completed receiving side will receive a wrtc.onFileReceived() event.

Examples

wrtc.sendFile("test.txt", window.btoa("HELLO"), "foo@bar.com");

If there already is an active call to foo@bar.com sendFile will add a data channel to that call and transfer the file that way.
If there is no current call to foo@bar.com (or your or foo@bar.com's webserver do not support data channels) sendFile will transfer the file using RTCgate/SIP signaling channel.

wrtc.sendFile("test.txt", window.btoa("HELLO"), "foo@bar.com", false);

Regardless of if there is a call to foo@bar.com or not file will always be transferred to foo@bar.com using RTCgate/SIP signaling channel. Avoid using this variant as it always results in slow file transfers.

wrtc.sendFile("test.txt", window.btoa("HELLO"), "foo@bar.com", callobj);

If both your browser and the browser at other end of callobj support data channels then add data channel to callobj and transfer file that way.
Otherwise transfer file to foo@bar.com using RTCgate/SIP signaling channel.

Also See

wrtc.stopFile()

wrtc.onFileProgress()

wrtc.onFileReceived()

wrtc.adv.sendLog()