simple_pusher 0.0.3 → 0.0.4

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
- N2MyNzZjMjk3OTYwNGFjNWMxODQ4NmIxNDk2NDhiZGQzNDViNWU5ZA==
4
+ NjQxMTcwYzBlZDE1NDg4NjY5MGJiYTE3OGNlZjRhMGJmYTQ0NmU4ZQ==
5
5
  data.tar.gz: !binary |-
6
- N2M1YzcyZTM0MzI5MmU1NTdmMTdhNzdmOTcyNGM0OWQyMzU2N2JhOA==
6
+ M2VlNzhkMTE0MWVlN2IwY2ViNjQ0NDY1OGZjZmI0ZDk4NmQxZTA0Ng==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MGZkM2ZjNmFkZGEyNjc3NGVkN2E5MzBhZjYxZjI0NDQ0OTY2NDk5NDgyNGM3
10
- YjBjZjIwM2M2NmQwMWE2NGMwNmIwMmJlMDI3YTM4Nzk5NjZkNzA5OWI1MjJk
11
- YTU4YmE4NWE5ZDgxMDFlNDFlYmJhZjZjN2NjNjZmZjllZmJjMGQ=
9
+ MzQ1YmNhM2YyOTQxZjI2MmZiNmFhN2FjMTEyZjMwYzkwZjU2ZDY2YzBmZjZh
10
+ MzQxM2Y0NDQ3OTQ1Mzk4ZTMxMWU3MmJlMDM5Yjg0OTNlYzg2NjRlNDM4ZDlk
11
+ ZWExZDMwNDUxOTU1NWFjNTk3MzkzZjg5NzJkMmZkOThiMmE0NGE=
12
12
  data.tar.gz: !binary |-
13
- MTY4M2UzZjUyM2I2MTVjYTU2ZWNlMTkzMWU4NmM2ZDU3ZDZmYTIxZDI5MDM2
14
- OGUzMGRjODI1MDRiNzBlYmQ0YzcyYjM5NjIxZTg2MWM4NGMyMTg3ODFmZGU5
15
- NzgyMWM2MjhmMjU0ZTg2MzYzM2U0Y2JkYjAxYmU0ZTIzMzg2YWU=
13
+ NWJiMGYyNTQ2NzlmYTdkMDhjNTQ3YjViMmJlMWM2NWIwNjQyY2RjNzU5OTk3
14
+ MDk0OTIyMmY0MzFmMmJiNTI5YWNkZTcxNGQ1NmI0NWNkZDVlNzhhMjdhMDVh
15
+ OTMxMzE1MTJkZGYyZjY2MzU0MjI5MGNkNWIxMzlmYjZiOWU4MTg=
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # SimplePusher
1
+ # SimplePusher [![Gem Version](https://badge.fury.io/rb/simple_pusher@2x.png)](http://badge.fury.io/rb/simple_pusher)
2
2
 
3
- SimplePusher is a HTML5 websocket powered realtime messaging tool used in Rails project.
3
+ SimplePusher is a HTML5 websocket powered realtime messaging tool used in Rails / Sintra project.
4
4
 
5
5
  ## Installation
6
6
 
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -17,6 +17,7 @@ module SimplePusher
17
17
  end
18
18
 
19
19
  def self.trigger(event)
20
+ callbacks[event] ||= []
20
21
  callbacks[event].each {|callback| callback.call }
21
22
  end
22
23
 
@@ -1,3 +1,3 @@
1
1
  module SimplePusher
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,20 +1,17 @@
1
1
  class SimplePusher
2
2
  constructor: (url) ->
3
3
  @websocket = new WebSocket(url)
4
- @websocket.onmessage = (e) ->
5
- event = e.data.split(":")
4
+ @_callbacks ||= {}
5
+ @websocket.onmessage = (e) =>
6
+ data = e.data.split(":")
7
+ event = data[0]
8
+ message = data[1..-1].join(":")
9
+ callback_fn.call(this, message) for callback_fn in @_callbacks[event]
6
10
 
7
- on: (event_name, callback) ->
8
- if event_name == 'connect'
9
- console.log("on open")
10
- @websocket.onopen = callback
11
- else if event_name == 'message'
12
- console.log("on message")
13
- @websocket.onmessage = (e) ->
14
- callback(e.data)
15
- else if event_name == 'close'
16
- console.log("on close")
17
- @websocket.onclose = callback
11
+ on: (event_name, callback_fn) ->
12
+ @_callbacks[event_name] = (@_callbacks[event_name] ||= [])
13
+ @_callbacks[event_name].push(callback_fn)
14
+ this
18
15
 
19
16
  broadcast: (message) ->
20
17
  @websocket.send("broadcast:#{message}")
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.3
4
+ version: 0.0.4
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-18 00:00:00.000000000 Z
11
+ date: 2014-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket