Class: Kinokero::Jingle
- Includes:
- Jabber
- Defined in:
- lib/kinokero/jingle.rb
Overview
#########################################################################
Constant Summary
Constants included from Jabber
Jabber::MECHANISM_XOAUTH2, Jabber::NS_GOOGLE_AUTH_PROTOCOL, Jabber::NS_GOOGLE_AUTH_SERVICE
Instance Attribute Summary collapse
-
#gcp_channel ⇒ Object
readonly
#########################################################################.
-
#gcp_control ⇒ Object
readonly
#########################################################################.
-
#is_connection ⇒ Object
readonly
#########################################################################.
-
#my_cloudprint ⇒ Object
readonly
#########################################################################.
Class Method Summary collapse
- .clear_verbose ⇒ Object
-
.set_verbose ⇒ Object
—————————————————————————–.
Instance Method Summary collapse
-
#begin_connection ⇒ Object
—————————————————————————–.
-
#gtalk_close_connection ⇒ Object
—————————————————————————–.
-
#gtalk_notification_callback(&block) ⇒ Object
setup callback for subscription, which then triggers kinokero <message from=“cloudprint.google.com” to=”JID”> <push:push channel=“cloudprint.google.com” xmlns:push=“google:push”> <push:recipient to=“JID”></push:recipient> <push:data>encoded printer id</push:data> </push:push> </message>.
-
#gtalk_start_connection(&block) ⇒ Object
—————————————————————————–.
-
#gtalk_start_subscription ⇒ Object
—————————————————————————–.
-
#initialize(my_cloudprint, gcp_control, verbose) ⇒ Jingle
constructor
—————————————————————————– —– jabber initialization here —————————————– —————————————————————————–.
Constructor Details
#initialize(my_cloudprint, gcp_control, verbose) ⇒ Jingle
—– jabber initialization here —————————————–
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kinokero/jingle.rb', line 20 def initialize( my_cloudprint, gcp_control, verbose ) @my_cloudprint = my_cloudprint # cloudprint object @gcp_control = gcp_control @gcp_channel = ::Kinokero.gcp_channel @client = nil @is_connection = false # true if connection established @in_callback = false # semaphore true during callback stanza Jabber::debug = verbose end |
Instance Attribute Details
#gcp_channel ⇒ Object (readonly)
#########################################################################
13 14 15 |
# File 'lib/kinokero/jingle.rb', line 13 def gcp_channel @gcp_channel end |
#gcp_control ⇒ Object (readonly)
#########################################################################
13 14 15 |
# File 'lib/kinokero/jingle.rb', line 13 def gcp_control @gcp_control end |
#is_connection ⇒ Object (readonly)
#########################################################################
13 14 15 |
# File 'lib/kinokero/jingle.rb', line 13 def is_connection @is_connection end |
#my_cloudprint ⇒ Object (readonly)
#########################################################################
13 14 15 |
# File 'lib/kinokero/jingle.rb', line 13 def my_cloudprint @my_cloudprint end |
Class Method Details
Instance Method Details
#begin_connection ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/kinokero/jingle.rb', line 66 def begin_connection() if @client.nil? @sender_jid = Jabber::JID.new( @gcp_control[ :gcp_xmpp_jid ] ) @client = Jabber::Client.new(@sender_jid) @client.jid.resource = @gcp_control[ :gcp_printer_name ] @conn = @client.connect(::Kinokero.xmpp_server) end end |
#gtalk_close_connection ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/kinokero/jingle.rb', line 144 def gtalk_close_connection() unless @client.nil? || @in_callback # cease responding to message callbacks @client.( nil ) # prep the Google Talk for GCP unsubscribe stanza iq_unsubscribe = Jabber::Iq.new( :set, @gcp_control[ :gcp_xmpp_jid ]) sub_el = iq_unsubscribe.add_element( 'unsubscribe', 'xmlns' => ::Kinokero.ns_google_push ) sub_el.add_element( 'item', 'channel' => @gcp_channel, 'from' => @gcp_channel ) # attempt to unsubscribe (currently GCP returns 501: feature-not-implemented error @client.send( iq_unsubscribe ) # now seal off the connection @client.close! @client = nil # and let it vanish away @is_connection = false end # if a client exists end |
#gtalk_notification_callback(&block) ⇒ Object
setup callback for subscription, which then triggers kinokero <message from=“cloudprint.google.com” to=”JID”>
<push:push channel="cloudprint.google.com" xmlns:push="google:push">
<push:recipient to="{Bare JID}"></push:recipient>
<push:data>{Base-64 encoded printer id}</push:data>
</push:push>
</message>
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/kinokero/jingle.rb', line 84 def gtalk_notification_callback( &block ) @client. do |m| @in_callback = true # shows we're within callback now if m.from == @gcp_channel # grab the "push:data" snippet from within the "push:push" snippet # from within the current stanza m # for better understanding this, see issue & comments at: # https://github.com/xmpp4r/xmpp4r/issues/29 encoded_printerid = m.first_element("push:push").first_element_text("push:data") if encoded_printerid.nil? # is it invalid? Jabber::debuglog("GCP CALLBACK printer_id nil ERROR ???????????????") else # decode it printerid = Base64::strict_decode64(encoded_printerid) if printerid.nil? # is that invalid? Jabber::debuglog("GCP CALLBACK decoded printer_id nil ERROR #{encoded_printerid} ???????????????") else Jabber::debuglog("GCP CALLBACK: printer_id: #{printerid}") # go into appliance and let it know we need the queue for this printer yield( printerid ) end # decoded printerid nil if..then..else end # printerid useless if..then..else end # if channel correct @in_callback = false # shows we're not within callback now end # callback block end |
#gtalk_start_connection(&block) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kinokero/jingle.rb', line 45 def gtalk_start_connection( &block ) begin begin_connection() # establishes client protocol gtalk_start_subscription() # starts subscription to receive jobs gtalk_notification_callback( &block ) # callback response to notifications Jabber::debuglog("**************** protocol ended normally ******************") rescue Jabber::debuglog("\e[1;31m**************** protocol yielded exception: #{ $! } ******************\e[0m") @is_connection = false end # block for catch exceptions end |
#gtalk_start_subscription ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/kinokero/jingle.rb', line 124 def gtalk_start_subscription() unless @client.nil? # prep the Google Talk for GCP subscribe stanza iq_subscribe = Jabber::Iq.new( :set, @gcp_control[ :gcp_xmpp_jid ]) sub_el = iq_subscribe.add_element( 'subscribe', 'xmlns' => ::Kinokero.ns_google_push ) sub_el.add_element( 'item', 'channel' => @gcp_channel, 'from' => @gcp_channel ) @client.auth( @my_cloudprint.gcp_form_jingle_auth_token ) @client.send( iq_subscribe ) @is_connection = true end # if a client exists end |