File loading#17
Conversation
|
I'll take a look at this tomorrow. If you have a chance, would you mind re-syncing with the latest from cdglabs:master and uploading a new PR that only includes the file loading changes? It's a bit hard to review this way, and I'm not quite sure what the history will look like if I merge it like this...but I'm not an expert on GitHub PRs. |
|
Yeah I expected that Github would show this PR without the first three commits after the first merge. Apparently it doesn't do that. It's why I didn't make a PR for the file saving yet either. |
…leLoading Merge older changes into fileLoading
|
Oh alright, I've merged cdglabs/master onto fileLoading, and github automatically edited this PR. |
There was a problem hiding this comment.
I would be tempted to pass the type in as an argument -- that way it's clear at the call sites what kind of channel you are instantiating. It's a little confusing that the type of channel is determined not by the value of any of the arguments, but by the type of the argument. I think passing in the type as a string would make it a bit less confusing.
Another approach would be to create a ClientChannel and a ServerChannel constructor, and export only those constructors -- they could call the Channel constructor with the appropriate args. I'm fine with whatever you prefer though.
There was a problem hiding this comment.
Yeah, I think the way it currently is feels a little awkward, I don't like different constructors, because It's supposed to be the same api on the server and on the client.
Maybe something like this?
// client
var channel = new Channel({
type: Channel.server,
httpServer: server
});
// client
var channel = new Channel({
type: Channel.client,
port: 8080
});There was a problem hiding this comment.
I like it. I would just do { type: 'server', ... }, but it's your call.
This pull request should be merged after the "fixes" one.
In this pull request, I've added the ability to load files by passing a filename to the
node server.js filename.jscommand. This textfile will then be read, and sent to all open editors, that's not intended behavior, but that's how it works right now.What I've done is, I've made a very light abstraction over websockets, to make it easy to work with. The server-side one is server/channel.js and the client-side one is lib/channel.js.
server/FileLoader.js does the actual work on the server side. Whenever a new websocket connection gets established between a Moonchild instance and the server, if the server received a file via the commandline, then it opens that file and sends a "fileLoad" event using the channel to all clients.
The client then handles this "fileLoad" event in editor/loadFile.js. On "fileLoad", it simply sets the editor content to the received content.