makenai / robotnik

Drag and drop robotics educational library starring Johnny Five and Blockly (crowd goes wild)
52 stars 13 forks source link

Use sockets #8

Closed makenai closed 9 years ago

makenai commented 9 years ago

I think I tried to get sockets working before Makerland, but had some compatibility issues. To solve the problem as quickly as possible, I am sending messages between the client and server using a POST request on '/message'. Using sockets would be much more responsive and real time.

BrianGenisio commented 9 years ago

Agreed.

Especially if we go with an architecture where the server is a generic REST interface to J5, having events come back over sockets would be really keen. So let's say we had an accelerometer, we could register for "data" events:

POST /api/components/myaccelerometer/register/data

Internally, that could do a accel.on('data') handler which sends events via websockets to the browser, which would route the value to the appropriate blocks, as well as the component representation.

makenai commented 9 years ago

Ended up wrapping everything in electron and using IPC for the native version. The Chrome app version will use native execution. No need for web sockets here as the performance of IPC is quite good.

lynnaloo commented 9 years ago

Nice work @makenai! I haven't used Electron yet, so I'm going to look through at how you're using it.

makenai commented 9 years ago

Electron is pretty neat, and it allows you to package native windows, linux and mac executable. The biggest problem is with using native modules, since it uses Chromium v8 headers instead of the ones that ship with node.

There is a solution called electron-rebuild in npm that should do it automatically, but I haven't been able to get it to work. Instead I am requiring iojs v1.8 as a stop gap since it uses the same (or a close enough) version of v8.