0

BLUF: Is there a way to monitor for changes to a file within a shared directory on the client side using javascript and the FileAPI?

Background I've written a simple p2p file sharing program with node.js - clients select a folder of files to share - a server maintains a list of all files that are being shared and emits it to all connected clients - list of files contains the name of the file, the client that has the master copy, and all peers that have downloaded the file - a client can tell the server it wants a particular file. The server provides the peerid of the client that has the master copy and the client establishes a p2p connection to download the file - if a client disconnects and was the master for a file that another client has, that client is then promoted to master

I want to have each client monitor for changes to its shared files and tell the server if any files have changed. If that client has the master copy, the server should broadcast that the master has changed and needs to be redownloaded. If that client doesn't have the master copy, then it should be removed from the list of peers that have the same file as the master and added as a new file.

  • Looks like you want to use `setInterval(function(){ /* do AJAX calls to get file */}, 250);` Change the milliseconds as desired. – StackSlave Mar 26 '18 at 23:45
  • Could you elaborate on "AJAX calls to get file"? I'm not familiar with AJAX. – John Dugger Mar 27 '18 at 00:07
  • There's a lot of information about AJAX online. You'll want to create a function to handle an XMLHttpRequest or use jQuery. – StackSlave Mar 27 '18 at 00:37

0 Answers0