sinatra-multi-screen 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ === 0.0.7 2013-03-06
2
+
3
+ * use Sinatra.register
4
+
1
5
  === 0.0.6 2013-02-27
2
6
 
3
7
  * Server push to TV or Remote
data/README.md CHANGED
@@ -127,7 +127,7 @@ MultiScreen.push :foo, data, {:type => "tv"} # to all TV
127
127
  MultiScreen.push :foo, data, {:type => "remote", :channel => "1"}
128
128
  ```
129
129
 
130
- TV or Remote
130
+ TV or Remote Side
131
131
  ```javascript
132
132
  screen.on("foo", function(data){
133
133
  alert(data.message);
@@ -1,4 +1,4 @@
1
- require "sinatra-multi-screen/version"
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
3
 
3
- module SinatraMultiScreen
4
- end
4
+ require 'sinatra-multi-screen/version'
@@ -0,0 +1,59 @@
1
+ module Sinatra::MultiScreen
2
+
3
+ CometIO.on :__multiscreen__data do |data, from|
4
+ opts = data["options"]
5
+ raise ArgumentError, 'option is empty' if !opts or opts.empty?
6
+ raise ArgumentError, 'channel is empty' if opts["channel"].empty?
7
+ raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
8
+ unless MultiScreen.channels[opts["channel"]][opts["type"]].include? from
9
+ raise StandardError, "client <#{from}> is not member of channel <#{opts['channel']}>"
10
+ end
11
+ MultiScreen.emit data["event"], data["data"], {:session => from, :channel => opts["channel"], :type => opts["type"]}
12
+ type = case opts["type"]
13
+ when "tv"
14
+ "remote"
15
+ when "remote"
16
+ "tv"
17
+ end
18
+ MultiScreen.channels[opts["channel"]][type].each do |session_id|
19
+ CometIO.push :__multiscreen__data, data, {:to => session_id}
20
+ end
21
+ end
22
+
23
+ CometIO.on :__multiscreen__options do |opts, from|
24
+ raise ArgumentError, 'channel is empty' if opts["channel"].empty?
25
+ raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
26
+ MultiScreen.channels[opts["channel"]][opts["type"]] << from
27
+ MultiScreen.emit :connect, {:session => from, :channel => opts["channel"], :type => opts["type"]}
28
+ end
29
+
30
+ CometIO.on :disconnect do |session_id|
31
+ MultiScreen.channels.each do |channel_id, h|
32
+ ["tv", "remote"].each do |type|
33
+ next unless h[type].include? session_id
34
+ h[type].delete session_id
35
+ MultiScreen.emit :disconnect, {:session => session_id, :channel => channel_id, :type => type}
36
+ end
37
+ end
38
+ end
39
+
40
+ helpers do
41
+ def multi_screen_js
42
+ "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}/cometio/multiscreen.js"
43
+ end
44
+ end
45
+
46
+ get '/cometio/multiscreen.js' do
47
+ content_type 'application/javascript'
48
+ @js ||= (
49
+ js = ''
50
+ Dir.glob(File.expand_path '../js/*.js', File.dirname(__FILE__)).each do |i|
51
+ File.open(i) do |f|
52
+ js += f.read
53
+ end
54
+ end
55
+ ERB.new(js).result(binding)
56
+ )
57
+ end
58
+
59
+ end
@@ -1,3 +1,5 @@
1
- module SinatraMultiScreen
2
- VERSION = "0.0.6"
1
+ module Sinatra
2
+ module MultiScreen
3
+ VERSION = "0.0.7"
4
+ end
3
5
  end
@@ -1,6 +1,8 @@
1
1
  require File.expand_path '../sinatra-multi-screen', File.dirname(__FILE__)
2
2
  require 'sinatra/cometio'
3
- require File.expand_path 'application', File.dirname(__FILE__)
3
+ require File.expand_path '../sinatra-multi-screen/application', File.dirname(__FILE__)
4
+
5
+ Sinatra.register Sinatra::MultiScreen
4
6
 
5
7
  class MultiScreen
6
8
 
@@ -1,17 +1,22 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- backports (3.0.3)
4
+ backports (3.1.0)
5
5
  daemons (1.1.9)
6
- event_emitter (0.2.2)
7
- eventmachine (1.0.0)
6
+ event_emitter (0.2.3)
7
+ eventmachine (1.0.1)
8
8
  foreman (0.61.0)
9
9
  thor (>= 0.13.6)
10
10
  haml (4.0.0)
11
11
  tilt
12
+ httparty (0.10.2)
13
+ multi_json (~> 1.0)
14
+ multi_xml (>= 0.5.2)
12
15
  json (1.7.7)
16
+ multi_json (1.6.1)
17
+ multi_xml (0.5.3)
13
18
  rack (1.5.2)
14
- rack-protection (1.3.2)
19
+ rack-protection (1.4.0)
15
20
  rack
16
21
  rack-test (0.6.2)
17
22
  rack (>= 1.0)
@@ -20,9 +25,10 @@ GEM
20
25
  rack (~> 1.4)
21
26
  rack-protection (~> 1.3)
22
27
  tilt (~> 1.3, >= 1.3.3)
23
- sinatra-cometio (0.1.3)
28
+ sinatra-cometio (0.1.8)
24
29
  event_emitter (>= 0.2.0)
25
30
  eventmachine (>= 1.0.0)
31
+ httparty
26
32
  json (>= 1.7.0)
27
33
  rack
28
34
  sinatra (>= 1.3.3)
@@ -39,7 +45,7 @@ GEM
39
45
  eventmachine (>= 0.12.6)
40
46
  rack (>= 1.0.0)
41
47
  thor (0.17.0)
42
- tilt (1.3.3)
48
+ tilt (1.3.4)
43
49
 
44
50
  PLATFORMS
45
51
  ruby
@@ -9,7 +9,7 @@
9
9
  != yield
10
10
  %hr
11
11
  %div#footer
12
- source code :
12
+ sinatra-multi-screen v#{Sinatra::MultiScreen::VERSION} -
13
13
  - src_url = 'https://github.com/shokai/sinatra-multi-screen'
14
14
  %a{:href => src_url} #{src_url}
15
15
  != yield_content :html_foot
@@ -4,7 +4,7 @@ require 'sinatra-multi-screen/version'
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "sinatra-multi-screen"
7
- gem.version = SinatraMultiScreen::VERSION
7
+ gem.version = Sinatra::MultiScreen::VERSION
8
8
  gem.authors = ["Sho Hashimoto"]
9
9
  gem.email = ["hashimoto@shokai.org"]
10
10
  gem.description = %q{Sinatra Plugin for Multi-Screen Application.}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-multi-screen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-27 00:00:00.000000000 Z
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -80,8 +80,8 @@ files:
80
80
  - Rakefile
81
81
  - lib/js/multiscreen.js
82
82
  - lib/sinatra-multi-screen.rb
83
+ - lib/sinatra-multi-screen/application.rb
83
84
  - lib/sinatra-multi-screen/version.rb
84
- - lib/sinatra/application.rb
85
85
  - lib/sinatra/multi_screen.rb
86
86
  - sample/Gemfile
87
87
  - sample/Gemfile.lock
@@ -1,63 +0,0 @@
1
- module Sinatra
2
-
3
- class Application
4
-
5
- CometIO.on :__multiscreen__data do |data, from|
6
- opts = data["options"]
7
- raise ArgumentError, 'option is empty' if !opts or opts.empty?
8
- raise ArgumentError, 'channel is empty' if opts["channel"].empty?
9
- raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
10
- unless MultiScreen.channels[opts["channel"]][opts["type"]].include? from
11
- raise StandardError, "client <#{from}> is not member of channel <#{opts['channel']}>"
12
- end
13
- MultiScreen.emit data["event"], data["data"], {:session => from, :channel => opts["channel"], :type => opts["type"]}
14
- type = case opts["type"]
15
- when "tv"
16
- "remote"
17
- when "remote"
18
- "tv"
19
- end
20
- MultiScreen.channels[opts["channel"]][type].each do |session_id|
21
- CometIO.push :__multiscreen__data, data, {:to => session_id}
22
- end
23
- end
24
-
25
- CometIO.on :__multiscreen__options do |opts, from|
26
- raise ArgumentError, 'channel is empty' if opts["channel"].empty?
27
- raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
28
- MultiScreen.channels[opts["channel"]][opts["type"]] << from
29
- MultiScreen.emit :connect, {:session => from, :channel => opts["channel"], :type => opts["type"]}
30
- end
31
-
32
- CometIO.on :disconnect do |session_id|
33
- MultiScreen.channels.each do |channel_id, h|
34
- ["tv", "remote"].each do |type|
35
- next unless h[type].include? session_id
36
- h[type].delete session_id
37
- MultiScreen.emit :disconnect, {:session => session_id, :channel => channel_id, :type => type}
38
- end
39
- end
40
- end
41
-
42
- helpers do
43
- def multi_screen_js
44
- "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}/cometio/multiscreen.js"
45
- end
46
- end
47
-
48
- get '/cometio/multiscreen.js' do
49
- content_type 'application/javascript'
50
- @js ||= (
51
- js = ''
52
- Dir.glob(File.expand_path '../js/*.js', File.dirname(__FILE__)).each do |i|
53
- File.open(i) do |f|
54
- js += f.read
55
- end
56
- end
57
- ERB.new(js).result(binding)
58
- )
59
- end
60
-
61
- end
62
-
63
- end