tamashii-client 0.1.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tamashii/client.rb +5 -3
- data/lib/tamashii/client/base.rb +10 -11
- data/lib/tamashii/client/config.rb +11 -10
- data/lib/tamashii/client/version.rb +1 -1
- data/tamashii-client.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aeeb6f1b88c8a5350d6be7c42bb6779f87b59e10
|
4
|
+
data.tar.gz: 10f952b754919daf6bba2f1a482d884e34f385e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f34b7b826b5ef70eab5235bbdd8ebf8d798f0b58773792008dd47133289500590d82ec34969c531eb74016242a953084600a6e73ed77df8fd91801655919c1ee
|
7
|
+
data.tar.gz: 33f6f01f482850cd410e1e27d9130f6367021148d8d154b6f45b8a7ff9628d244b9d5316d927d21fff84d44e7f00634c0f829c301ef87c9f9e7bc45a101bdf68
|
data/lib/tamashii/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require "tamashii/config"
|
1
2
|
require "tamashii/common"
|
2
3
|
require "tamashii/client/version"
|
3
4
|
require "tamashii/client/config"
|
@@ -7,12 +8,13 @@ module Tamashii
|
|
7
8
|
autoload :Base, "tamashii/client/base"
|
8
9
|
|
9
10
|
def self.config(&block)
|
10
|
-
|
11
|
-
|
11
|
+
@config ||= Config.new
|
12
|
+
return instance_exec(@config, &block) if block_given?
|
13
|
+
@config
|
12
14
|
end
|
13
15
|
|
14
16
|
def self.logger
|
15
|
-
@logger ||= Tamashii::Logger.new(
|
17
|
+
@logger ||= Tamashii::Logger.new(self.config.log_file).tap do |logger|
|
16
18
|
logger.progname = "WebSocket Client"
|
17
19
|
end
|
18
20
|
end
|
data/lib/tamashii/client/base.rb
CHANGED
@@ -6,7 +6,6 @@ require 'timeout'
|
|
6
6
|
require 'websocket/driver'
|
7
7
|
|
8
8
|
|
9
|
-
require "tamashii/common"
|
10
9
|
require "tamashii/client/config"
|
11
10
|
|
12
11
|
module Tamashii
|
@@ -20,8 +19,8 @@ module Tamashii
|
|
20
19
|
end
|
21
20
|
|
22
21
|
def initialize
|
23
|
-
entry_point_with_slash =
|
24
|
-
@url = "#{
|
22
|
+
entry_point_with_slash = Tamashii::Client.config.entry_point.start_with?("/") ? Tamashii::Client.config.entry_point : "/#{Tamashii::Client.config.entry_point}"
|
23
|
+
@url = "#{Tamashii::Client.config.use_ssl ? "wss" : "ws"}://#{Tamashii::Client.config.host}:#{Tamashii::Client.config.port}#{entry_point_with_slash}"
|
25
24
|
|
26
25
|
@callbacks = {}
|
27
26
|
|
@@ -118,8 +117,8 @@ module Tamashii
|
|
118
117
|
end
|
119
118
|
|
120
119
|
def wait_for_worker_thread
|
121
|
-
if !@thread.join(
|
122
|
-
logger.error "Unable to stop worker thread in #{
|
120
|
+
if !@thread.join(Tamashii::Client.config.closing_timeout)
|
121
|
+
logger.error "Unable to stop worker thread in #{Tamashii::Client.config.closing_timeout} second! Force kill the worker thread"
|
123
122
|
kill_worker_thread
|
124
123
|
end
|
125
124
|
end
|
@@ -131,15 +130,15 @@ module Tamashii
|
|
131
130
|
end
|
132
131
|
|
133
132
|
def open_socket
|
134
|
-
Timeout::timeout(
|
135
|
-
if
|
136
|
-
OpenSSL::SSL::SSLSocket.new(TCPSocket.new(
|
133
|
+
Timeout::timeout(Tamashii::Client.config.opening_timeout) do
|
134
|
+
if Tamashii::Client.config.use_ssl
|
135
|
+
OpenSSL::SSL::SSLSocket.new(TCPSocket.new(Tamashii::Client.config.host, Tamashii::Client.config.port)).connect
|
137
136
|
else
|
138
|
-
TCPSocket.new(
|
137
|
+
TCPSocket.new(Tamashii::Client.config.host, Tamashii::Client.config.port)
|
139
138
|
end
|
140
139
|
end
|
141
140
|
rescue Timeout::Error => e
|
142
|
-
logger.error "Opening timeout after #{
|
141
|
+
logger.error "Opening timeout after #{Tamashii::Client.config.opening_timeout} seconds"
|
143
142
|
nil
|
144
143
|
rescue => e
|
145
144
|
nil
|
@@ -163,7 +162,7 @@ module Tamashii
|
|
163
162
|
|
164
163
|
def open_socket_async
|
165
164
|
if !closing? && !stopped?
|
166
|
-
@open_socket_task = Concurrent::ScheduledTask.execute(
|
165
|
+
@open_socket_task = Concurrent::ScheduledTask.execute(Tamashii::Client.config.opening_retry_interval, &method(:open_socket_runner))
|
167
166
|
else
|
168
167
|
logger.warn "Client is closing, no longer need to create socket"
|
169
168
|
end
|
@@ -1,16 +1,17 @@
|
|
1
|
-
require 'tamashii/common'
|
2
1
|
module Tamashii
|
3
2
|
module Client
|
4
|
-
class Config
|
5
|
-
|
3
|
+
class Config
|
4
|
+
include Tamashii::Configurable
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
6
|
+
config :log_file, default: STDOUT
|
7
|
+
|
8
|
+
config :use_ssl, default: false
|
9
|
+
config :entry_point, default: ''
|
10
|
+
config :host, default: 'localhost'
|
11
|
+
config :port, default: 3000
|
12
|
+
config :opening_timeout, default: 10
|
13
|
+
config :opening_retry_interval, default: 1
|
14
|
+
config :closing_timeout, default: 10
|
14
15
|
|
15
16
|
def log_level(level = nil)
|
16
17
|
return Client.logger.level if level.nil?
|
data/tamashii-client.gemspec
CHANGED
@@ -32,7 +32,8 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_runtime_dependency "websocket-driver"
|
33
33
|
spec.add_runtime_dependency "nio4r"
|
34
34
|
spec.add_runtime_dependency "logger-colors"
|
35
|
-
spec.add_runtime_dependency "tamashii-
|
35
|
+
spec.add_runtime_dependency "tamashii-config"
|
36
|
+
spec.add_runtime_dependency "tamashii-common", ">= 0.2"
|
36
37
|
spec.add_runtime_dependency "concurrent-ruby"
|
37
38
|
|
38
39
|
spec.add_development_dependency "bundler", "~> 1.13"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tamashii-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 蒼時弦也
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: exe
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-11-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: websocket-driver
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
|
-
name: tamashii-
|
58
|
+
name: tamashii-config
|
59
59
|
requirement: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
@@ -68,6 +68,20 @@ dependencies:
|
|
68
68
|
- - ">="
|
69
69
|
- !ruby/object:Gem::Version
|
70
70
|
version: '0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: tamashii-common
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0.2'
|
78
|
+
type: :runtime
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0.2'
|
71
85
|
- !ruby/object:Gem::Dependency
|
72
86
|
name: concurrent-ruby
|
73
87
|
requirement: !ruby/object:Gem::Requirement
|
@@ -209,7 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
223
|
version: '0'
|
210
224
|
requirements: []
|
211
225
|
rubyforge_project:
|
212
|
-
rubygems_version: 2.
|
226
|
+
rubygems_version: 2.6.11
|
213
227
|
signing_key:
|
214
228
|
specification_version: 4
|
215
229
|
summary: The WebSocket client of Tamashii framework
|