Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

2 file transfer receivers, only one getting data

I am trying tranfer some files using file transfer API.

 

This is my index.js:

function processAllFiles() {
    let fileName;
    while (fileName = inbox.nextFile()) {
        console.log(`/private/data/${fileName} is now available`);
    }
}

inbox.onnewfile = processAllFiles;

 

 This is my settings.js:

inbox.onnewfile = loadSettings;

 

And this is my weather.js

inbox.onnewfile = () => {
    processWeatherData(fs.readFileSync('weather.cbor', 'cbor'));
};

 

But for soe reason it only goes to the weather function instead of both settings and weather. Why? How do I fix this?

 

Thank you.

Best Answer
0 Votes
1 REPLY 1

When you assign a function to the event in that way you're essentially replacing the existing handler each time.

 

Use this instead, but really you only want 1 handler for new files anyway.

 

inbox.addEventListener('newfile', loadSettings);
inbox.addEventListener('newfile', processAllFiles);

 

Best Answer
0 Votes