ws_lite 1.0.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: 0a4d467537dc76203fecc8772535bff50177558679bfdf486ebddd0377527cbe
4
- data.tar.gz: e07a6f57ca1fb0fb65b14e0f6be4afcb51d6f6e0c58c95c616bf8e150762e541
3
+ metadata.gz: e92d3ead4261b5f4c8f3ea9e9bf97c3f5656ee22661acd4263802bfad5926e73
4
+ data.tar.gz: 29fab93562e216ffc5ef86221dcba0befed7788ca434bc71268ccf288c1e7413
5
5
  SHA512:
6
- metadata.gz: cc3b14af80f5d887ef4fece93825388640e8966fc1e1c36f02a4a9694f87d3186b9e0525d4eee5fd7301762c0192d2f73fa3f6ca6e8ac76c5c1c0c9a25471411
7
- data.tar.gz: 26fe3e76666de59d5a671e2f26641409c752d9c90aced70e4b17b623502a748ef071cb71f49ffe1c4e7b6d8b260251d5834aecdade9518090a2ddf08e28f0dd5
6
+ metadata.gz: 6f132c4f4ea9ac91ff35b9868b98d884a19ab5d47407a6d38bcf4e72bbdf3347786aefe1b37082d0a818ea8580188b73e5dc522dbc154c1701851484796d1cd4
7
+ data.tar.gz: 10e6ce3c6cf7aed308ade1d5f946c9766234022b619c6ebab170977f15b8d704548dba555bfca763b30d7483b0fd099fce404e179db8d9bdcb1fa3a7f7691d34
@@ -14,7 +14,9 @@ jobs:
14
14
  strategy:
15
15
  matrix:
16
16
  ruby:
17
- - '3.4.3'
17
+ - '3.3'
18
+ - '3.4'
19
+ - '4.0'
18
20
 
19
21
  steps:
20
22
  - uses: actions/checkout@v4
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.4
2
+ TargetRubyVersion: 3.3
3
3
  NewCops: enable
4
4
  SuggestExtensions: false
5
5
  Exclude:
data/AGENTS.md ADDED
@@ -0,0 +1,48 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ ## Project Overview
6
+
7
+ ws_lite is a lightweight WebSocket client library for Ruby (successor to websocket-client-simple). It provides an event-driven API for connecting to WebSocket servers with support for secure connections (WSS) and custom SSL options. Requires Ruby >= 3.3.0.
8
+
9
+ ## Commands
10
+
11
+ ```bash
12
+ bundle install # Install dependencies
13
+ bundle exec rake # Run tests and linting (default task)
14
+ bundle exec rake test # Run tests only
15
+ bundle exec rake rubocop # Run linting only
16
+ ```
17
+
18
+ ## Architecture
19
+
20
+ The library uses an event-driven pattern built on the `event_emitter` gem:
21
+
22
+ - **Entry point**: `lib/ws_lite.rb` - Module-level `connect` method creates Client instances
23
+ - **Core implementation**: `lib/ws_lite/client.rb` - Contains all WebSocket logic
24
+
25
+ **Connection flow**:
26
+ 1. `WSLite.connect(url, options)` creates a new `WSLite::Client`
27
+ 2. Client parses URL and opens TCP socket
28
+ 3. For `wss://`, wraps socket with SSL (OpenSSL 3.x compatible)
29
+ 4. Performs WebSocket handshake
30
+ 5. Spawns reader thread that loops on `socket.getc`, emitting events:
31
+ - `:open` - Connection established
32
+ - `:message` - Frame received (data in `event.data`)
33
+ - `:close` - Connection closed
34
+ - `:error` - Error occurred
35
+
36
+ **Key methods**: `send(data, opt)`, `close()`, `open?`, `closed?`
37
+
38
+ ## Testing
39
+
40
+ Tests use Minitest with an EventMachine-based echo server (`test/echo_server.rb`). Run individual tests with:
41
+
42
+ ```bash
43
+ ruby -Ilib:test test/test_websocket_client_simple.rb
44
+ ```
45
+
46
+ ## Code Style
47
+
48
+ RuboCop configured for Ruby 3.3+ with 120-character line limit. The client.rb file has relaxed method length/complexity metrics due to inherent WebSocket protocol complexity.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1
4
+
5
+ * Support Ruby 3.3.x through 4.0.x
6
+
3
7
  ## 1.0.0
