simple_pusher 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjQxMTcwYzBlZDE1NDg4NjY5MGJiYTE3OGNlZjRhMGJmYTQ0NmU4ZQ==
4
+ ZDIxNTNkOTYxMGQxMGM3MzdlZDE5OTcwYzVkNmVlMGM3ODJhYjFmYg==
5
5
  data.tar.gz: !binary |-
6
- M2VlNzhkMTE0MWVlN2IwY2ViNjQ0NDY1OGZjZmI0ZDk4NmQxZTA0Ng==
6
+ YWNkYTc0ZjgzN2UwYWU2OGFlMGMxZGY5ZTFjOGIxOGY2NmU1YjA5OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MzQ1YmNhM2YyOTQxZjI2MmZiNmFhN2FjMTEyZjMwYzkwZjU2ZDY2YzBmZjZh
10
- MzQxM2Y0NDQ3OTQ1Mzk4ZTMxMWU3MmJlMDM5Yjg0OTNlYzg2NjRlNDM4ZDlk
11
- ZWExZDMwNDUxOTU1NWFjNTk3MzkzZjg5NzJkMmZkOThiMmE0NGE=
9
+ MWFhOTBlMjgxMDc2OTM4ZjFiNWNiZmU3ZTg3OTE1ZTIzNDg2MDUzNzg4YTUx
10
+ NDMxODhkNTRhNmRlMGM3MGI2ZmY1MjliOTM2MTY1NzgxNjk0YzJlMDkyNWMz
11
+ ZTY1YThmYjY3MDRmOWYxYTVmZmUyNzRiNThkMTI0MDBmODRiYTY=
12
12
  data.tar.gz: !binary |-
13
- NWJiMGYyNTQ2NzlmYTdkMDhjNTQ3YjViMmJlMWM2NWIwNjQyY2RjNzU5OTk3
14
- MDk0OTIyMmY0MzFmMmJiNTI5YWNkZTcxNGQ1NmI0NWNkZDVlNzhhMjdhMDVh
15
- OTMxMzE1MTJkZGYyZjY2MzU0MjI5MGNkNWIxMzlmYjZiOWU4MTg=
13
+ ZDNiOTc0OTk5N2ZiMzk3MzhjOTQwNTRhZjhlZWU5OGRjMTI0OWFiZDVmMzRi
14
+ ZGNjNTcyNmM1ZTY2OTIyZTk4MWQyMjdhYjk3YjdkYzBhNjE4Y2YyYmM3YTI0
15
+ YzhmNDEwNzJhYWZiYjk3MjQzNTYzMTM1YjU0ZDQ5OWQ2OGQ3YjQ=
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # SimplePusher [![Gem Version](https://badge.fury.io/rb/simple_pusher@2x.png)](http://badge.fury.io/rb/simple_pusher)
1
+ # SimplePusher
2
2
 
3
3
  SimplePusher is a HTML5 websocket powered realtime messaging tool used in Rails / Sintra project.
4
4
 
5
5
  ## Installation
6
6
 
