Skip to content

Commit

Permalink
experimental sse-support
Browse files Browse the repository at this point in the history
  • Loading branch information
lindskogen committed May 15, 2015
1 parent d9c42b0 commit 13b8afb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,15 @@
"bootstrap": "^3.3.4",
"console-polyfill": "^0.2.0",
"es5-shim": "^4.1.0",
"express-sse": "^0.2.1",
"jquery": "^2.1.3",
"moment": "^2.10.2",
"pubsub-js": "^1.5.2",
"q": "^1.2.0",
"react": "^0.13.1",
"react-router": "^0.13.2",
"web3.js": "ethereum/ethereum.js#develop",
"ws": "^0.7.1",
"xhr": "^2.0.1"
},
"browserify": {
Expand Down
8 changes: 7 additions & 1 deletion server.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import express from 'express';
import SSE from 'express-sse';
import bodyParser from 'body-parser';
import dockerx from 'docker-transfer';
import moment from 'moment';

let app = express();
let sse = new SSE(['connected']);

// Serve static files
app.use(express.static(__dirname + '/build'));
Expand All @@ -24,12 +26,16 @@ app.post('/transfer', function(req, res) {
res.send(timestamp() + " TRANSFER: Init client transfer of " + imageHash + " to " + host + ":" + port + "\n");
});

app.get('/stream', sse.init);

app.post('/receive', function(req, res) {
let name = "lolubuntu";
let port = req.body.port;
sse.send(timestamp())
dockerx.server.receive(name, port).then(
res.send(timestamp() + " RECEIVE: Init server listening at " + port + "\n")
sse.send('Finished at ' + timestamp())
);
res.send(timestamp() + " RECEIVE: Init server listening at " + port + "\n");
});

function timestamp() {
Expand Down
4 changes: 4 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ let App = React.createClass({
// tell ui that docker is hosted
},
workerEnableXfer(agreement) {
let es = new EventSource('/stream');
es.onmessage = function(event) {
console.log(event);
};
$.post("/receive", {
port: DockerConfig.port
}, (data) => {
Expand Down

0 comments on commit 13b8afb

Please sign in to comment.