lib/sapos/print/q_reader.rb in sapos-print-1.0.7 vs lib/sapos/print/q_reader.rb in sapos-print-1.0.8
- old
+ new
@@ -11,32 +11,38 @@
def self.run!
reader = QReader.new
callback = Pubnub::SubscribeCallback.new(
message: -> (envelope){
- msg = envelope.result[:data][:message]
- print_control = nil
- document_number = nil
+ begin
+
+ msg = envelope.result[:data][:message]
+ msgid = envelope.result.dig(:data, :publish_time_object, :timetoken)
+ print_control = nil
+ document_number = nil
+
+ puts msg.inspect if reader.config.verbose
+
+ if msg.is_a?(Hash)
+ print_control = msg['print_control']
+ document_number = msg['document_number']
+ msg = msg['document']
+ end
- if msg.is_a?(Hash)
- msg = msg['document']
- print_control = msg['print_control']
- document_number = msg['document_number']
- end
+ document = Base64.decode64(msg)
- document = Base64.decode64(msg)
-
- if reader.printer.print(document: document, print_control: print_control, document_number: document_number)
- puts "OK"
- else
- puts "Printer Error".red
+ if !reader.printer.print(document: document, print_control: print_control, document_number: document_number, id: msgid)
+ puts "Printer Error"
+ end
+ rescue => e
+ puts "Error: #{e.message}"
end
},
presence: ->(envelope){},
status: ->(envelope){}
)
reader.pubnub.add_listener(callback: callback)
- reader.pubnub.subscribe(channels: reader.config.q)
+ reader.pubnub.subscribe(channels: [reader.config.q])
ARGV.clear
while line = gets do
#Wait forever ;-)
end
end
\ No newline at end of file