tamashii-client 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +24 -21
- data/lib/tamashii/client/base.rb +2 -1
- data/lib/tamashii/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be044e47ec7a244c52a655253dd614914f16d9c3
|
4
|
+
data.tar.gz: 572050ce905a7f055a1fe2db1551731a68962779
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efaecb8ab11fb8facf2d0b9b6468f937699f4f5b24a4b553ac81340bdc4ab3a6c50b36712943d8c6eb079738749fc872411f0b774d29b449cbb6ef2e88d46d55
|
7
|
+
data.tar.gz: 8d6c7c85d20a035fd825c1c3bdd1e05e342eba5e68d282b119b5b54836153a3988864ad1f2c55af5db073caeb11e299ce66752d5b67bb678062295c05823607f
|
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
tags: tamashii, readme
|
3
|
-
---
|
4
|
-
|
5
|
-
Tamashii Client [](https://badge.fury.io/rb/tamashii-client)
|
1
|
+
Tamashii Client [](https://badge.fury.io/rb/tamashii-client)
|
6
2
|
===
|
7
3
|
|
8
|
-
Tamashii Client is the client
|
4
|
+
Tamashii Client is the websocket client for the [Tamashii](https://github.com/tamashii-io/tamashii) project. It is event-driven and it provides high-level API for users to communicates with WebSocket server easily.
|
9
5
|
|
10
6
|
## Installation
|
11
7
|
|
12
|
-
Add the following code to your `Gemfile
|
8
|
+
Add the following code to your `Gemfile`:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'tamashii-client'
|
12
|
+
```
|
13
13
|
|
14
14
|
And then execute:
|
15
15
|
```ruby
|
@@ -42,19 +42,20 @@ Tamashii::Client.config do
|
|
42
42
|
# Note the current version client does not infer the port from 'use_ssl'
|
43
43
|
# So you must explictly specifiy the port to use
|
44
44
|
port 443
|
45
|
-
# the log file for internel connection log
|
45
|
+
# the log file for internel connection log
|
46
46
|
# default is STDOUT
|
47
47
|
log_file 'tamashii.log'
|
48
48
|
end
|
49
49
|
|
50
50
|
client = Tamashii::Client::Base.new
|
51
|
-
@server_opened = false
|
51
|
+
@server_opened = false
|
52
52
|
|
53
53
|
# callback for server opened
|
54
54
|
# called when the WebSocket connection is readt
|
55
|
-
client.on(:open) do
|
55
|
+
client.on(:open) do
|
56
56
|
@server_opened = true
|
57
57
|
end
|
58
|
+
|
58
59
|
# callback for receving messages
|
59
60
|
# The data received is represented in a byte array
|
60
61
|
# You may need to 'pack' it back to Ruby string
|
@@ -66,19 +67,19 @@ end
|
|
66
67
|
# sending loop
|
67
68
|
# We send a request to server every second and terminates after 10 seconds
|
68
69
|
# In the begining, the server is not opened so the sending may fail.
|
69
|
-
count = 0
|
70
|
+
count = 0
|
70
71
|
loop do
|
71
72
|
sleep 1
|
72
73
|
if @server_opened # can also use 'client.opened?'
|
73
74
|
client.transmit "Hello World! #{count}"
|
74
75
|
else
|
75
76
|
puts "Unable to send #{count}: server not opened"
|
76
|
-
end
|
77
|
+
end
|
77
78
|
count += 1
|
78
79
|
if count >= 10
|
79
80
|
client.close
|
80
81
|
break
|
81
|
-
end
|
82
|
+
end
|
82
83
|
end
|
83
84
|
```
|
84
85
|
|
@@ -127,13 +128,14 @@ end
|
|
127
128
|
|
128
129
|
### The events and callbacks
|
129
130
|
|
130
|
-
These are events in the Tamashii Client. You can use `on` method to register callbacks for them.
|
131
|
+
These are events in the Tamashii Client. You can use `on` method to register callbacks for them.
|
131
132
|
- `socket_opened`
|
132
|
-
- When the low-level io socket (`TCPSocket` or `OpenSSL::SSL::SSLSocket`) successfully connected to the server.
|
133
|
-
- Receving this event does not imply the server supports WebSocket.
|
133
|
+
- When the low-level io socket (`TCPSocket` or `OpenSSL::SSL::SSLSocket`) successfully connected to the server.
|
134
|
+
- Receving this event does not imply the server supports WebSocket. Client still cannot send messages at this moment
|
134
135
|
- `open`
|
135
136
|
- When the WebSocket handshake is finished and the connection is opened
|
136
|
-
- Client can start sending
|
137
|
+
- Client can start sending messages to server after receiving this event.
|
138
|
+
- Fired after `socket_opened`
|
137
139
|
- `message`
|
138
140
|
- When the client receives the WebSocket payload from server.
|
139
141
|
- The message payload will be pass as the argument of the callback.
|
@@ -142,17 +144,18 @@ These are events in the Tamashii Client. You can use `on` method to register cal
|
|
142
144
|
- This event is purely informational, you do not need to implement error recovery.
|
143
145
|
- The error object will be pass as the argument of the callback.
|
144
146
|
- `close`
|
145
|
-
- When the WebSocket is closed **normally**.
|
146
|
-
- Will **NOT** be fired when the connection is closed by low-level IO error such as connection reset.
|
147
|
+
- When the WebSocket is closed **normally**.
|
148
|
+
- Will **NOT** be fired when the connection is closed by low-level IO error such as connection reset.
|
149
|
+
- Fired before `socket_closed`
|
147
150
|
- `socket_closed`
|
148
|
-
- When the low-level socket is closed.
|
151
|
+
- When the low-level socket is closed.
|
149
152
|
- Will be fired no matter the WebSocket is closed normally or not.
|
150
153
|
|
151
154
|
|
152
155
|
|
153
156
|
### Cooperate with Tamashii Server
|
154
157
|
|
155
|
-
Above example using the [wss://echo.websocket.org](wss://echo.websocket.org) to test your client. You can also use the [Tamashii](https://github.com/tamashii-io/tamashii) server to test your client. Only thing to do is to change the `host` and `port` in the configuration into the one used by your Tamashii server.
|
158
|
+
Above example using the [wss://echo.websocket.org](wss://echo.websocket.org) to test your client. You can also use the [Tamashii](https://github.com/tamashii-io/tamashii) server to test your client. Only thing to do is to change the `host` and `port` in the configuration into the one used by your Tamashii server.
|
156
159
|
|
157
160
|
## Development
|
158
161
|
|
data/lib/tamashii/client/base.rb
CHANGED
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.1.2
|
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-09-
|
13
|
+
date: 2017-09-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: websocket-driver
|