This repository has been archived by the owner on Dec 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprinter.js
58 lines (49 loc) · 1.54 KB
/
printer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function() {
'use strict';
var ipp = require('ipp');
var Job = require('./job');
var utils = require('util');
var events = require('events');
utils.inherits(Printer, events.EventEmitter);
function Printer(address) {
var self = this;
self._api = ipp.Printer(address);
self._api.execute('Get-Printer-Attributes', null, function(err, res) {
if (err) {
self.emit('error', err);
return console.error(err);
}
self.attributes = res['printer-attributes-tag'];
self.emit('init', self.attributes['printer-state']);
});
}
Printer.prototype.createJob = function(file) {
var self = this;
if (file && !Buffer.isBuffer(file)) {
return console.error('createJob method needs takes no argument or a buffer.');
}
return new Job(self, file);
};
Printer.prototype.getJobs = function() {
var self = this;
self._api.execute('Get-Jobs', null, function(err, res) {
if (err) return console.error(err);
self.emit('printer:jobs', res['job-attributes-tag']);
});
};
Printer.prototype.pause = function() {
// TODO: test and clean
self._api.execute('Pause-Printer', null, function(err, res) {
if (err) return console.error(err);
self.emit('printer:paused', res);
});
};
Printer.prototype.resume = function() {
// TODO: test and clean
self._api.execute('Pause-Printer', null, function(err, res) {
if (err) return console.error(err);
self.emit('printer:paused', res);
});
};
module.exports = Printer;
}).call(this);