Files
Testing/videocall1/DataChannel/dev/FileReceiver.js
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

59 lines
1.5 KiB
JavaScript

function FileReceiver(root) {
var content = {};
var packets = {};
var numberOfPackets = {};
function receive(data) {
var uuid = data.uuid;
if (typeof data.packets !== 'undefined') {
numberOfPackets[uuid] = packets[uuid] = parseInt(data.packets);
}
if (root.onFileProgress) {
root.onFileProgress({
remaining: packets[uuid]--,
length: numberOfPackets[uuid],
received: numberOfPackets[uuid] - packets[uuid],
maxChunks: numberOfPackets[uuid],
uuid: uuid,
currentPosition: numberOfPackets[uuid] - packets[uuid]
}, uuid);
}
if (!content[uuid]) {
content[uuid] = [];
}
content[uuid].push(data.message);
if (data.last) {
var dataURL = content[uuid].join('');
FileConverter.DataURLToBlob(dataURL, data.fileType, function(blob) {
blob.uuid = uuid;
blob.name = data.name;
// blob.type = data.fileType;
blob.extra = data.extra || {};
blob.url = (window.URL || window.webkitURL).createObjectURL(blob);
if (root.autoSaveToDisk) {
FileSaver.SaveToDisk(blob.url, data.name);
}
if (root.onFileReceived) {
root.onFileReceived(blob);
}
delete content[uuid];
});
}
}
return {
receive: receive
};
}