summaryrefslogtreecommitdiff
path: root/lib/awprint/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/awprint/index.js')
-rw-r--r--lib/awprint/index.js16
1 files changed, 13 insertions, 3 deletions
diff --git a/lib/awprint/index.js b/lib/awprint/index.js
index f500545..dec43fd 100644
--- a/lib/awprint/index.js
+++ b/lib/awprint/index.js
@@ -2,6 +2,7 @@ var bodyParser = require('body-parser')
var mongoose = require('mongoose')
var path = require('path')
mongoose.Promise = require('bluebird')
+var socketIO = require('socket.io')
function AWPrint (options) {
if (!(this instanceof AWPrint))
@@ -16,6 +17,7 @@ function AWPrint (options) {
var express = options.express
var router = express.Router()
var config = options.config
+ var io;
var db, Print
@@ -55,8 +57,8 @@ function AWPrint (options) {
date: Date.now()
}
res.sendStatus(200)
- new Print(data).save().then( (req) => {
- // send a websocket message
+ new Print(data).save().then( (job) => {
+ io && io.emit('job', job)
}).catch( (err) => {
// idk
})
@@ -64,7 +66,7 @@ function AWPrint (options) {
router.post('/print', bodyParser.json({}), function (req, res) {
res.sendStatus(200)
- Print.update({ url: req.body.url }, { printed: true, }).then( (req) => {
+ Print.update({ _id: req.body._id }, { printed: true, }).then( (req) => {
// send a websocket message?
}).catch( (err) => {
// idk
@@ -72,6 +74,14 @@ function AWPrint (options) {
})
this._router = router
+
+ // defer until the app is mounted
+ setImmediate(function(){
+ io = socketIO(options.app._server)
+ io.on('connection', function(socket){
+ // ...
+ })
+ })
}
AWPrint.prototype.middleware = function () {