UNPKG

@c_phillips/ipp-browser

Version:
55 lines 2.08 kB
import { extend } from "./ipputil"; import { serializer } from "./serializer"; import parse from "./parser"; class Printer { constructor(url, opts) { if (!(this instanceof Printer)) return new Printer(url, opts); opts = opts || {}; this.url = typeof url === "string" ? new URL(url) : url; this.version = opts.version || "2.0"; this.uri = opts.uri || "ipp://" + this.url.host + this.url.pathname; this.charset = opts.charset || "utf-8"; this.language = opts.language || "en-us"; } _message(operation, msg) { if (typeof operation === "undefined") operation = "Get-Printer-Attributes"; const base = { version: this.version, operation: operation, id: null, "operation-attributes-tag": { // these are required to be in this order "attributes-charset": this.charset, "attributes-natural-language": this.language, "printer-uri": this.uri, }, }; if (msg && msg["operation-attributes-tag"]["job-id"]) base["operation-attributes-tag"]["job-id"] = msg["operation-attributes-tag"]["job-id"]; else if (msg && msg["operation-attributes-tag"]["job-uri"]) base["operation-attributes-tag"]["job-uri"] = msg["operation-attributes-tag"]["job-uri"]; msg = extend(base, msg); if (msg["operation-attributes-tag"]["job-uri"]) delete msg["operation-attributes-tag"]["printer-uri"]; return msg; } getHeaders(headers) { let defaultHeaders = Object.assign(Object.assign({}, headers), { "Content-Type": "application/ipp" }); return defaultHeaders; } encodeMsg(operation, msg) { msg = this._message(operation, msg); const buf = serializer(msg); console.log(buf); return buf; } decodeMsg(buf) { return parse(buf); } } export default Printer; //# sourceMappingURL=printer.js.map