websocket-client-simple 0.2.5 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2e514163b26ef3c9a5b777947059c009d6b058ae
4
- data.tar.gz: 264e3ce953723f8e9e99c6a1bc6a54433f4a6c96
2
+ SHA256:
3
+ metadata.gz: 9419913b098ff41396cbc11f0d3c2495f9cccb03471c79800f929079b1355537
4
+ data.tar.gz: 24de10f74455a26bdd20921975f031df322f5c744c5d12b95a071e0f7be48cb8
5
5
  SHA512:
6
- metadata.gz: 852d3a16f5538e187e492410b37c4e46b1aa29eb14d25d0dc2257ce9a2d319d13428eb99fef3a860da647b27e22665a8e185efa21d351bdf03ce0021662670e1
7
- data.tar.gz: 2b889144abf61793096c056c0555395c1bf4d1bf23357c29afc1567d5c3fa401e6e0047d78a270e89fc8befc0fbe395868e4ffc281e4f5cb17865aca4e64c8f9
6
+ metadata.gz: 31b267d997fdfd90d93a6477984614d5a6235bea3400a2c4b22008e1303ae2e801be15c647f50a9b1149bd87564ec4311e378e58d80d6cc1933b558f19d95469
7
+ data.tar.gz: 6ea95642df78c178290c1451645aa61ad916b59d8b00767dfefe8e552245eae1b96903e458107506760b0cf3f17c1d1e935f16615c6039b40572767fdb8b7fa7
@@ -0,0 +1,23 @@
1
+ on:
2
+ push:
3
+ branches:
4
+ - "*"
5
+ pull_request:
6
+ branches:
7
+ - "*"
8
+ schedule:
9
+ - cron: "0 0 * * 6" # At 00:00 on Saturday
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-20.04
13
+ strategy:
14
+ matrix:
15
+ ruby: ["3.1", "3.0", "2.7", "2.6"]
16
+ name: Ruby ${{ matrix.ruby }}
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - uses: ruby/setup-ruby@v1
20
+ with:
21
+ ruby-version: ${{ matrix.ruby }}
22
+ bundler-cache: true
23
+ - run: bundle exec rake
data/.gitignore CHANGED
@@ -14,3 +14,5 @@ spec/reports
14
14
  test/tmp
15
15
  test/version_tmp
16
16
  tmp
17
+ Gemfile.lock
18
+ .ruby-version
data/History.txt CHANGED
@@ -1,3 +1,25 @@
1
+ === Not yet released
2
+
3
+ === 0.5.0 2021-12-31
4
+
5
+ * Change TLS context defaults to system's default. The previous defaults were ssl_version=SSLv23 and verify_mode=VERIFY_NONE, which are insecure nowadays. #5
6
+ * thank you for contributing @eagletmt
7
+ * Made the necessary changes to use SNI. #6
8
+ * thank you for contributing @fuyuton
9
+
10
+ === 0.4.0 2021-12-30
11
+
12
+ * Drop support of ruby 2.5 or older versions as explicit.
13
+
14
+ === 0.3.1 2021-12-30
15
+
16
+ * The development of this repository has moved to https://github.com/ruby-jp/websocket-client-simple
17
+
18
+ === 0.3.0 2016-02-20
19
+
20
+ * "connect" method runs a given block before connecting WebSocket #12
21
+ * thank you for suggestion @codekitchen
22
+
1
23
  === 0.2.5 2016-02-18
2
24
 
3
25
  * bugfixed sending when broken pipe #15
data/README.md CHANGED
@@ -1,12 +1,11 @@
1
1
  websocket-client-simple
2
2
  =======================
3
- Simple WebSocket Client for Ruby
3
+ Simple WebSocket Client for Ruby (original author: @shokai)
4
4
 
5
- - https://github.com/shokai/websocket-client-simple
5
+ - https://github.com/ruby-jp/websocket-client-simple
6
6
  - https://rubygems.org/gems/websocket-client-simple
7
7
 
8
- [![Build Status](https://travis-ci.org/shokai/websocket-client-simple.png?branch=master)](https://travis-ci.org/shokai/websocket-client-simple)
9
-
8
+ [![.github/workflows/test.yml](https://github.com/ruby-jp/websocket-client-simple/actions/workflows/test.yml/badge.svg)](https://github.com/ruby-jp/websocket-client-simple/actions/workflows/test.yml)
10
9
 
11
10
  Installation
12
11
  ------------
@@ -44,6 +43,20 @@ loop do
44
43
  end
45
44
  ```
46
45
 
46
+ `connect` runs a given block before connecting websocket
47
+
48
+ ```ruby
49
+ WebSocket::Client::Simple.connect 'ws://example.com:8888' do |ws|
50
+ ws.on :open do
51
+ puts "connect!"
52
+ end
53
+
54
+ ws.on :message do |msg|
55
+ puts msg.data
56
+ end
57
+ end
58
+ ```
59
+
47
60
 
48
61
  Sample
49
62
  ------
@@ -3,26 +3,31 @@ module WebSocket
3
3
  module Simple
4
4
 
5
5
  def self.connect(url, options={})
6
- ::WebSocket::Client::Simple::Client.new(url, options)
6
+ client = ::WebSocket::Client::Simple::Client.new
7
+ yield client if block_given?
8
+ client.connect url, options
9
+ return client
7
10
  end
8
11
 
9
12
  class Client
10
13
  include EventEmitter
11
14
  attr_reader :url, :handshake
12
15
 
13
- def initialize(url, options={})
16
+ def connect(url, options={})
17
+ return if @socket
14
18
  @url = url
15
19
  uri = URI.parse url
16
20
  @socket = TCPSocket.new(uri.host,
17
21
  uri.port || (uri.scheme == 'wss' ? 443 : 80))
18
22
  if ['https', 'wss'].include? uri.scheme
19
23
  ctx = OpenSSL::SSL::SSLContext.new
20
- ctx.ssl_version = options[:ssl_version] || 'SSLv23'
21
- ctx.verify_mode = options[:verify_mode] || OpenSSL::SSL::VERIFY_NONE #use VERIFY_PEER for verification
24
+ ctx.ssl_version = options[:ssl_version] if options[:ssl_version]
25
+ ctx.verify_mode = options[:verify_mode] if options[:verify_mode]
22
26
  cert_store = OpenSSL::X509::Store.new
23
27
  cert_store.set_default_paths
24
28
  ctx.cert_store = cert_store
25
29
  @socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ctx)
30
+ @socket.hostname = uri.host
26
31
  @socket.connect
27
32
  end
28
33
  @handshake = ::WebSocket::Handshake::Client.new :url => url, :headers => options[:headers]
@@ -1,7 +1,7 @@
1
1
  module WebSocket
2
2
  module Client
3
3
  module Simple
4
- VERSION = "0.2.5"
4
+ VERSION = "0.5.0"
5
5
  end
6
6
  end
7
7
  end
@@ -0,0 +1,26 @@
1
+ module EchoServer
2
+ def self.start
3
+ WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => self.port) do |ws|
4
+ @channel = EM::Channel.new
5
+ ws.onopen do
6
+ sid = @channel.subscribe do |mes|
7
+ ws.send mes # echo to client
8
+ end
9
+ ws.onmessage do |msg|
10
+ @channel.push msg
11
+ end
12
+ ws.onclose do
13
+ @channel.unsubscribe sid
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.port
20
+ (ENV['WS_PORT'] || 18080).to_i
21
+ end
22
+
23
+ def self.url
24
+ "ws://localhost:#{self.port}"
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestWebSocketClientSimple < MiniTest::Test
4
+
5
+ def test_onopen
6
+
7
+ EM::run{
8
+
9
+ EchoServer.start
10
+
11
+ res = nil
12
+
13
+ EM::add_timer 1 do
14
+ WebSocket::Client::Simple.connect EchoServer.url do |client|
15
+ client.on :open do
16
+ client.send "hello world"
17
+ end
18
+
19
+ client.on :message do |msg|
20
+ res = msg.to_s
21
+ end
22
+ end
23
+ end
24
+
25
+ EM::add_timer 2 do
26
+ assert_equal res, "hello world"
27
+ EM::stop_event_loop
28
+ end
29
+ }
30
+
31
+ end
32
+
33
+ end
data/test/test_helper.rb CHANGED
@@ -4,5 +4,6 @@ require 'minitest/autorun'
4
4
  require 'websocket-client-simple'
5
5
  require 'eventmachine'
6
6
  require 'websocket-eventmachine-server'
7
+ require_relative 'echo_server'
7
8
 
8
9
  $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
@@ -1,40 +1,20 @@
1
- require File.expand_path 'test_helper', File.dirname(__FILE__)
1
+ require_relative 'test_helper'
2
2
 
3
3
  class TestWebSocketClientSimple < MiniTest::Test
4
4
 
5
- def port
6
- (ENV['WS_PORT'] || 18080).to_i
7
- end
8
-
9
5
  def test_echo
10
6
  msgs = ['foo','bar','baz']
11
7
  res1 = []
12
8
  res2 = []
13
9
 
14
10
  EM::run{
15
- @channel = EM::Channel.new
16
-
17
- ## echo server
18
- WebSocket::EventMachine::Server.start(:host => "0.0.0.0", :port => port) do |ws|
19
- ws.onopen do
20
- sid = @channel.subscribe do |mes|
21
- ws.send mes
22
- end
23
- ws.onmessage do |msg|
24
- @channel.push msg
25
- end
26
- ws.onclose do
27
- @channel.unsubscribe sid
28
- end
29
- end
30
- end
11
+ EchoServer.start
31
12
 
32
13
  ## client1 --> server --> client2
33
14
  EM::add_timer 1 do
34
- url = "ws://localhost:#{port}"
35
- client1 = WebSocket::Client::Simple.connect url
15
+ client1 = WebSocket::Client::Simple.connect EchoServer.url
16
+ client2 = WebSocket::Client::Simple.connect EchoServer.url
36
17
  assert_equal client1.open?, false
37
- client2 = WebSocket::Client::Simple.connect url
38
18
  assert_equal client2.open?, false
39
19
 
40
20
  client1.on :message do |msg|
@@ -5,19 +5,28 @@ require 'websocket-client-simple/version'
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "websocket-client-simple"
7
7
  spec.version = WebSocket::Client::Simple::VERSION
8
- spec.authors = ["Sho Hashimoto"]
9
- spec.email = ["hashimoto@shokai.org"]
8
+ spec.authors = ["Sho Hashimoto", "Yusuke Nakamura"]
9
+ spec.email = ["hashimoto@shokai.org", "yusuke1994525@gmail.com"]
10
10
  spec.description = %q{Simple WebSocket Client for Ruby}
11
11
  spec.summary = spec.description
12
- spec.homepage = "https://github.com/shokai/websocket-client-simple"
12
+ spec.homepage = "https://github.com/ruby-jp/websocket-client-simple"
13
13
  spec.license = "MIT"
14
+ spec.required_ruby_version = '>= 2.6.9'
15
+
16
+ if spec.respond_to?(:metadata)
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["changelog_uri"] = "https://github.com/ruby-jp/websocket-client-simple/blob/master/History.txt"
20
+ end
21
+
22
+ spec.post_install_message = "The development of this gem has moved to #{spec.homepage}."
14
23
 
15
24
  spec.files = `git ls-files`.split($/).reject{|f| f == "Gemfile.lock" }
16
25
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
26
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
27
  spec.require_paths = ["lib"]
19
28
 
20
- spec.add_development_dependency "bundler", "~> 1.3"
29
+ spec.add_development_dependency "bundler"
21
30
  spec.add_development_dependency "rake"
22
31
  spec.add_development_dependency "minitest"
23
32
  spec.add_development_dependency "websocket-eventmachine-server"
metadata CHANGED
@@ -1,29 +1,30 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-client-simple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
8
+ - Yusuke Nakamura
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
12
+ date: 2021-12-31 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: bundler
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
- - - "~>"
18
+ - - ">="
18
19
  - !ruby/object:Gem::Version
19
- version: '1.3'
20
+ version: '0'
20
21
  type: :development
21
22
  prerelease: false
22
23
  version_requirements: !ruby/object:Gem::Requirement
23
24
  requirements:
24
- - - "~>"
25
+ - - ">="
25
26
  - !ruby/object:Gem::Version
26
- version: '1.3'
27
+ version: '0'
27
28
  - !ruby/object:Gem::Dependency
28
29
  name: rake
29
30
  requirement: !ruby/object:Gem::Requirement
@@ -111,12 +112,13 @@ dependencies:
111
112
  description: Simple WebSocket Client for Ruby
112
113
  email:
113
114
  - hashimoto@shokai.org
115
+ - yusuke1994525@gmail.com
114
116
  executables: []
115
117
  extensions: []
116
118
  extra_rdoc_files: []
117
119
  files:
120
+ - ".github/workflows/test.yml"
118
121
  - ".gitignore"
119
- - ".travis.yml"
120
122
  - Gemfile
121
123
  - History.txt
122
124
  - LICENSE.txt
@@ -129,14 +131,19 @@ files:
129
131
  - sample/echo_server.rb
130
132
  - sample/webbrowser/index.html
131
133
  - sample/webbrowser/main.js
134
+ - test/echo_server.rb
135
+ - test/test_connect_block.rb
132
136
  - test/test_helper.rb
133
137
  - test/test_websocket_client_simple.rb
134
138
  - websocket-client-simple.gemspec
135
- homepage: https://github.com/shokai/websocket-client-simple
139
+ homepage: https://github.com/ruby-jp/websocket-client-simple
136
140
  licenses:
137
141
  - MIT
138
- metadata: {}
139
- post_install_message:
142
+ metadata:
143
+ homepage_uri: https://github.com/ruby-jp/websocket-client-simple
144
+ source_code_uri: https://github.com/ruby-jp/websocket-client-simple
145
+ changelog_uri: https://github.com/ruby-jp/websocket-client-simple/blob/master/History.txt
146
+ post_install_message: The development of this gem has moved to https://github.com/ruby-jp/websocket-client-simple.
140
147
  rdoc_options: []
141
148
  require_paths:
142
149
  - lib
@@ -144,18 +151,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
151
  requirements:
145
152
  - - ">="
146
153
  - !ruby/object:Gem::Version
147
- version: '0'
154
+ version: 2.6.9
148
155
  required_rubygems_version: !ruby/object:Gem::Requirement
149
156
  requirements:
150
157
  - - ">="
151
158
  - !ruby/object:Gem::Version
152
159
  version: '0'
153
160
  requirements: []
154
- rubyforge_project:
155
- rubygems_version: 2.4.5
161
+ rubygems_version: 3.1.6
156
162
  signing_key:
157
163
  specification_version: 4
158
164
  summary: Simple WebSocket Client for Ruby
159
165
  test_files:
166
+ - test/echo_server.rb
167
+ - test/test_connect_block.rb
160
168
  - test/test_helper.rb
161
169
  - test/test_websocket_client_simple.rb
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - '2.1.2'
5
- notifications:
6
- slack:
7
- secure: avBo0DyucPM8qK2F2qNT5yirZJNcXWfY9d4QKxZLfOa4aQZJ6y/x78Guo8fki/8ZLNnud+rsty3/QkPxBi3YUWcyIuCXMEcuYc8BWOjL+oD37DPgJxGg6ANKxuMotZMUzZweplkd/KgafugOHr7fsPt5UwX2ZYrZr+ksuemEoxs=