socket.io-client-simple 1.1.0 → 1.1.2

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
2
  SHA1:
3
- metadata.gz: 6293cae06f3938964054ea93f5837c3ee3fe920a
4
- data.tar.gz: 103d3bd06faea135bdcba6c59e96a47de8c8e0df
3
+ metadata.gz: bca9a1cac4a5f1360162905a37d5312ea2efead6
4
+ data.tar.gz: 671a1c8640db9d0c6b765e28b40a7d25e5c063a9
5
5
  SHA512:
6
- metadata.gz: ff36295267269bb7f87e5748eecdce1d6e02ef5c279ddef9481e81792ffec5f940cc342accafb91fe51710210da2ce9da3dd671b757291854f59b4a768e86362
7
- data.tar.gz: 3120faf19a55589c9a8eae733b58a4c069a3c5b5a67985da176f6bb189dcb0eab354658b516295e9c81c8a7ee58ee0f1c42b049c32c13aa0ea3a91e6bf33bc56
6
+ metadata.gz: ae32b7c6015a2f3db1698089c037136d4ce9a0b6c051abc277d60c0f1704c9bf14a9ee8a73a5db67478268c39d6657701928f2f34a65cf4300e08f39f6d08b63
7
+ data.tar.gz: 26e9f1dc32b32be4f2c7b583c7147d8c42e42998a5155193a8ae3f501353d5b12a2b2f60335761caaa0b0e30227cc41f09ea9d196017856d8cdcd8e3bab2194f
@@ -1,8 +1,11 @@
1
1
  language: ruby
2
2
  node_js:
3
- - "0.10"
3
+ - '0.10'
4
4
  rvm:
5
- - 1.9.3
6
- - 2.0.0
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=
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- socket.io-client-simple (1.0.0)
4
+ socket.io-client-simple (1.1.2)
5
5
  event_emitter
6
6
  httparty
7
7
  json
8
- websocket-client-simple (>= 0.0.9)
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.0)
22
+ websocket-client-simple (0.2.1)
23
23
  event_emitter
24
24
  websocket
25
25
 
@@ -1,3 +1,10 @@
1
+ === 1.1.1 2014-10-20
2
+
3
+ * bugfix reconnection on websocket proxy #9
4
+ * fix samples
5
+ * bundle update, use websocket-client-simple v0.2.1 #9
6
+ * bugfix encoding handshake query parameter #5
7
+
1
8
  === 1.1.0 2014-10-04
2
9
 
3
10
  * support Socket.IO v1.1x
@@ -1,3 +1,4 @@
1
+ require 'uri'
1
2
  require 'json'
2
3
  require 'httparty'
3
4
  require 'websocket-client-simple'
@@ -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 @state == :connect
29
- @websocket.send "2" ## ping
30
- @last_ping_at = Time.now
31
- sleep @ping_interval/1000
32
- else
33
- sleep 1
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 = body["pingTimeout"]
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(10)+5
108
+ sleep rand(5) + 5
99
109
  connect
100
110
  end
101
111
 
@@ -1,7 +1,7 @@
1
1
  module SocketIO
2
2
  module Client
3
3
  module Simple
4
- VERSION = "1.1.0"
4
+ VERSION = "1.1.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env coffee
2
2
  ## npm insatll socket.io-client coffee-script
3
3
 
4
- socket = require('socket.io-client').connect('http://localhost:3000')
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!!'
@@ -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
- socket = SocketIO::Client::Simple.connect 'http://localhost:3000'
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.0.9'
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.0
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-04 00:00:00.000000000 Z
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.0.9
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.0.9
82
+ version: 0.2.1
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: httparty
85
85
  requirement: !ruby/object:Gem::Requirement