slanger 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of slanger might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +9 -8
- data/bin/slanger +12 -0
- data/lib/slanger/api_server.rb +3 -12
- data/lib/slanger/connection.rb +9 -5
- data/lib/slanger/handler.rb +22 -4
- data/lib/slanger/presence_channel.rb +1 -1
- data/lib/slanger/subscription.rb +1 -1
- data/lib/slanger/version.rb +1 -1
- data/lib/slanger/webhook.rb +8 -3
- metadata +22 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abbd4b1fc22d16cd1a72b1bd647fa4f3703f580d
|
4
|
+
data.tar.gz: 0b6db960a6b39f26a219b8cb7cf56826b02ca111
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a5cab2cc4a2672405ec12bc830dd43c0051183a68aa54c24a07426d4012c0570a5dda15b1c9a78178347137e61fc2001c3ee9ca4bd716ba3b89b601384e1882
|
7
|
+
data.tar.gz: a2fc49dbb668a8a343c69c852fb946faaa29d89cdadc4f50386a3b810b578bd388cdd0e93d73ad81462797825711badab9a59b91ffa7096d4e777ebb744c3f1c
|
data/README.md
CHANGED
@@ -103,14 +103,14 @@ Pusher.port = 4567
|
|
103
103
|
|
104
104
|
You will also need to do the same to the Pusher JavaScript client in your client side JavaScript, e.g
|
105
105
|
|
106
|
-
```
|
106
|
+
```html
|
107
107
|
<script type="text/javascript">
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
108
|
+
var pusher = new Pusher('#{Pusher.key}', {
|
109
|
+
wsHost: "0.0.0.0",
|
110
|
+
wsPort: "8080",
|
111
|
+
wssPort: "8080",
|
112
|
+
enabledTransports: ['ws', 'flash']
|
113
|
+
});
|
114
114
|
</script>
|
115
115
|
```
|
116
116
|
|
@@ -140,8 +140,9 @@ Slanger supports several configuration options, which can be supplied as command
|
|
140
140
|
-c or --cert_file Certificate file for SSL support. This argument is optional, if given, SSL will be enabled
|
141
141
|
|
142
142
|
-v or --[no-]verbose This makes Slanger run verbosely, meaning WebSocket frames will be echoed to STDOUT. Useful for debugging
|
143
|
-
```
|
144
143
|
|
144
|
+
--pid_file The path to a file you want slanger to write it's PID to. Optional.
|
145
|
+
```
|
145
146
|
|
146
147
|
# Why use Slanger instead of Pusher?
|
147
148
|
|
data/bin/slanger
CHANGED
@@ -64,6 +64,10 @@ OptionParser.new do |opts|
|
|
64
64
|
options[:activity_timeout] = t
|
65
65
|
end
|
66
66
|
|
67
|
+
opts.on '--pid_file PIDFILE', "The Slanger process ID file name." do |k|
|
68
|
+
options[:pid_file] = k
|
69
|
+
end
|
70
|
+
|
67
71
|
opts.parse!
|
68
72
|
|
69
73
|
%w<app_key secret>.each do |parameter|
|
@@ -85,12 +89,20 @@ if options[:tls_options]
|
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
92
|
+
STDOUT.sync = true
|
93
|
+
|
88
94
|
EM.epoll
|
89
95
|
EM.kqueue
|
90
96
|
|
91
97
|
EM.run do
|
92
98
|
File.tap { |f| require f.expand_path(f.join(f.dirname(__FILE__),'..', 'slanger.rb')) }
|
93
99
|
Slanger::Config.load options
|
100
|
+
|
101
|
+
# Write PID to file
|
102
|
+
unless options[:pid_file].nil?
|
103
|
+
File.open(options[:pid_file], 'w') { |f| f.puts Process.pid }
|
104
|
+
end
|
105
|
+
|
94
106
|
Slanger::Service.run
|
95
107
|
|
96
108
|
puts "\n"
|
data/lib/slanger/api_server.rb
CHANGED
@@ -28,6 +28,7 @@ module Slanger
|
|
28
28
|
# Send event to each channel
|
29
29
|
data["channels"].each { |channel| publish(channel, data['name'], data['data']) }
|
30
30
|
|
31
|
+
status 202
|
31
32
|
return {}.to_json
|
32
33
|
end
|
33
34
|
|
@@ -36,6 +37,7 @@ module Slanger
|
|
36
37
|
|
37
38
|
publish(params[:channel_id], params['name'], request.body.read.tap{ |s| s.force_encoding('utf-8') })
|
38
39
|
|
40
|
+
status 202
|
39
41
|
return {}.to_json
|
40
42
|
end
|
41
43
|
|
@@ -56,18 +58,7 @@ module Slanger
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def publish(channel, event, data)
|
59
|
-
|
60
|
-
|
61
|
-
# Publish the event in Redis and translate the result into an HTTP
|
62
|
-
# status to return to the client.
|
63
|
-
Slanger::Redis.publish(channel, payload(channel, event, data)).tap do |r|
|
64
|
-
r.callback { f.resume [202, {}, "202 ACCEPTED\n"] }
|
65
|
-
r.errback { f.resume [500, {}, "500 INTERNAL SERVER ERROR\n"] }
|
66
|
-
end
|
67
|
-
|
68
|
-
Fiber.yield
|
61
|
+
Slanger::Redis.publish(channel, payload(channel, event, data))
|
69
62
|
end
|
70
|
-
|
71
63
|
end
|
72
64
|
end
|
73
|
-
|
data/lib/slanger/connection.rb
CHANGED
@@ -17,21 +17,25 @@ module Slanger
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def error e
|
20
|
-
|
20
|
+
begin
|
21
|
+
send_payload nil, 'pusher:error', e
|
22
|
+
rescue EventMachine::WebSocket::WebSocketError
|
23
|
+
# Raised if connecection already closed. Only seen with Thor load testing tool
|
24
|
+
end
|
21
25
|
end
|
22
26
|
|
23
27
|
def establish
|
24
28
|
@socket_id = SecureRandom.uuid
|
25
29
|
send_payload nil, 'pusher:connection_established', {
|
26
|
-
|
27
|
-
|
28
|
-
|
30
|
+
socket_id: @socket_id,
|
31
|
+
activity_timeout: Slanger::Config.activity_timeout
|
32
|
+
}
|
29
33
|
end
|
30
34
|
|
31
35
|
private
|
32
36
|
|
33
37
|
def format(channel_id, event_name, payload = {})
|
34
|
-
body = { event: event_name, data: payload }
|
38
|
+
body = { event: event_name, data: payload.to_json }
|
35
39
|
body[:channel] = channel_id if channel_id
|
36
40
|
body.to_json
|
37
41
|
end
|
data/lib/slanger/handler.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/core_ext/hash'
|
|
5
5
|
require 'securerandom'
|
6
6
|
require 'signature'
|
7
7
|
require 'fiber'
|
8
|
+
require 'rack'
|
8
9
|
|
9
10
|
module Slanger
|
10
11
|
class Handler
|
@@ -23,7 +24,10 @@ module Slanger
|
|
23
24
|
# Dispatches message handling to method with same name as
|
24
25
|
# the event name
|
25
26
|
def onmessage(msg)
|
26
|
-
msg
|
27
|
+
msg = JSON.parse(msg)
|
28
|
+
|
29
|
+
msg['data'] = JSON.parse(msg['data']) if msg['data'].is_a? String
|
30
|
+
|
27
31
|
event = msg['event'].gsub(/^pusher:/, 'pusher_')
|
28
32
|
|
29
33
|
if event =~ /^client-/
|
@@ -47,10 +51,19 @@ module Slanger
|
|
47
51
|
end
|
48
52
|
|
49
53
|
def authenticate
|
50
|
-
|
54
|
+
if !valid_app_key? app_key
|
55
|
+
error({ code: 4001, message: "Could not find app by key #{app_key}" })
|
56
|
+
@socket.close_websocket
|
57
|
+
elsif !valid_protocol_version?
|
58
|
+
error({ code: 4007, message: "Unsupported protocol version" })
|
59
|
+
@socket.close_websocket
|
60
|
+
else
|
61
|
+
return connection.establish
|
62
|
+
end
|
63
|
+
end
|
51
64
|
|
52
|
-
|
53
|
-
|
65
|
+
def valid_protocol_version?
|
66
|
+
protocol_version.between?(3, 7)
|
54
67
|
end
|
55
68
|
|
56
69
|
def pusher_ping(msg)
|
@@ -83,6 +96,11 @@ module Slanger
|
|
83
96
|
@handshake.path.split(/\W/)[2]
|
84
97
|
end
|
85
98
|
|
99
|
+
def protocol_version
|
100
|
+
@query_string ||= Rack::Utils.parse_nested_query(@handshake.query_string)
|
101
|
+
@query_string["protocol"].to_i || -1
|
102
|
+
end
|
103
|
+
|
86
104
|
def valid_app_key? app_key
|
87
105
|
Slanger::Config.app_key == app_key
|
88
106
|
end
|
@@ -127,7 +127,7 @@ module Slanger
|
|
127
127
|
# Don't tell the channel subscriptions the member has been removed if the subscriber data
|
128
128
|
# still remains in the subscriptions hash, i.e. multiple browser windows open.
|
129
129
|
subscriber = subscriptions.delete message['subscription_id']
|
130
|
-
|
130
|
+
if subscriber && !subscriptions.has_value?(subscriber)
|
131
131
|
push payload('pusher_internal:member_removed', { user_id: subscriber['user_id'] })
|
132
132
|
end
|
133
133
|
end
|
data/lib/slanger/subscription.rb
CHANGED
data/lib/slanger/version.rb
CHANGED
data/lib/slanger/webhook.rb
CHANGED
@@ -10,11 +10,16 @@ module Slanger
|
|
10
10
|
time_ms: Time.now.strftime('%s%L'), events: [payload]
|
11
11
|
}.to_json
|
12
12
|
|
13
|
-
digest
|
14
|
-
hmac
|
13
|
+
digest = OpenSSL::Digest::SHA256.new
|
14
|
+
hmac = OpenSSL::HMAC.hexdigest(digest, Slanger::Config.secret, payload)
|
15
|
+
content_type = 'application/json'
|
15
16
|
|
16
17
|
EM::HttpRequest.new(Slanger::Config.webhook_url).
|
17
|
-
post(body: payload, head: {
|
18
|
+
post(body: payload, head: {
|
19
|
+
"X-Pusher-Key" => Slanger::Config.app_key,
|
20
|
+
"X-Pusher-Signature" => hmac,
|
21
|
+
"Content-Type" => content_type
|
22
|
+
})
|
18
23
|
# TODO: Exponentially backed off retries for errors
|
19
24
|
end
|
20
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slanger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stevie Graham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eventmachine
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.5.
|
47
|
+
version: 0.5.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.5.
|
54
|
+
version: 0.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rack
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: 0.
|
187
|
+
version: 0.14.2
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: 0.
|
194
|
+
version: 0.14.2
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: haml
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -262,6 +262,20 @@ dependencies:
|
|
262
262
|
- - "~>"
|
263
263
|
- !ruby/object:Gem::Version
|
264
264
|
version: 0.13.2
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: pry
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 0.10.1
|
272
|
+
type: :development
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: 0.10.1
|
265
279
|
description: A websocket service compatible with Pusher libraries
|
266
280
|
email: sjtgraham@mac.com
|
267
281
|
executables:
|
@@ -298,7 +312,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
298
312
|
requirements:
|
299
313
|
- - ">="
|
300
314
|
- !ruby/object:Gem::Version
|
301
|
-
version: 2.
|
315
|
+
version: 2.0.0
|
302
316
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
303
317
|
requirements:
|
304
318
|
- - ">="
|
@@ -306,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
306
320
|
version: '0'
|
307
321
|
requirements: []
|
308
322
|
rubyforge_project:
|
309
|
-
rubygems_version: 2.
|
323
|
+
rubygems_version: 2.2.2
|
310
324
|
signing_key:
|
311
325
|
specification_version: 4
|
312
326
|
summary: A websocket service compatible with Pusher libraries
|