socketio-client 0.0.1 → 0.0.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.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/README.md +5 -5
- data/lib/SocketIO.rb +14 -9
- data/socketio-client.gemspec +1 -1
- data/spec/parser_spec.rb +2 -2
- data/spec/socketio_spec.rb +2 -2
- metadata +12 -5
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/Gemfile.lock
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -15,9 +15,9 @@ This client currently supports:
|
|
15
15
|
## How to use:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
require '
|
18
|
+
require 'SocketIO'
|
19
19
|
|
20
|
-
client = SocketIO.connect("localhost") do
|
20
|
+
client = SocketIO.connect("http://localhost") do
|
21
21
|
before_start do
|
22
22
|
on_message {|message| puts "incoming message: #{message}"}
|
23
23
|
on_event('news') { |data| puts data.first} # data is an array fo things.
|
@@ -32,9 +32,9 @@ You can start the socket io syncronously and then continue with your work
|
|
32
32
|
this crates threads so be careful.
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
require '
|
35
|
+
require 'SocketIO'
|
36
36
|
|
37
|
-
client = SocketIO.connect("localhost", sync: true) do
|
37
|
+
client = SocketIO.connect("http://localhost", sync: true) do
|
38
38
|
before_start do
|
39
39
|
on_message {|message| puts message}
|
40
40
|
on_disconnect {puts "I GOT A DISCONNECT"}
|
@@ -55,4 +55,4 @@ end
|
|
55
55
|
## Examples
|
56
56
|
|
57
57
|
examples can be found in the examples/ folder.
|
58
|
-
A corrosponding server can be found in the examples/servers
|
58
|
+
A corrosponding server can be found in the examples/servers
|
data/lib/SocketIO.rb
CHANGED
@@ -5,18 +5,20 @@ require 'parser'
|
|
5
5
|
|
6
6
|
module SocketIO
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
# params [URI, String] uri
|
9
|
+
def self.connect(uri, options = {}, &block)
|
10
|
+
uri = URI(uri)
|
11
|
+
# handshke
|
12
|
+
response = RestClient.get "#{uri.scheme}://#{uri.host}:#{uri.port}/socket.io/1/"
|
11
13
|
response_array = response.split(':')
|
12
|
-
response_array = [
|
14
|
+
response_array = [uri] + response_array << options
|
13
15
|
cli = Client.new(*response_array)
|
14
16
|
cli.instance_eval(&block) if block
|
15
17
|
cli.start
|
16
18
|
end
|
17
19
|
|
18
20
|
class Client
|
19
|
-
VERSION = "0.0.
|
21
|
+
VERSION = "0.0.2"
|
20
22
|
|
21
23
|
[:INT, :TERM].each do |sig|
|
22
24
|
Signal.trap(sig) do
|
@@ -29,8 +31,10 @@ module SocketIO
|
|
29
31
|
# The state of the Socket.IO socket can be disconnected, disconnecting, connected and connecting.
|
30
32
|
# The transport connection can be closed, closing, open, and opening.
|
31
33
|
|
32
|
-
def initialize(
|
33
|
-
@
|
34
|
+
def initialize(uri, session_id, heartbeat_timeout, connection_timeout, supported_transports, options = {})
|
35
|
+
@uri = uri
|
36
|
+
namespace = uri.path.sub(%r~^/~, '')
|
37
|
+
@namespace = namespace.empty? ? "socket.io" : namespace
|
34
38
|
@session_id = session_id
|
35
39
|
@hb_timeout = heartbeat_timeout
|
36
40
|
@connect_timeout = connection_timeout
|
@@ -51,7 +55,8 @@ module SocketIO
|
|
51
55
|
|
52
56
|
def connect_transport
|
53
57
|
if @supported_transports.include? "websocket"
|
54
|
-
|
58
|
+
scheme = @uri.scheme == "https" ? "wss" : "ws"
|
59
|
+
@transport = WebSocket.new("#{scheme}://#{@uri.host}:#{@uri.port}/socket.io/1/websocket/#{@session_id}", origin: @uri.to_s)
|
55
60
|
else
|
56
61
|
raise "We only support WebSockets.. and this server doesnt like web sockets.. O NO!!"
|
57
62
|
end
|
@@ -166,4 +171,4 @@ module SocketIO
|
|
166
171
|
end
|
167
172
|
end
|
168
173
|
|
169
|
-
end
|
174
|
+
end
|
data/socketio-client.gemspec
CHANGED
data/spec/parser_spec.rb
CHANGED
data/spec/socketio_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
describe SocketIO do
|
2
2
|
|
3
3
|
before :all do
|
4
|
-
@client = SocketIO.connect("localhost", :sync => true)
|
4
|
+
@client = SocketIO.connect("http://localhost", :sync => true)
|
5
5
|
end
|
6
6
|
|
7
7
|
it "can send a heartbeat" do
|
@@ -43,4 +43,4 @@ describe SocketIO do
|
|
43
43
|
|
44
44
|
|
45
45
|
|
46
|
-
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: socketio-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-03-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: uses a very simple web socket
|
26
31
|
email:
|
27
32
|
- lyon@delorum.com
|
@@ -29,6 +34,7 @@ executables: []
|
|
29
34
|
extensions: []
|
30
35
|
extra_rdoc_files: []
|
31
36
|
files:
|
37
|
+
- .gitignore
|
32
38
|
- Gemfile
|
33
39
|
- README.md
|
34
40
|
- Rakefile
|
@@ -69,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
75
|
version: '0'
|
70
76
|
requirements: []
|
71
77
|
rubyforge_project: socketio-client
|
72
|
-
rubygems_version: 1.8.
|
78
|
+
rubygems_version: 1.8.20
|
73
79
|
signing_key:
|
74
80
|
specification_version: 3
|
75
81
|
summary: A basic Socket.io client implememtation written for ruby
|
@@ -79,3 +85,4 @@ test_files:
|
|
79
85
|
- spec/setup/start.rb
|
80
86
|
- spec/setup/stop.rb
|
81
87
|
- spec/socketio_spec.rb
|
88
|
+
has_rdoc:
|