socket.io-client-simple 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +9 -0
- data/Gemfile.lock +3 -1
- data/History.txt +8 -0
- data/README.md +7 -7
- data/Rakefile +7 -0
- data/lib/socket.io-client-simple/client.rb +1 -1
- data/lib/socket.io-client-simple/version.rb +1 -1
- data/package.json +22 -0
- data/samples/chat_server.js +10 -1
- data/samples/sample.rb +6 -6
- data/socket.io-client-simple.gemspec +1 -0
- data/test/server.rb +16 -0
- data/test/test_helper.rb +8 -0
- data/test/test_socket.io.rb +35 -0
- metadata +26 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2afed194d20af9d81e21b0048f1c056f12736ea1
|
4
|
+
data.tar.gz: 6113d9b1854c2a2a9e97fe37f682be60fa634e52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a7d3e056498915bb1ab326dc070962cc2d84127799af6f65670e3c7fa35b8684e574538d2aa420da0d4449493c6b1559e34af69df7fbdb74e34927710021551
|
7
|
+
data.tar.gz: b3f08e4f17e8cb4075b2e16d29a77a1c486e8508383c315a20ede5cd8caeeb616922c955e8e4370e1ebed34ed99b92dfb9851762c16a7cbfa94434116f3430e4
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
socket.io-client-simple (0.0.
|
4
|
+
socket.io-client-simple (0.0.2)
|
5
5
|
event_emitter
|
6
6
|
httparty
|
7
7
|
json
|
@@ -15,6 +15,7 @@ GEM
|
|
15
15
|
json (~> 1.8)
|
16
16
|
multi_xml (>= 0.5.2)
|
17
17
|
json (1.8.1)
|
18
|
+
minitest (5.2.1)
|
18
19
|
multi_xml (0.5.5)
|
19
20
|
rake (10.1.1)
|
20
21
|
websocket (1.1.2)
|
@@ -27,5 +28,6 @@ PLATFORMS
|
|
27
28
|
|
28
29
|
DEPENDENCIES
|
29
30
|
bundler (~> 1.3)
|
31
|
+
minitest
|
30
32
|
rake
|
31
33
|
socket.io-client-simple!
|
data/History.txt
ADDED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
A simple ruby client for node.js's socket.io. Supports only WebSocket.
|
3
3
|
|
4
4
|
- https://github.com/shokai/ruby-socket.io-client-simple
|
5
|
-
- https://rubygems.org/gems/
|
5
|
+
- https://rubygems.org/gems/socket.io-client-simple
|
6
6
|
|
7
7
|
|
8
8
|
## Install
|
@@ -17,17 +17,17 @@ A simple ruby client for node.js's socket.io. Supports only WebSocket.
|
|
17
17
|
require 'rubygems'
|
18
18
|
require 'socket.io-client-simple'
|
19
19
|
|
20
|
-
|
20
|
+
socket = SocketIO::Client::Simple.connect 'http://localhost:3000'
|
21
21
|
|
22
|
-
|
22
|
+
socket.on :connect do
|
23
23
|
puts "connect!!!"
|
24
24
|
end
|
25
25
|
|
26
|
-
|
26
|
+
socket.on :disconnect do
|
27
27
|
puts "disconnected!!"
|
28
28
|
end
|
29
29
|
|
30
|
-
|
30
|
+
socket.on :chat do |data|
|
31
31
|
puts "> " + data['msg']
|
32
32
|
end
|
33
33
|
|
@@ -35,7 +35,7 @@ puts "please input and press Enter key"
|
|
35
35
|
loop do
|
36
36
|
msg = STDIN.gets.strip
|
37
37
|
next if msg.empty?
|
38
|
-
|
38
|
+
socket.emit :chat, {:msg => msg, :at => Time.now}
|
39
39
|
end
|
40
40
|
```
|
41
41
|
|
@@ -43,7 +43,7 @@ sample.rb works with [samples/chat_server.js](https://github.com/shokai/ruby-soc
|
|
43
43
|
|
44
44
|
### start chat server
|
45
45
|
|
46
|
-
% npm install
|
46
|
+
% npm install
|
47
47
|
% node samples/chat_server.js
|
48
48
|
|
49
49
|
=> chat server start at localhost:3000
|
data/Rakefile
CHANGED
data/package.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"name": "ruby-socket.io-client-simple",
|
3
|
+
"description": "A simple ruby client for node.js's socket.io. Supports only WebSocket.",
|
4
|
+
"private": true,
|
5
|
+
"author": "Sho Hashimoto <hashimoto@shokai.org>",
|
6
|
+
"license": "MIT",
|
7
|
+
"homepage": "https://github.com/shokai/ruby-socket.io-client-simple",
|
8
|
+
"dependencies": {
|
9
|
+
"socket.io": "~0.9.16"
|
10
|
+
},
|
11
|
+
"devDependencies": {},
|
12
|
+
"scripts": {
|
13
|
+
"start": "node samples/chat_server.js"
|
14
|
+
},
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "git://github.com/shokai/ruby-socket.io-client-simple.git"
|
18
|
+
},
|
19
|
+
"bugs": {
|
20
|
+
"url": "https://github.com/shokai/ruby-socket.io-client-simple/issues"
|
21
|
+
}
|
22
|
+
}
|
data/samples/chat_server.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
// socket.io chat server
|
2
|
+
var port = (process.env.PORT || 3000) - 0;
|
2
3
|
|
3
|
-
var io = require('socket.io').listen(
|
4
|
+
var io = require('socket.io').listen(port);
|
5
|
+
console.log("socket.io server start - port:"+port);
|
4
6
|
|
5
7
|
io.sockets.on('connection', function(socket){
|
6
8
|
socket.emit('chat', {msg: 'hello world (from server)'});
|
@@ -9,3 +11,10 @@ io.sockets.on('connection', function(socket){
|
|
9
11
|
socket.emit('chat', data); // echo
|
10
12
|
});
|
11
13
|
});
|
14
|
+
|
15
|
+
|
16
|
+
if(!!process.env.EXIT_AT){
|
17
|
+
setTimeout(function(){
|
18
|
+
process.exit();
|
19
|
+
}, process.env.EXIT_AT-0);
|
20
|
+
}
|
data/samples/sample.rb
CHANGED
@@ -2,21 +2,21 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'socket.io-client-simple'
|
4
4
|
|
5
|
-
|
5
|
+
socket = SocketIO::Client::Simple.connect 'http://localhost:3000'
|
6
6
|
|
7
|
-
#
|
7
|
+
#socket.websocket.on :message do |msg| ## inspect websocket data
|
8
8
|
# p msg.data
|
9
9
|
#end
|
10
10
|
|
11
|
-
|
11
|
+
socket.on :connect do
|
12
12
|
puts "connect!!!"
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
socket.on :disconnect do
|
16
16
|
puts "disconnected!!"
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
socket.on :chat do |data|
|
20
20
|
puts "> " + data['msg']
|
21
21
|
end
|
22
22
|
|
@@ -24,5 +24,5 @@ puts "please input and press Enter key"
|
|
24
24
|
loop do
|
25
25
|
msg = STDIN.gets.strip
|
26
26
|
next if msg.empty?
|
27
|
-
|
27
|
+
socket.emit :chat, {:msg => msg, :at => Time.now}
|
28
28
|
end
|
data/test/server.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class TestServer
|
2
|
+
|
3
|
+
def self.port
|
4
|
+
(ENV['PORT'] || 13000).to_i
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.start(exit_at=4000)
|
8
|
+
system "PORT=#{port} EXIT_AT=#{exit_at} npm start > /dev/null &"
|
9
|
+
sleep 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.url
|
13
|
+
"http://localhost:#{port}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.expand_path 'test_helper', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class TestSocketIOClientSimple < MiniTest::Test
|
4
|
+
|
5
|
+
def setup
|
6
|
+
TestServer.start
|
7
|
+
end
|
8
|
+
|
9
|
+
def test_connect
|
10
|
+
socket = SocketIO::Client::Simple.connect TestServer.url
|
11
|
+
result = false
|
12
|
+
socket.on :connect do
|
13
|
+
result = true
|
14
|
+
end
|
15
|
+
sleep 0.5
|
16
|
+
assert result
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_emit_on
|
20
|
+
socket = SocketIO::Client::Simple.connect TestServer.url
|
21
|
+
result = nil
|
22
|
+
socket.on :chat do |data| ## receive echo
|
23
|
+
result = data
|
24
|
+
end
|
25
|
+
|
26
|
+
post_data = {"msg" => "hello", "at" => Time.now.to_s}
|
27
|
+
socket.on :connect do
|
28
|
+
socket.emit :chat, post_data
|
29
|
+
end
|
30
|
+
|
31
|
+
sleep 0.5
|
32
|
+
assert_equal post_data, result
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socket.io-client-simple
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sho Hashimoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: json
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,8 +116,10 @@ extensions: []
|
|
102
116
|
extra_rdoc_files: []
|
103
117
|
files:
|
104
118
|
- .gitignore
|
119
|
+
- .travis.yml
|
105
120
|
- Gemfile
|
106
121
|
- Gemfile.lock
|
122
|
+
- History.txt
|
107
123
|
- LICENSE.txt
|
108
124
|
- README.md
|
109
125
|
- Rakefile
|
@@ -111,9 +127,13 @@ files:
|
|
111
127
|
- lib/socket.io-client-simple/client.rb
|
112
128
|
- lib/socket.io-client-simple/error.rb
|
113
129
|
- lib/socket.io-client-simple/version.rb
|
130
|
+
- package.json
|
114
131
|
- samples/chat_server.js
|
115
132
|
- samples/sample.rb
|
116
133
|
- socket.io-client-simple.gemspec
|
134
|
+
- test/server.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
- test/test_socket.io.rb
|
117
137
|
homepage: https://github.com/shokai/ruby-socket.io-client-simple
|
118
138
|
licenses:
|
119
139
|
- MIT
|
@@ -138,4 +158,7 @@ rubygems_version: 2.0.14
|
|
138
158
|
signing_key:
|
139
159
|
specification_version: 4
|
140
160
|
summary: A simple ruby client for node.js's socket.io. Supports only WebSocket.
|
141
|
-
test_files:
|
161
|
+
test_files:
|
162
|
+
- test/server.rb
|
163
|
+
- test/test_helper.rb
|
164
|
+
- test/test_socket.io.rb
|