simple_pusher 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/README.md +30 -1
- data/lib/simple_pusher.rb +6 -4
- data/lib/simple_pusher/engine.rb +3 -0
- data/lib/simple_pusher/middleware.rb +22 -0
- data/lib/simple_pusher/server.rb +0 -1
- data/lib/simple_pusher/sinatra_app.rb +16 -0
- data/lib/simple_pusher/version.rb +1 -1
- data/vendor/assets/javascripts/simple_pusher.coffee +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGIwMzM4YmJlZjZhY2JlZGI2MWI5NzY5ZGE0NWVkNWVlNThjNmI3OQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWY0NGU5YmFlYjQ1N2M1OGYwMmVlODMzNjFlYWJiN2IwNjU3ZWM1OQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDk4ZWRlNWMzMDI0M2ViYjc0YmJmMmZmYWVlZTA3NTdhZDIxYzg2ZmRlMmY0
|
10
|
+
Y2YyODVhMzE3Yzk2NDgwMWFiMDhkYzYyZDlhZjgzYzk1Yzg3YTU1M2U2N2Q5
|
11
|
+
MzQ0YmYwNGRmNWNlZmY3NmRlYTRlYmI4YTY0M2Y2YWZhNGI4ZDI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzNlZjJiMDMxNDA4ZGRlZTg4MTRmMDg5N2ZlM2I4MTZhYjExMDk4MWIzNzA0
|
14
|
+
MGMxMzkzMzRjZWUyZGMxYTdjMmVjZDc1NWFkZWI4ZDhlZjJiYjI5ZjMyNjk0
|
15
|
+
YTNlNmY2NjQzMzgwY2RkNzA5YTc5Njg5Yzg3NjkwODJhMmI1YTI=
|
data/README.md
CHANGED
@@ -54,6 +54,11 @@ Broadcast message via server side.
|
|
54
54
|
SimplePusher.publish('channel_name', "Time now #{Time.now.to_s(:db}")
|
55
55
|
```
|
56
56
|
|
57
|
+
Broadcast message via http POST.
|
58
|
+
```
|
59
|
+
curl -d 'channel=channel1&message=hello' http://localhost:3000/simple_pusher
|
60
|
+
```
|
61
|
+
|
57
62
|
Message callback at server side.
|
58
63
|
|
59
64
|
```
|
@@ -66,12 +71,36 @@ SimplePusher.on("ping") do
|
|
66
71
|
end
|
67
72
|
```
|
68
73
|
|
74
|
+
## Use SimplePusher in Sinatra app
|
75
|
+
|
76
|
+
```
|
77
|
+
# app.rb
|
78
|
+
require 'simple_pusher/sinatra_app'
|
79
|
+
|
80
|
+
EventMachine.next_tick do
|
81
|
+
SimplePusher.setup do |config|
|
82
|
+
config.port = 8088
|
83
|
+
end
|
84
|
+
SimplePusher.start
|
85
|
+
end
|
86
|
+
|
87
|
+
class MyApp < Sinatra::Base
|
88
|
+
|
89
|
+
use SimplePusher::SinatraApp # With this you just setup http post interface: curl -d 'channel=channel1&message=hello' http://localhost:3000/simple_pusher
|
90
|
+
end
|
91
|
+
|
92
|
+
```
|
93
|
+
|
94
|
+
Currently I have not implement directly require simple_pusher js from project. You can download `simple_pusher.coffee` file from [Github repository](https://raw.githubusercontent.com/qichunren/simple_pusher/master/vendor/assets/javascripts/simple_pusher.coffee) to your project for use.
|
95
|
+
|
69
96
|
## Emulating WebSockets in older browsers
|
70
97
|
It is possible to emulate WebSockets in older browsers using flash emulation. For example take a look at the [web-socket-js](https://github.com/gimite/web-socket-js) project.
|
71
98
|
|
72
99
|
## TODO
|
73
100
|
|
74
|
-
* Add `on` method message callback to client js
|
101
|
+
* <del>Add `on` method message callback to client js.</del>
|
102
|
+
* Support JSON format message.
|
103
|
+
* Use SimplePusher js in Sinatra app.
|
75
104
|
|
76
105
|
## Contributing
|
77
106
|
|
data/lib/simple_pusher.rb
CHANGED
@@ -3,6 +3,12 @@ require 'em-websocket'
|
|
3
3
|
require 'simple_pusher/engine' if defined?(Rails)
|
4
4
|
|
5
5
|
module SimplePusher
|
6
|
+
autoload :Configuration, 'simple_pusher/configuration'
|
7
|
+
autoload :Connection, 'simple_pusher/connection'
|
8
|
+
autoload :Server, 'simple_pusher/server'
|
9
|
+
autoload :Middleware, 'simple_pusher/middleware'
|
10
|
+
|
11
|
+
|
6
12
|
class << self
|
7
13
|
def setup
|
8
14
|
yield configuration
|
@@ -34,7 +40,3 @@ module SimplePusher
|
|
34
40
|
module_function :publish
|
35
41
|
module_function :on
|
36
42
|
end
|
37
|
-
|
38
|
-
SimplePusher.autoload :Configuration, 'simple_pusher/configuration'
|
39
|
-
SimplePusher.autoload :Connection, 'simple_pusher/connection'
|
40
|
-
SimplePusher.autoload :Server, 'simple_pusher/server'
|
data/lib/simple_pusher/engine.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
module SimplePusher
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
if env['PATH_INFO'] == '/simple_pusher' && env['REQUEST_METHOD'] == 'POST'
|
9
|
+
# Both support param from url query string and form post data
|
10
|
+
simple_pusher_params = env['rack.request.form_hash'].present? ? env['rack.request.form_hash'] : Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
11
|
+
if simple_pusher_params['channel'].blank?
|
12
|
+
[200, {}, 'Required channel param']
|
13
|
+
else
|
14
|
+
SimplePusher.publish(simple_pusher_params['channel'], simple_pusher_params['message'])
|
15
|
+
[200, {}, 'OK']
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/simple_pusher/server.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
|
3
|
+
module SimplePusher
|
4
|
+
class SinatraApp < Sinatra::Base
|
5
|
+
|
6
|
+
post('/simple_pusher') do
|
7
|
+
params[:channel].to_s.strip!
|
8
|
+
if params[:channel].to_s.length == 0
|
9
|
+
'Required channel param'
|
10
|
+
else
|
11
|
+
SimplePusher.publish(params[:channel], params[:message])
|
12
|
+
'ok'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -6,7 +6,7 @@ class SimplePusher
|
|
6
6
|
data = e.data.split(":")
|
7
7
|
event = data[0]
|
8
8
|
message = data[1..-1].join(":")
|
9
|
-
callback_fn.call(this, message) for callback_fn in @_callbacks[event]
|
9
|
+
callback_fn.call(this, message) for callback_fn in @_callbacks[event] if @_callbacks[event]
|
10
10
|
|
11
11
|
on: (event_name, callback_fn) ->
|
12
12
|
@_callbacks[event_name] = (@_callbacks[event_name] ||= [])
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_pusher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- qichunren
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|
@@ -68,7 +68,9 @@ files:
|
|
68
68
|
- lib/simple_pusher/configuration.rb
|
69
69
|
- lib/simple_pusher/connection.rb
|
70
70
|
- lib/simple_pusher/engine.rb
|
71
|
+
- lib/simple_pusher/middleware.rb
|
71
72
|
- lib/simple_pusher/server.rb
|
73
|
+
- lib/simple_pusher/sinatra_app.rb
|
72
74
|
- lib/simple_pusher/version.rb
|
73
75
|
- simple_pusher.gemspec
|
74
76
|
- test/configuration_test.rb
|