websocket-client-simple 0.2.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/test.yml +23 -0
- data/.gitignore +2 -0
- data/History.txt +21 -1
- data/README.md +17 -4
- data/lib/websocket-client-simple/client.rb +15 -3
- data/lib/websocket-client-simple/version.rb +1 -1
- data/test/echo_server.rb +26 -0
- data/test/test_connect_block.rb +33 -0
- data/test/test_helper.rb +1 -0
- data/test/test_websocket_client_simple.rb +4 -24
- data/websocket-client-simple.gemspec +13 -4
- metadata +21 -13
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7d666b814dc1c12018495f1eb3e5810ff95ac854cb2e6b67e8932d6d9e2734be
|
4
|
+
data.tar.gz: dc8803a68f0a83dca8cc7768669294b98329fc425caa6e29329fb5aed1221670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9cd01826ba0e697dfd029422491317f25d4946688fc1ad3764d7d5c1976f0913ed030839213a04772099882989a0c324700320ef409e31770ae9a63c2870431
|
7
|
+
data.tar.gz: 4ce1ef9d1ebc4a67f373c527e151ece73717f8e782fca31b09dd77baa242c3e93ccf4d5918e7c23381671adceeb69075b4987f5a5e5336f358000692bb0b09c9
|
@@ -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
data/History.txt
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
+
=== 0.4.0 2021-12-30
|
2
|
+
|
3
|
+
* Drop support of ruby 2.5 or older versions as explicit.
|
4
|
+
|
5
|
+
=== 0.3.1 2021-12-30
|
6
|
+
|
7
|
+
* The development of this repository has moved to https://github.com/ruby-jp/websocket-client-simple
|
8
|
+
|
9
|
+
=== 0.3.0 2016-02-20
|
10
|
+
|
11
|
+
* "connect" method runs a given block before connecting WebSocket #12
|
12
|
+
* thank you for suggestion @codekitchen
|
13
|
+
|
14
|
+
=== 0.2.5 2016-02-18
|
15
|
+
|
16
|
+
* bugfixed sending when broken pipe #15
|
17
|
+
* add :verify_mode option for SSL Context #14
|
18
|
+
* thank you for contributing @michaelvilensky
|
19
|
+
|
1
20
|
=== 0.2.4 2015-11-12
|
2
21
|
|
3
|
-
* support handshake headers
|
22
|
+
* support handshake headers #11
|
23
|
+
* thank you for contributing @mathieugagne
|
4
24
|
|
5
25
|
=== 0.2.3 2015-10-26
|
6
26
|
|
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/
|
5
|
+
- https://github.com/ruby-jp/websocket-client-simple
|
6
6
|
- https://rubygems.org/gems/websocket-client-simple
|
7
7
|
|
8
|
-
[![
|
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,14 +3,18 @@ module WebSocket
|
|
3
3
|
module Simple
|
4
4
|
|
5
5
|
def self.connect(url, options={})
|
6
|
-
::WebSocket::Client::Simple::Client.new
|
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
|
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,
|
@@ -18,11 +22,16 @@ module WebSocket
|
|
18
22
|
if ['https', 'wss'].include? uri.scheme
|
19
23
|
ctx = OpenSSL::SSL::SSLContext.new
|
20
24
|
ctx.ssl_version = options[:ssl_version] || 'SSLv23'
|
25
|
+
ctx.verify_mode = options[:verify_mode] || OpenSSL::SSL::VERIFY_NONE #use VERIFY_PEER for verification
|
26
|
+
cert_store = OpenSSL::X509::Store.new
|
27
|
+
cert_store.set_default_paths
|
28
|
+
ctx.cert_store = cert_store
|
21
29
|
@socket = ::OpenSSL::SSL::SSLSocket.new(@socket, ctx)
|
22
30
|
@socket.connect
|
23
31
|
end
|
24
32
|
@handshake = ::WebSocket::Handshake::Client.new :url => url, :headers => options[:headers]
|
25
33
|
@handshaked = false
|
34
|
+
@pipe_broken = false
|
26
35
|
frame = ::WebSocket::Frame::Incoming::Client.new
|
27
36
|
@closed = false
|
28
37
|
once :__close do |err|
|
@@ -65,13 +74,16 @@ module WebSocket
|
|
65
74
|
begin
|
66
75
|
@socket.write frame.to_s
|
67
76
|
rescue Errno::EPIPE => e
|
77
|
+
@pipe_broken = true
|
68
78
|
emit :__close, e
|
69
79
|
end
|
70
80
|
end
|
71
81
|
|
72
82
|
def close
|
73
83
|
return if @closed
|
74
|
-
|
84
|
+
if !@pipe_broken
|
85
|
+
send nil, :type => :close
|
86
|
+
end
|
75
87
|
@closed = true
|
76
88
|
@socket.close if @socket
|
77
89
|
@socket = nil
|
data/test/echo_server.rb
ADDED
@@ -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
@@ -1,40 +1,20 @@
|
|
1
|
-
|
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
|
-
|
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
|
-
|
35
|
-
|
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/
|
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"
|
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.
|
4
|
+
version: 0.4.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:
|
12
|
+
date: 2021-12-30 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: '
|
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: '
|
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/
|
139
|
+
homepage: https://github.com/ruby-jp/websocket-client-simple
|
136
140
|
licenses:
|
137
141
|
- MIT
|
138
|
-
metadata:
|
139
|
-
|
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:
|
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
|
-
|
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
|