pusher-client 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +5 -5
- data/README.rdoc +3 -1
- data/VERSION +1 -1
- data/examples/hello_pusher.rb +1 -1
- data/examples/hello_pusher_async.rb +2 -2
- data/lib/pusher-client.rb +1 -0
- data/lib/pusher-client/socket.rb +22 -42
- data/lib/pusher-client/websocket.rb +64 -0
- data/pkg/pusher-client-0.1.1.gem +0 -0
- data/test/teststrap.rb +3 -1
- metadata +8 -11
- data/.bundle/config +0 -2
- data/pkg/pusher-client-0.1.0.gem +0 -0
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
addressable (2.2.2)
|
5
4
|
bacon (1.1.0)
|
6
|
-
em-http-request (0.2.15)
|
7
|
-
addressable (>= 2.0.0)
|
8
|
-
eventmachine (>= 0.12.9)
|
9
5
|
eventmachine (0.12.10)
|
6
|
+
eventmachine (0.12.10-java)
|
10
7
|
git (1.2.5)
|
11
8
|
jeweler (1.5.2)
|
12
9
|
bundler (~> 1.0.0)
|
13
10
|
git (>= 1.2.5)
|
14
11
|
rake
|
12
|
+
libwebsocket (0.1.0)
|
15
13
|
rake (0.8.7)
|
16
14
|
rcov (0.9.9)
|
15
|
+
rcov (0.9.9-java)
|
17
16
|
|
18
17
|
PLATFORMS
|
18
|
+
java
|
19
19
|
ruby
|
20
20
|
|
21
21
|
DEPENDENCIES
|
22
22
|
bacon
|
23
23
|
bundler (~> 1.0.0)
|
24
|
-
em-http-request (~> 0.2.15)
|
25
24
|
eventmachine (~> 0.12.10)
|
26
25
|
jeweler (~> 1.5.2)
|
26
|
+
libwebsocket
|
27
27
|
rcov
|
data/README.rdoc
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
pusher-client is a ruby gem for consuming WebSockets from the Pusher webservice[http://pusherapp.com]
|
4
4
|
|
5
|
-
|
5
|
+
The connection to Pusher can optionally be maintained in its own thread (see Asynchronous Usage)
|
6
|
+
|
7
|
+
This gem no longer depends on em-http, and is compatible with jruby as of 0.2.
|
6
8
|
|
7
9
|
== Installation
|
8
10
|
gem install pusher-client
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/examples/hello_pusher.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'pusher-client'
|
2
|
+
require './lib/pusher-client.rb'
|
3
3
|
require 'pp'
|
4
4
|
|
5
|
-
YOUR_APPLICATION_KEY = ''
|
5
|
+
YOUR_APPLICATION_KEY = '73c70db2f09b7f279382'
|
6
6
|
|
7
7
|
PusherClient.logger = Logger.new('/dev/null')
|
8
8
|
socket = PusherClient::Socket.new(YOUR_APPLICATION_KEY)
|
data/lib/pusher-client.rb
CHANGED
@@ -18,6 +18,7 @@ end
|
|
18
18
|
|
19
19
|
Thread.abort_on_exception = true
|
20
20
|
|
21
|
+
require File.dirname(__FILE__) + '/pusher-client/websocket.rb'
|
21
22
|
require File.dirname(__FILE__) + '/pusher-client/socket.rb'
|
22
23
|
require File.dirname(__FILE__) + '/pusher-client/channel.rb'
|
23
24
|
require File.dirname(__FILE__) + '/pusher-client/channels.rb'
|
data/lib/pusher-client/socket.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require 'json'
|
2
|
-
require 'eventmachine'
|
3
|
-
require 'em-http'
|
4
2
|
|
5
3
|
module PusherClient
|
6
4
|
class Socket
|
@@ -40,54 +38,36 @@ module PusherClient
|
|
40
38
|
end
|
41
39
|
|
42
40
|
def connect(async = false)
|
43
|
-
@
|
44
|
-
|
45
|
-
if @encrypted || @secure
|
46
|
-
url = "wss://#{HOST}:#{WSS_PORT}#{@path}"
|
47
|
-
else
|
48
|
-
url = "ws://#{HOST}:#{WS_PORT}#{@path}"
|
49
|
-
end
|
50
|
-
PusherClient.logger.debug("Pusher : connecting : #{url}")
|
51
|
-
|
52
|
-
@connection = EventMachine::HttpRequest.new(url).get :timeout => 0
|
53
|
-
|
54
|
-
@connection.callback {
|
55
|
-
PusherClient.logger.debug "Websocket connected"
|
56
|
-
}
|
57
|
-
|
58
|
-
@connection.stream { |msg|
|
59
|
-
PusherClient.logger.debug "Received: #{msg}"
|
60
|
-
params = parser(msg)
|
61
|
-
return if (params['socket_id'] && params['socket_id'] == this.socket_id)
|
62
|
-
|
63
|
-
event_name = params['event']
|
64
|
-
event_data = params['data']
|
65
|
-
channel_name = params['channel']
|
66
|
-
|
67
|
-
send_local_event(event_name, event_data, channel_name)
|
68
|
-
}
|
69
|
-
|
70
|
-
@connection.errback {
|
71
|
-
PusherClient.logger.fatal "Pusher : eventmachine error"
|
72
|
-
}
|
73
|
-
|
74
|
-
@connection.disconnect {
|
75
|
-
PusherClient.logger.debug "Pusher : dropped connection"
|
76
|
-
}
|
77
|
-
}
|
78
|
-
end
|
79
|
-
@connection_thread.run
|
80
|
-
if async
|
81
|
-
sleep(1)
|
41
|
+
if @encrypted || @secure
|
42
|
+
url = "wss://#{HOST}:#{WSS_PORT}#{@path}"
|
82
43
|
else
|
83
|
-
@
|
44
|
+
url = "ws://#{HOST}:#{WS_PORT}#{@path}"
|
84
45
|
end
|
46
|
+
PusherClient.logger.debug("Pusher : connecting : #{url}")
|
47
|
+
|
48
|
+
@connection_thread = Thread.new {
|
49
|
+
@connection = WebSocket.new(url)
|
50
|
+
PusherClient.logger.debug "Websocket connected"
|
51
|
+
loop do
|
52
|
+
msg = @connection.receive[0]
|
53
|
+
params = parser(msg)
|
54
|
+
next if (params['socket_id'] && params['socket_id'] == self.socket_id)
|
55
|
+
event_name = params['event']
|
56
|
+
event_data = params['data']
|
57
|
+
channel_name = params['channel']
|
58
|
+
send_local_event(event_name, event_data, channel_name)
|
59
|
+
end
|
60
|
+
}
|
61
|
+
|
62
|
+
@connection_thread.run
|
63
|
+
@connection_thread.join unless async
|
85
64
|
return self
|
86
65
|
end
|
87
66
|
|
88
67
|
def disconnect
|
89
68
|
if @connected
|
90
69
|
PusherClient.logger.debug "Pusher : disconnecting"
|
70
|
+
@connection.close
|
91
71
|
@connection_thread.kill if @connection_thread
|
92
72
|
@connected = false
|
93
73
|
else
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'socket'
|
3
|
+
require 'libwebsocket'
|
4
|
+
|
5
|
+
module PusherClient
|
6
|
+
class WebSocket
|
7
|
+
|
8
|
+
def initialize(url, params = {})
|
9
|
+
@hs ||= LibWebSocket::OpeningHandshake::Client.new(:url => url, :version => params[:version])
|
10
|
+
@frame ||= LibWebSocket::Frame.new
|
11
|
+
|
12
|
+
@socket = TCPSocket.new(@hs.url.host, @hs.url.port || 80)
|
13
|
+
|
14
|
+
@socket.write(@hs.to_s)
|
15
|
+
@socket.flush
|
16
|
+
|
17
|
+
loop do
|
18
|
+
data = @socket.getc
|
19
|
+
next if data.nil?
|
20
|
+
|
21
|
+
result = @hs.parse(data.chr)
|
22
|
+
|
23
|
+
raise @hs.error unless result
|
24
|
+
|
25
|
+
if @hs.done?
|
26
|
+
@handshaked = true
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def send(data)
|
33
|
+
raise "no handshake!" unless @handshaked
|
34
|
+
|
35
|
+
data = @frame.new(data).to_s
|
36
|
+
@socket.write data
|
37
|
+
@socket.flush
|
38
|
+
end
|
39
|
+
|
40
|
+
def receive
|
41
|
+
raise "no handshake!" unless @handshaked
|
42
|
+
|
43
|
+
data = @socket.gets("\xff")
|
44
|
+
@frame.append(data)
|
45
|
+
|
46
|
+
messages = []
|
47
|
+
while message = @frame.next
|
48
|
+
messages << message
|
49
|
+
end
|
50
|
+
messages
|
51
|
+
end
|
52
|
+
|
53
|
+
def socket
|
54
|
+
@socket
|
55
|
+
end
|
56
|
+
|
57
|
+
def close
|
58
|
+
@socket.close
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
data/pkg/pusher-client-0.1.1.gem
CHANGED
Binary file
|
data/test/teststrap.rb
CHANGED
@@ -36,7 +36,6 @@ module PusherClient
|
|
36
36
|
end
|
37
37
|
@connection_thread.run
|
38
38
|
@connection_thread.join unless async
|
39
|
-
sleep(1)
|
40
39
|
return self
|
41
40
|
end
|
42
41
|
|
@@ -49,6 +48,9 @@ module PusherClient
|
|
49
48
|
def send(payload)
|
50
49
|
PusherClient.logger.test("SEND: #{payload}")
|
51
50
|
end
|
51
|
+
|
52
|
+
def close
|
53
|
+
end
|
52
54
|
end
|
53
55
|
|
54
56
|
PusherClient.logger = TestLogger.new('test.log')
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
version: 0.2.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Logan Koester
|
@@ -33,17 +33,15 @@ dependencies:
|
|
33
33
|
prerelease: false
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: libwebsocket
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
segments:
|
43
43
|
- 0
|
44
|
-
|
45
|
-
- 15
|
46
|
-
version: 0.2.15
|
44
|
+
version: "0"
|
47
45
|
type: :runtime
|
48
46
|
prerelease: false
|
49
47
|
version_requirements: *id002
|
@@ -113,7 +111,6 @@ extra_rdoc_files:
|
|
113
111
|
- LICENSE.txt
|
114
112
|
- README.rdoc
|
115
113
|
files:
|
116
|
-
- .bundle/config
|
117
114
|
- .document
|
118
115
|
- Gemfile
|
119
116
|
- Gemfile.lock
|
@@ -127,7 +124,7 @@ files:
|
|
127
124
|
- lib/pusher-client/channel.rb
|
128
125
|
- lib/pusher-client/channels.rb
|
129
126
|
- lib/pusher-client/socket.rb
|
130
|
-
-
|
127
|
+
- lib/pusher-client/websocket.rb
|
131
128
|
- pkg/pusher-client-0.1.1.gem
|
132
129
|
- pusher-client.gemspec
|
133
130
|
- test/pusherclient_test.rb
|
@@ -147,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
144
|
requirements:
|
148
145
|
- - ">="
|
149
146
|
- !ruby/object:Gem::Version
|
150
|
-
hash: -
|
147
|
+
hash: -2316521902587729957
|
151
148
|
segments:
|
152
149
|
- 0
|
153
150
|
version: "0"
|
data/.bundle/config
DELETED
data/pkg/pusher-client-0.1.0.gem
DELETED
Binary file
|