diff --git a/package.json b/package.json index c5793764..38ad5ab0 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "body-parser": "^1.17.1", "connect-multiparty": "^2.0.0", "express": "^4.15.2", - "nodemon": "^1.11.0" + "nodemon": "^1.11.0", + "socket.io": "^2.0.1" } } diff --git a/public/claim.html b/public/claim.html new file mode 100644 index 00000000..f7641fda --- /dev/null +++ b/public/claim.html @@ -0,0 +1,28 @@ + + + + + + + Spee.ch Claim + + +

spee.ch

+

spee.ch is a single-serving site that reads and publishes images to and from the LBRY blockchain.

+

Status:

+

your image is being retrieved

+ + + + \ No newline at end of file diff --git a/public/eagle.jpg b/public/eagle.jpg new file mode 100644 index 00000000..cb736738 Binary files /dev/null and b/public/eagle.jpg differ diff --git a/public/index.html b/public/index.html index d6561367..eb7ff418 100644 --- a/public/index.html +++ b/public/index.html @@ -101,6 +101,9 @@ previewFile(); //calls the function named previewFile() - + + \ No newline at end of file diff --git a/routes/html-routes.js b/routes/html-routes.js index 2f358a86..9df16a12 100644 --- a/routes/html-routes.js +++ b/routes/html-routes.js @@ -18,7 +18,7 @@ module.exports = function(app){ // receive the request console.log(" >> POST request on /publish"); //console.log(">> req.files:", req.files) - console.log(" >> req.body:", req.body) + //console.log(" >> req.body:", req.body) // build the data needed to publish the file var publishObject = { @@ -64,10 +64,9 @@ module.exports = function(app){ app.get("/:name", function(req, res){ var name = req.params.name; console.log(">> GET request on /" + name) - // publish a message to the cue - // queueApi.addNewTaskToQueue("return claim for " + req.params.name + " ...") // retrieve the claim - lbryApi.serveClaimBasedOnNameOnly(name, res); + //lbryApi.serveClaimBasedOnNameOnly(name, res); + res.status(200).sendFile(path.join(__dirname, '../public', 'claim.html')); }); // route for the home page app.get("/", function(req, res){ diff --git a/routes/sockets-routes.js b/routes/sockets-routes.js new file mode 100644 index 00000000..e66b7e96 --- /dev/null +++ b/routes/sockets-routes.js @@ -0,0 +1,27 @@ + +// routes to export +module.exports = function(app) { + var http = require("http").Server(app); + var io = require("socket.io")(http); + + io.on('connection', function(socket){ + console.log('a user connected'); + + // trying to serve an image file from the server + socket.on('image-request', function(data){ + // 1. retrieve the image from lbry via daemon + console.log("received image request for:", data) + // 2. emit updates as the image is being retrieved + + // 3. serve the image back once it is retrieved + socket.emit("image-send", "test string for: " + data); + }) + + // handle disconnect + socket.on('disconnect', function(){ + console.log('user disconnected'); + }); + }); + + return http; +} \ No newline at end of file diff --git a/server.js b/server.js index b812f4cb..5872b342 100644 --- a/server.js +++ b/server.js @@ -2,19 +2,29 @@ var express = require('express'); var bodyParser = require('body-parser'); var path = require('path'); + // set port var PORT = 3000; -// initialize express + +// initialize express app var app = express(); + // make express look in the public directory for assets (css/js/img) app.use(express.static(__dirname + '/public')); -// configure epress + +// configure express app app.use(bodyParser.json()); // for parsing application/json app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded -// require in routes + +// require express routes require("./routes/api-routes.js")(app); require("./routes/html-routes.js")(app); + +// include socket.io functionality +// this wraps the server in sockets, to intercept incoming sockets requests +var http = require("./routes/sockets-routes.js")(app); + // start server -app.listen(PORT, function() { +http.listen(PORT, function() { console.log("Listening on PORT " + PORT); });