Skip to content

Commit

Permalink
Add support for specifying printer server's IP
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusoterogomez committed Nov 9, 2017
1 parent cb53d87 commit 807e90e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ module.exports = function (printer) {
} else {
server = printer.server = http.createServer(onrequest)
server.on('error', onerror)
server.listen(printer.port, onlistening)
server.listen({
host: printer.host,
port: printer.port
}, onlistening)
}

// Enable destroy method in http server
serverDestroy(server)

// Enhance printer object
printer.destroy = destroy
printer.bonjour = bonjour

return printer

Expand Down Expand Up @@ -100,14 +104,14 @@ module.exports = function (printer) {
function onlistening () {
printer.port = server.address().port

if (!printer.uri) printer.uri = 'ipp://' + os.hostname() + ':' + printer.port + '/'
if (!printer.uri) printer.uri = 'ipp://' + printer.host + ':' + printer.port + '/'

debug('printer "%s" is listening on %s', printer.name, printer.uri)
printer.start()

if (printer._zeroconf) {
debug('advertising printer "%s" on network on port %s', printer.name, printer.port)
bonjour.publish({ type: 'ipp', port: printer.port, name: printer.name })
bonjour.publish({ type: 'ipp', ip: printer.host, port: printer.port, name: printer.name, host: printer.host })
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions lib/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var debug = require('debug')(require('../package').name)
var ipp = require('ipp-encoder')
var utils = require('./utils')
var bind = require('./bind')
var os = require('os')

var C = ipp.CONSTANTS

Expand All @@ -27,6 +28,7 @@ function Printer (opts) {
this.jobs = []
this.name = opts.name
this.port = opts.port
this.host = opts.host || os.hostname
this.uri = opts.uri
this.state = C.STOPPED
this.server = opts.server
Expand Down

0 comments on commit 807e90e

Please sign in to comment.