diff --git a/inc/xmppcomponent.rb b/inc/xmppcomponent.rb index 4a03156..a5cb6bd 100644 --- a/inc/xmppcomponent.rb +++ b/inc/xmppcomponent.rb @@ -75,6 +75,11 @@ class XMPPComponent @@transport.send(p) end Thread.stop() + rescue Interrupt + @logger.error 'Interrupted!' + @@transport.on_exception do |exception,| end + self.disconnect() + return -11 rescue Exception => e @logger.error 'Connection failed: %s' % e @db.close @@ -82,6 +87,13 @@ class XMPPComponent end end + # transport shutdown # + def disconnect() + @logger.info "Closing all connections..." + @sessions.each do |jid, session| @sessions[jid].disconnect() end + @@transport.close() + end + def survive(exception, stream, state) @logger.error "Stream error on :%s (%s)" % [state.to_s, exception.to_s] @logger.info "Trying to revive session..." diff --git a/zhabogram.rb b/zhabogram.rb index 40bd40f..d670b4e 100644 --- a/zhabogram.rb +++ b/zhabogram.rb @@ -9,9 +9,10 @@ require 'tdlib-ruby' require_relative 'inc/telegramclient' require_relative 'inc/xmppcomponent' -# Configuration file # +# configuration Config = YAML.load_file(File.dirname(__FILE__) + '/config.yml') +TelegramClient.configure(Config['telegram']) # configure tdlib -# Configure Telegram Client # -TelegramClient.configure(Config['telegram']) -XMPPComponent.new(Config['xmpp']).connect() +# run +Zhabogram = XMPPComponent.new(Config['xmpp']) +Zhabogram.connect()