-
Notifications
You must be signed in to change notification settings - Fork 284
Description
Brackets recently started to evolve its LiveDevelopment feature to work in multiple browsers. The new architecture allows the editor to talk to a browser over a transport layer (currently WebSocket based) and communicate bi-directionally between the preview and editor document(s).
Our goal with Mozilla's editor for Thimble is to leverage this new architecture in order to create an in-browser editor with an in-browser livedev preview which substitute an iframe-based browser, a postMessage-based transport layer, and a nohost-based Blob URL Object server.
Accomplishing this will involve a bunch of things. I've started to make a list below, and I'm CC'ing @busykai for additional thoughts. This list is incomplete, but should get us started.
- LiveDev needs to default to multi browser (i.e., the
livedev.multibrowserpref should be true):
https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/main.js#L77-L80
We can probably use PreferencesManager.set() in an extension to flip this to true at startup. We just need to make sure it happens early enough (i.e., before AppInit.appReady) so as to not miss the multibrowser init here:
https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/main.js#L303-L314
- Launch/open a browser to display the preview need to be altered:
https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/LiveDevMultiBrowser.js#L517-L527
We need to change that to not use Node, but to start the iframe-based browser. Maybe we should override the launcher, or maybe we should implement the various “open browser” bits of the appshell:
https://github.com/humphd/brackets/blob/bramble/src/thirdparty/browser-appshell.js#L74-L79
- We need to create a LiveDevServer that implements enough of the LiveDevelopment/Servers/BaseServer base class. The FileServer is an example:
https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/Servers/FileServer.js
We can do this in an extension. We then need to register this server with the LiveDevServerManager such that it has a high enough priority to always get used (e.g., 9001, which is higher than 0 or 99):
- We should be able to alter how URLs are created to our server, and instead create Blob URL Objects (i.e., override the pathToUrl method):
https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/Servers/BaseServer.js#L92-L112
One issue to ponder is that we'll need to do this async (i.e., read path from fs), and pathToUrl is sync. The URL gets used with the launcher here:
We can steal code from nohost to create the Blob URLs:
https://github.com/humphd/nohost/blob/master/src/handlers.js#L510-L530
- We need to switch the MultBrowser LiveDev from a web socket transport to postMessage. This will require changes to both the editor side and remote (i.e., preview) side:
- Editor side - https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/MultiBrowserImpl/transports/NodeSocketTransport.js
- Remote/Preview side - https://github.com/humphd/brackets/blob/bramble/src/LiveDevelopment/MultiBrowserImpl/transports/remote/NodeSocketTransportRemote.js