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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 616b8acc7d50fcb48f9b8e3cd333fd664e41e9cb
4
- data.tar.gz: 0c4529a5ee7eee3844f6cad3d05052d01b656526
3
+ metadata.gz: be044e47ec7a244c52a655253dd614914f16d9c3
4
+ data.tar.gz: 572050ce905a7f055a1fe2db1551731a68962779
5
5
  SHA512:
6
- metadata.gz: 3e329f34d53186908f64c96143acc0ba3dcd7d657f8d85957a204bdc9c12b1cf8638a3b8611409f5fb99a16d845e22c2dbfdcaf3b0b4e8f0118bf2531700fc60
7
- data.tar.gz: 11f3285f16c6d6634603cc1b82b8ebd60ebd9ee61e3e71ce60c1e62be832eb06f7353086a9937944763e9187eb6ca7f926d5560c453393dbbc2a95f0a839a0a8
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 [![Gem Version](https://badge.fury.io/rb/tamashii-client.svg)](https://badge.fury.io/rb/tamashii-client)
1
+ Tamashii Client [![Gem Version](https://badge.fury.io/rb/tamashii-client.svg)](https://badge.fury.io/rb/tamashii-client)
6
2
  ===
7
3
 
8
- Tamashii Client is the client side of the WebSocket framework [Tamashii](https://github.com/tamashii-io/tamashii). It is event-driven and it provides high-level API for users to communicates with WebSocket server easily.
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 data to server after receiving this event.
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
 
@@ -256,7 +256,8 @@ module Tamashii
256
256
  else
257
257
  @driver.parse(incoming)
258
258
  end
259
- rescue
259
+ rescue => e
260
+ logger.error "Error when reading from server: #{e.message}"
260
261
  server_gone
261
262
  end
262
263
 
@@ -1,5 +1,5 @@
1
1
  module Tamashii
2
2
  module Client
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
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.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-08 00:00:00.000000000 Z
13
+ date: 2017-09-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: websocket-driver