7
+ [![Gem Version](https://badge.fury.io/rb/simple_pusher@2x.png)](http://badge.fury.io/rb/simple_pusher)
8
+
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  gem 'simple_pusher'
@@ -22,7 +24,6 @@ Then start simple pusher server when rails app boot:
22
24
  EventMachine.next_tick do
23
25
  SimplePusher.setup do |config|
24
26
  config.port = 8088
25
- config.debug = false
26
27
  end
27
28
  SimplePusher.start
28
29
  end
@@ -41,14 +42,16 @@ Add code to app/views/layouts/application.html.erb
41
42
  ```
42
43
  <script type="text/javascript">
43
44
  var simple_pusher = new SimplePusher("ws://<%= request.host %>:8088/");
44
- simple_pusher.broadcast("Hello everybody.");
45
+ simple_pusher.on('channel_name', function(message){
46
+ alert('got message:'+message);
47
+ });
45
48
  </script>
46
49
  ```
47
50
 
48
51
  Broadcast message via server side.
49
52
 
50
53
  ```
51
- SimplePusher.broadcast("Time now #{Time.now.to_s(:db}")
54
+ SimplePusher.publish('channel_name', "Time now #{Time.now.to_s(:db}")
52
55
  ```
53
56
 
54
57
  Message callback at server side.
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
2
  require 'rake/testtask'
3
3
 
4
4
  Rake::TestTask.new do |t|
5
- t.libs << "test"
6
- t.test_files = FileList['test/*_test.rb']
7
- t.verbose = true
5
+ t.libs << 'test'
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
8
  end
9
9
 
10
- task :default => :test
10
+ task default: :test
@@ -7,7 +7,5 @@ module SimplePusher
7
7
  @port ||= 8088
8
8
  @debug ||= false
9
9
  end
10
-
11
-
12
10
  end
13
- end
11
+ end
@@ -18,11 +18,11 @@ module SimplePusher
18
18
 
19
19
  def self.trigger(event)
20
20
  callbacks[event] ||= []
21
- callbacks[event].each {|callback| callback.call }
21
+ callbacks[event].each { |callback| callback.call }
22
22
  end
23
23
 
24
24
  def self.add_client(socket)
25
- client = self.new(socket)
25
+ client = new(socket)
26
26
  clients[socket] = client
27
27
  end
28
28
 
@@ -30,9 +30,9 @@ module SimplePusher
30
30
  clients.delete(socket)
31
31
  end
32
32
 
33
- def self.broadcast(message)
34
- clients.each do |websocket, client|
35
- websocket.send message
33
+ def self.publish(channel, message)
34
+ clients.each do |websocket, _client|
35
+ websocket.send "#{channel}:#{message}"
36
36
  end
37
37
  end
38
38
 
@@ -47,6 +47,5 @@ module SimplePusher
47
47
  def emit(message)
48
48
  @websocket.send(message)
49
49
  end
50
-
51
50
  end
52
- end
51
+ end
@@ -1,5 +1,4 @@
1
1
  module SimplePusher
2
2
  class Engine < ::Rails::Engine
3
-
4
3
  end
5
- end
4
+ end
@@ -6,45 +6,43 @@ module SimplePusher
6
6
  class Server
7
7
  include Singleton
8
8
 
9
- attr :host, :port
9
+ attr_reader :host, :port
10
10
 
11
11
  def initialize
12
- @host = "0.0.0.0"
12
+ @host = '0.0.0.0'
13
13
  @port = SimplePusher.configuration.port
14
14
  end
15
15
 
16
16
  def self.start
17
- $stderr.puts "Start SimplePush ..." if SimplePusher.configuration.debug
18
- EM::WebSocket.run(:host => instance.host, :port => instance.port) do |socket|
17
+ $stderr.puts 'Start SimplePusher ...' if SimplePusher.configuration.debug
18
+ EM::WebSocket.run(host: instance.host, port: instance.port) do |socket|
19
19
  socket.onopen do |handshake|
20
- $stderr.puts "on open:" + handshake.inspect if SimplePusher.configuration.debug
20
+ $stderr.puts 'on open:' + handshake.inspect if SimplePusher.configuration.debug
21
21
  Connection.add_client(socket)
22
22
  end
23
23
 
24
24
  socket.onclose do
25
- $stderr.puts "on close"
25
+ $stderr.puts 'on close'
26
26
  Connection.remove_client(socket)
27
27
  end
28
28
 
29
29
  socket.onmessage do |raw_message|
30
- $stderr.puts "on message: " + raw_message if SimplePusher.configuration.debug
31
- action, *message = raw_message.split(":")
30
+ $stderr.puts 'on message: ' + raw_message if SimplePusher.configuration.debug
31
+ action, *message = raw_message.split(':')
32
32
 
33
33
  case action
34
34
  when 'broadcast'
35
- message = message.join(":")
35
+ message = message.join(':')
36
36
  Connection.broadcast(message)
37
37
  when 'emit'
38
38
  event = message[0]
39
39
  Connection.trigger(event)
40
40
  else
41
- #TODO
41
+ # TODO
42
42
  end
43
43
  end
44
44
 
45
-
46
45
  end
47
46
  end
48
-
49
47
  end
50
- end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module SimplePusher
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.5'
3
3
  end
data/lib/simple_pusher.rb CHANGED
@@ -1,9 +1,8 @@
1
- require "simple_pusher/version"
1
+ require 'simple_pusher/version'
2
2
  require 'em-websocket'
3
3
  require 'simple_pusher/engine' if defined?(Rails)
4
4
 
5
5
  module SimplePusher
6
-
7
6
  class << self
8
7
  def setup
9
8
  yield configuration
@@ -15,14 +14,16 @@ module SimplePusher
15
14
  end
16
15
  end
17
16
 
18
- def start(options={})
17
+ def start(_options = {})
19
18
  EventMachine.next_tick do
20
19
  Server.start
21
20
  end
22
21
  end
23
22
 
24
- def broadcast(message)
25
- Connection.broadcast(message)
23
+ # Publish message to all connected socket.
24
+ # And the client websocket which listened 'channel' will get message callback.
25
+ def publish(channel, message = '')
26
+ Connection.publish(channel, message)
26
27
  end
27
28
 
28
29
  def on(event, &callback)
@@ -30,11 +31,10 @@ module SimplePusher
30
31
  end
31
32
 
32
33
  module_function :start
33
- module_function :broadcast
34
+ module_function :publish
34
35
  module_function :on
35
-
36
36
  end
37
37
 
38
- SimplePusher.autoload :Configuration, "simple_pusher/configuration"
39
- SimplePusher.autoload :Connection, "simple_pusher/connection"
40
- SimplePusher.autoload :Server, "simple_pusher/server"
38
+ SimplePusher.autoload :Configuration, 'simple_pusher/configuration'
39
+ SimplePusher.autoload :Connection, 'simple_pusher/connection'
40
+ SimplePusher.autoload :Server, 'simple_pusher/server'
@@ -4,22 +4,22 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'simple_pusher/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "simple_pusher"
7
+ spec.name = 'simple_pusher'
8
8
  spec.version = SimplePusher::VERSION
9
- spec.authors = ["qichunren"]
10
- spec.email = ["whyruby@gmail.com"]
11
- spec.description = %q{Simple pusher based on websocket}
12
- spec.summary = %q{Simple pusher based on websocket, build with Eventmachine}
13
- spec.homepage = ""
14
- spec.license = "MIT"
9
+ spec.authors = ['qichunren']
10
+ spec.email = ['whyruby@gmail.com']
11
+ spec.description = %q(Simple pusher based on websocket)
12
+ spec.summary = %q(Simple pusher based on websocket, build with Eventmachine)
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "em-websocket", "~> 0.5.0"
21
+ spec.add_dependency 'em-websocket', '~> 0.5.0'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.3"
24
- spec.add_development_dependency "rake"
23
+ spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'rake'
25
25
  end
@@ -1,14 +1,14 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  describe SimplePusher::Configuration do
4
- it "must respond to debug method" do
4
+ it 'must respond to debug method' do
5
5
  configuration = SimplePusher::Configuration.new
6
- configuration.debug.must_equal false #default to false
6
+ configuration.debug.must_equal false # default to false
7
7
  end
8
8
 
9
- it "must respond to port method" do
9
+ it 'must respond to port method' do
10
10
  configuration = SimplePusher::Configuration.new
11
- configuration.port.must_equal 8088 #default to 8088
11
+ configuration.port.must_equal 8088 # default to 8088
12
12
  end
13
13
 
14
- end
14
+ end
@@ -1,12 +1,12 @@
1
- require File.expand_path("../test_helper", __FILE__)
1
+ require File.expand_path('../test_helper', __FILE__)
2
2
 
3
3
  describe SimplePusher do
4
4
 
5
- it "must respond version method" do
5
+ it 'must respond version method' do
6
6
  SimplePusher::VERSION.wont_be_nil
7
7
  end
8
8
 
9
- it "setup method work" do
9
+ it 'setup method work' do
10
10
  # EventMachine.run do
11
11
  #
12
12
  # end
@@ -16,7 +16,4 @@ describe SimplePusher do
16
16
  SimplePusher.configuration.port.must_equal 8888
17
17
  end
18
18
 
19
-
20
-
21
19
  end
22
-
data/test/test_helper.rb CHANGED
@@ -1,10 +1,9 @@
1
- ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__)
2
2
  require 'bundler'
3
3
  Bundler.setup
4
4
  Bundler.require :default, :test
5
5
 
6
6
  require 'minitest/autorun'
7
7
 
8
-
9
8
  lib = File.expand_path('../../lib', __FILE__)
10
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
9
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - qichunren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-20 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket