Skip to content

Commit

Permalink
Merge pull request #8 from centosadmin/proxy
Browse files Browse the repository at this point in the history
Add proxy support
  • Loading branch information
vladislav-yashin authored May 4, 2018
2 parents 0d75b15 + 24d1e46 commit be3d17c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 0.9.3 / 2018-05-04

* Add proxy support

### 0.9.2 / 2018-05-04

* Fix some potential deadlocks
Expand Down
17 changes: 17 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env ruby

require 'bundler/setup'
require 'tdlib-ruby'

TD.configure do |config|
config.lib_path = File.join(File.expand_path("#{TD.root_path}/../"), 'td', 'build')

config.client.api_id = ENV['TD_API_ID']
config.client.api_hash = ENV['TD_API_HASH']
config.client.use_test_dc = true
end

TD::Api.set_log_verbosity_level(1)

require 'irb'
IRB.start(__FILE__)
6 changes: 5 additions & 1 deletion lib/tdlib/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ class TD::Client

def initialize(td_client = TD::Api.client_create,
update_manager = TD::UpdateManager.new(td_client),
proxy: { '@type' => 'proxyEmpty' },
**extra_config)
@td_client = td_client
@update_manager = update_manager
@config = TD.config.client.to_h.merge(extra_config)
@proxy = proxy
@ready_condition_mutex = Mutex.new
@ready_condition = ConditionVariable.new
authorize
Expand Down Expand Up @@ -98,9 +100,10 @@ def broadcast_and_receive(query, timeout: TIMEOUT)
result = nil
mutex = Mutex.new
handler = ->(update) do
next unless update['@extra'] == extra
return unless update['@extra'] == extra
mutex.synchronize do
result = update
@update_manager.remove_handler(handler)
condition.signal
end
end
Expand Down Expand Up @@ -174,6 +177,7 @@ def authorize
when 'authorizationStateWaitEncryptionKey'
broadcast(encryption_key_query)
else
broadcast('@type' => 'setProxy', 'proxy' => @proxy)
@update_manager.remove_handler(handler)
@ready_condition_mutex.synchronize do
@ready = true
Expand Down
2 changes: 1 addition & 1 deletion lib/tdlib/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module TD
# tdlib-ruby version
VERSION = "0.9.2"
VERSION = "0.9.3"
end
1 change: 0 additions & 1 deletion tdlib-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Gem::Specification.new do |gem|
gem.require_paths = ['lib']

gem.add_runtime_dependency 'dry-configurable', '~> 0.7'
gem.add_runtime_dependency 'celluloid', '~> 0.17'

gem.add_development_dependency 'bundler', '~> 1.10'
gem.add_development_dependency 'rake', '12.3.1'
Expand Down

0 comments on commit be3d17c

Please sign in to comment.