humphd / next

What I'm doing next (name TBD)
MIT License
14 stars 5 forks source link

Allow mounting of local filesystem into the editor. #61

Open dsych opened 6 years ago

dsych commented 6 years ago

It would be very useful to be able to open local files in the online editor instead of the emulated ones. I believe this could be achieve through the following steps;

  1. Create an option on editor UI to switch to the local filesystem. Now, since js is sandboxed inside a browser, we will require user to suply string path to the folder to be opened.
  2. At this point, we will need to refresh the editor and switch references to the fs from Filer to our custom implementation here and here.
  3. As mentioned above, js is restricted from accessing local fs directly. Instead, we can have a WebSocket passing messages between local server and bramble. Similar to how thimble communicates with bramble.
  4. Our local server could be a simple exepress server. It would implement routes like /local_fs/readfile, /local_fs/readdir?recursive=true, similar things for writing to file and dir.
  5. Local exepress server would pass binary streams from and to WebSocket simulating connection to local fs.
humphd commented 6 years ago

This is very similar to what I was discussing previously with WebRTC data channels. The problem we'll have is that we can't shared data cross-origin (i.e., from gh-pages on github to localhost) with a web server and normal WS or HTTP. We might be able to establish a p2p connection with WebRTC (browser to node locally) and do it, though. I'm researching it with someone who has done this stuff before.

dsych commented 6 years ago

Gh-pages allows CORS by defalut see. As an alternative we can use JSONP.

dsych commented 6 years ago

One more thing, WebSockets does not require any kind of CORS headers, which means that we can use them freely to communicate with the local server. Here is a demo that does just that. Pull done the code, run node index.js and navigate to here. Check you console.