4
8
 
5
9
  * Update metadata
data/CLAUDE.md ADDED
@@ -0,0 +1,6 @@
1
+ # CLAUDE.md
2
+
3
+ This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
+
5
+ AGENTS.md is the canonical source of truth; this file exists only as a Claude Code convenience entrypoint.
6
+ For comprehensive architecture documentation and implementation details, see **[AGENTS.md](./AGENTS.md)**.
data/README.md CHANGED
@@ -1,18 +1,29 @@
1
- ws_lite
2
- =======
1
+ # ws_lite
2
+
3
3
  [![Gem Version](https://badge.fury.io/rb/ws_lite.svg)](https://rubygems.org/gems/ws_lite)
4
4
  [![Downloads](https://img.shields.io/gem/dt/ws_lite.svg)](https://rubygems.org/gems/ws_lite)
5
5
  [![CI](https://github.com/carter2099/ws_lite/actions/workflows/test.yml/badge.svg)](https://github.com/carter2099/ws_lite/actions)
6
6
 
7
7
  Successor to [websocket-client-simple](https://github.com/ruby-jp/websocket-client-simple) with OpenSSL 3.x fixes and improved connection reliability.
8
8
 
9
- Installation
10
- ------------
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'ws_lite'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
11
22
 
12
- gem install ws_lite
23
+ $ gem install ws_lite
24
+
25
+ ## Usage
13
26
 
14
- Usage
15
- -----
16
27
  ```ruby
17
28
  require 'ws_lite'
18
29
 
@@ -67,25 +78,15 @@ ws = WSLite.connect 'wss://example.com', ssl_context: ctx
67
78
 
68
79
  By default, `OP_IGNORE_UNEXPECTED_EOF` is enabled on OpenSSL 3.x to prevent `SSL_read: unexpected eof while reading` errors when servers close connections without a TLS `close_notify` alert.
69
80
 
81
+ ## Development
70
82
 
71
- Sample
72
- ------
73
- [websocket chat](https://github.com/carter2099/ws_lite/tree/master/sample)
74
-
83
+ $ bundle install
84
+ $ rake
75
85
 
76
- Test
77
- ----
86
+ ## Contributing
78
87
 
79
- % gem install bundler
80
- % bundle install
81
- % export WS_PORT=8888
82
- % rake test
88
+ Bug reports and pull requests are welcome on GitHub at https://github.com/carter2099/ws_lite.
83
89
 
90
+ ## License
84
91
 
85
- Contributing
86
- ------------
87
- 1. Fork it
88
- 2. Create your feature branch (`git checkout -b my-new-feature`)
89
- 3. Commit your changes (`git commit -am 'Add some feature'`)
90
- 4. Push to the branch (`git push origin my-new-feature`)
91
- 5. Create new Pull Request
92
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,3 +1,3 @@
1
1
  module WSLite
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
data/ws_lite.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = spec.description
13
13
  spec.homepage = "https://github.com/carter2099/ws_lite"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = '>= 3.4.0'
15
+ spec.required_ruby_version = '>= 3.3.0'
16
16
 
17
17
  if spec.respond_to?(:metadata)
18
18
  spec.metadata["homepage_uri"] = spec.homepage
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ws_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - carter2099
@@ -146,7 +146,9 @@ files:
146
146
  - ".github/workflows/test.yml"
147
147
  - ".gitignore"
148
148
  - ".rubocop.yml"
149
+ - AGENTS.md
149
150
  - CHANGELOG.md
151
+ - CLAUDE.md
150
152
  - Gemfile
151
153
  - LICENSE.txt
152
154
  - README.md
@@ -154,10 +156,6 @@ files:
154
156
  - lib/ws_lite.rb
155
157
  - lib/ws_lite/client.rb
156
158
  - lib/ws_lite/version.rb
157
- - sample/client.rb
158
- - sample/echo_server.rb
159
- - sample/webbrowser/index.html
160
- - sample/webbrowser/main.js
161
159
  - test/echo_server.rb
162
160
  - test/test_connect_block.rb
163
161
  - test/test_helper.rb
@@ -178,14 +176,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
178
176
  requirements:
179
177
  - - ">="
180
178
  - !ruby/object:Gem::Version
181
- version: 3.4.0
179
+ version: 3.3.0
182
180
  required_rubygems_version: !ruby/object:Gem::Requirement
183
181
  requirements:
184
182
  - - ">="
185
183
  - !ruby/object:Gem::Version
186
184
  version: '0'
187
185
  requirements: []
188
- rubygems_version: 3.6.7
186
+ rubygems_version: 3.6.9
189
187
  specification_version: 4
190
188
  summary: A lightweight and configurable ruby websocket client
191
189
  test_files: []
data/sample/client.rb DELETED
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
3
- require 'ws_lite'
4
-
5
- puts "ws_lite v#{WSLite::VERSION}"
6
-
7
- url = ARGV.shift || 'ws://localhost:8080'
8
-
9
- ws = WSLite.connect url
10
-
11
- ws.on :message do |msg|
12
- puts ">> #{msg.data}"
13
- end
14
-
15
- ws.on :open do
16
- puts "-- websocket open (#{ws.url})"
17
- end
18
-
19
- ws.on :close do |e|
20
- puts "-- websocket close (#{e.inspect})"
21
- exit 1
22
- end
23
-
24
- ws.on :error do |e|
25
- puts "-- error (#{e.inspect})"
26
- end
27
-
28
- loop do
29
- ws.send STDIN.gets.strip
30
- end
@@ -1,34 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'eventmachine'
3
- require 'websocket-eventmachine-server'
4
-
5
- PORT = (ARGV.shift || 8080).to_i
6
-
7
- EM::run do
8
- @channel = EM::Channel.new
9
-
10
- puts "start websocket server - port:#{PORT}"
11
-
12
- WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => PORT) do |ws|
13
- ws.onopen do
14
- sid = @channel.subscribe do |mes|
15
- ws.send mes
16
- end
17
- puts "<#{sid}> connect"
18
-
19
- @channel.push "hello new client <#{sid}>"
20
-
21
- ws.onmessage do |msg|
22
- puts "<#{sid}> #{msg}"
23
- @channel.push "<#{sid}> #{msg}"
24
- end
25
-
26
- ws.onclose do
27
- puts "<#{sid}> disconnected"
28
- @channel.unsubscribe sid
29
- @channel.push "<#{sid}> disconnected"
30
- end
31
- end
32
- end
33
-
34
- end
@@ -1,22 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <meta charset="UTF-8" content="text/html" http-equiv="Content-Type">
5
- <title>websocket chat</title>
6
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
7
- <script src="./main.js"></script>
8
- </head>
9
- <body>
10
- <h1>websocket chat</h1>
11
- <div>
12
- <input id="name" size="15" type="text" value="NAME">
13
- <input id="message" size="80" type="text" value="hello hello">
14
- <input id="btn_post" type="button" value="post">
15
- </div>
16
- <ul id="chat"></ul>
17
- <div id="footer">
18
- <hr>
19
- <a href="https://github.com/carter2099/ws_lite">https://github.com/carter2099/ws_lite</a>
20
- </div>
21
- </body>
22
- </html>
@@ -1,38 +0,0 @@
1
- var ws = new WebSocket("ws://localhost:8080");
2
-
3
- ws.onmessage = function(e){
4
- print(e.data);
5
- };
6
-
7
- ws.onopen = function(e){
8
- log("websocket open");
9
- console.log(e);
10
- };
11
-
12
- ws.onclose = function(e){
13
- log("websocket close");
14
- console.log(e);
15
- };
16
-
17
- $(function(){
18
- $("#btn_post").click(post);
19
- $("#message").keydown(function(e){
20
- if(e.keyCode == 13) post();
21
- });
22
- });
23
-
24
- var post = function(){
25
- var name = $("#name").val();
26
- var mes = $("#message").val();
27
- ws.send(name+" : "+mes);
28
- $("input#message").val("");
29
- };
30
-
31
- var log = function(msg){
32
- console.log(msg);
33
- $("#chat").prepend($("<li>").text("[log] "+msg));
34
- };
35
-
36
- var print = function(msg){
37
- $("#chat").prepend($("<li>").text(msg));
38
- };