socket.io-client-simple 1.1.0 → 1.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 +4 -4
- data/.travis.yml +6 -3
- data/Gemfile.lock +3 -3
- data/History.txt +7 -0
- data/lib/socket.io-client-simple.rb +1 -0
- data/lib/socket.io-client-simple/client.rb +24 -14
- data/lib/socket.io-client-simple/version.rb +1 -1
- data/samples/sample.coffee +2 -1
- data/samples/sample.rb +2 -1
- data/socket.io-client-simple.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bca9a1cac4a5f1360162905a37d5312ea2efead6
|
4
|
+
data.tar.gz: 671a1c8640db9d0c6b765e28b40a7d25e5c063a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae32b7c6015a2f3db1698089c037136d4ce9a0b6c051abc277d60c0f1704c9bf14a9ee8a73a5db67478268c39d6657701928f2f34a65cf4300e08f39f6d08b63
|
7
|
+
data.tar.gz: 26e9f1dc32b32be4f2c7b583c7147d8c42e42998a5155193a8ae3f501353d5b12a2b2f60335761caaa0b0e30227cc41f09ea9d196017856d8cdcd8e3bab2194f
|
data/.travis.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
language: ruby
|
2
2
|
node_js:
|
3
|
-
-
|
3
|
+
- '0.10'
|
4
4
|
rvm:
|
5
|
-
-
|
6
|
-
- 2.
|
5
|
+
- '2.0.0'
|
6
|
+
- '2.1.2'
|
7
7
|
before_script:
|
8
8
|
- npm install
|
9
|
+
notifications:
|
10
|
+
slack:
|
11
|
+
secure: VDGagENM7+Hie8WSRvlvN+tjIxTf7AN2LSXb25Y8XVdY5UAL1ScQzLhObOHZ91W+MzLAOlVk19lPxdXUrH/n1a9R/mjPeikdZCfwQqMeI6db6BltMP3QhJyJyubuBQP0TrD1TfKyQuSHO+8+UcsHPzwaGy4VmOV3S6ctZ3dRyo8=
|
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
socket.io-client-simple (1.
|
4
|
+
socket.io-client-simple (1.1.2)
|
5
5
|
event_emitter
|
6
6
|
httparty
|
7
7
|
json
|
8
|
-
websocket-client-simple (>= 0.
|
8
|
+
websocket-client-simple (>= 0.2.1)
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
@@ -19,7 +19,7 @@ GEM
|
|
19
19
|
multi_xml (0.5.5)
|
20
20
|
rake (10.3.2)
|
21
21
|
websocket (1.2.1)
|
22
|
-
websocket-client-simple (0.2.
|
22
|
+
websocket-client-simple (0.2.1)
|
23
23
|
event_emitter
|
24
24
|
websocket
|
25
25
|
|
data/History.txt
CHANGED
@@ -13,7 +13,7 @@ module SocketIO
|
|
13
13
|
alias_method :__emit, :emit
|
14
14
|
|
15
15
|
attr_accessor :auto_reconnection, :websocket, :url, :reconnecting, :state,
|
16
|
-
:session_id, :ping_interval, :ping_timeout, :last_pong_at
|
16
|
+
:session_id, :ping_interval, :ping_timeout, :last_pong_at, :last_ping_at
|
17
17
|
|
18
18
|
def initialize(url, opts={})
|
19
19
|
@url = url
|
@@ -25,13 +25,21 @@ module SocketIO
|
|
25
25
|
|
26
26
|
Thread.new do
|
27
27
|
loop do
|
28
|
-
if @
|
29
|
-
@
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
if @websocket
|
29
|
+
if @state == :connect
|
30
|
+
if Time.now.to_i - @last_ping_at > @ping_interval/1000
|
31
|
+
@websocket.send "2" ## ping
|
32
|
+
@last_ping_at = Time.now.to_i
|
33
|
+
end
|
34
|
+
end
|
35
|
+
if @websocket.open? and Time.now.to_i - @last_pong_at > @ping_timeout/1000
|
36
|
+
@websocket.close
|
37
|
+
@state = :disconnect
|
38
|
+
__emit :disconnect
|
39
|
+
reconnect
|
40
|
+
end
|
34
41
|
end
|
42
|
+
sleep 1
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
@@ -39,7 +47,7 @@ module SocketIO
|
|
39
47
|
|
40
48
|
|
41
49
|
def connect
|
42
|
-
query = @opts.map{|k,v| "#{k}=#{v}" }.join '&'
|
50
|
+
query = @opts.map{|k,v| URI.encode "#{k}=#{v}" }.join '&'
|
43
51
|
begin
|
44
52
|
@websocket = WebSocket::Client::Simple.connect "#{@url}/socket.io/?#{query}"
|
45
53
|
rescue Errno::ECONNREFUSED => e
|
@@ -48,6 +56,7 @@ module SocketIO
|
|
48
56
|
reconnect
|
49
57
|
return
|
50
58
|
end
|
59
|
+
@reconnecting = false
|
51
60
|
|
52
61
|
this = self
|
53
62
|
|
@@ -67,15 +76,16 @@ module SocketIO
|
|
67
76
|
code = code.to_i
|
68
77
|
case code
|
69
78
|
when 0 ## socket.io connect
|
70
|
-
this.reconnecting = false
|
71
79
|
body = JSON.parse body rescue next
|
72
|
-
this.session_id = body["sid"]
|
73
|
-
this.ping_interval = body["pingInterval"]
|
74
|
-
this.ping_timeout
|
80
|
+
this.session_id = body["sid"] || "no_sid"
|
81
|
+
this.ping_interval = body["pingInterval"] || 25000
|
82
|
+
this.ping_timeout = body["pingTimeout"] || 60000
|
83
|
+
this.last_ping_at = Time.now.to_i
|
84
|
+
this.last_pong_at = Time.now.to_i
|
75
85
|
this.state = :connect
|
76
86
|
this.__emit :connect
|
77
87
|
when 3 ## pong
|
78
|
-
this.last_pong_at = Time.now
|
88
|
+
this.last_pong_at = Time.now.to_i
|
79
89
|
when 41 ## disconnect from server
|
80
90
|
this.websocket.close if this.websocket.open?
|
81
91
|
this.state = :disconnect
|
@@ -95,7 +105,7 @@ module SocketIO
|
|
95
105
|
return unless @auto_reconnection
|
96
106
|
return if @reconnecting
|
97
107
|
@reconnecting = true
|
98
|
-
sleep rand(
|
108
|
+
sleep rand(5) + 5
|
99
109
|
connect
|
100
110
|
end
|
101
111
|
|
data/samples/sample.coffee
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
#!/usr/bin/env coffee
|
2
2
|
## npm insatll socket.io-client coffee-script
|
3
3
|
|
4
|
-
|
4
|
+
url = process.argv[2] or 'http://localhost:3000'
|
5
|
+
socket = require('socket.io-client').connect url, {transports: ['websocket']}
|
5
6
|
|
6
7
|
socket.on 'connect', ->
|
7
8
|
console.log 'connect!!'
|
data/samples/sample.rb
CHANGED
@@ -2,7 +2,8 @@ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'socket.io-client-simple'
|
4
4
|
|
5
|
-
|
5
|
+
url = ARGV.shift or 'http://localhost:3000'
|
6
|
+
socket = SocketIO::Client::Simple.connect url
|
6
7
|
|
7
8
|
# socket.auto_reconnection = false
|
8
9
|
|
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "minitest"
|
24
24
|
|
25
25
|
spec.add_dependency "json"
|
26
|
-
spec.add_dependency "websocket-client-simple", '>= 0.
|
26
|
+
spec.add_dependency "websocket-client-simple", '>= 0.2.1'
|
27
27
|
spec.add_dependency "httparty"
|
28
28
|
spec.add_dependency "event_emitter"
|
29
29
|
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: 1.1.
|
4
|
+
version: 1.1.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-10-
|
11
|
+
date: 2014-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.2.1
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.2.1
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: httparty
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|