sinatra-multi-screen 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -15,3 +14,5 @@ spec/reports
15
14
  test/tmp
16
15
  test/version_tmp
17
16
  tmp
17
+ *#*
18
+ *~
data/History.txt CHANGED
@@ -1,4 +1,8 @@
1
- === 0.0.1 2013-02-06
1
+ === 0.0.2 2013-02-19
2
+
3
+ * separate channels
4
+
5
+ === 0.0.1 2013-02-16
2
6
 
3
7
  * dispatch UI Event on TV from Remote
4
8
  * push event from TV to Remote
data/README.md CHANGED
@@ -85,6 +85,8 @@ tv.on("change_color", function(data){ // regist "change_color" event
85
85
  Samples
86
86
  -------
87
87
  * https://github.com/shokai/sinatra-multi-screen/tree/master/sample
88
+ * http://multiscreen-youtube.herokuapp.com
89
+ * https://github.com/shokai/multiscreen-youtube-sample
88
90
 
89
91
 
90
92
  Contributing
@@ -5,11 +5,14 @@ var MultiScreen = function(cometio, options){
5
5
  var self = this;
6
6
  this.io = cometio;
7
7
  this.options = options;
8
+ this.io.on("connect", function(session){
9
+ self.io.push("__multiscreen__options", self.options);
10
+ });
8
11
  if(options.type == "remote"){
9
12
  this.tv = {};
10
13
  new EventEmitter().apply(this.tv);
11
14
  this.tv.event = function(selector, event_name, args){
12
- self.io.push("__multiscreen__event", {selector: selector, event: event_name, args: args});
15
+ self.io.push("__multiscreen__event", {selector: selector, event: event_name, args: args, options: self.options});
13
16
  };
14
17
  this.tv.$ = function(selector){
15
18
  return {
@@ -44,7 +47,7 @@ var MultiScreen = function(cometio, options){
44
47
  if(options.type == "tv"){
45
48
  this.remote = {};
46
49
  this.remote.push = function(event_name, args){
47
- self.io.push("__multiscreen__event", {event: event_name, args: args});
50
+ self.io.push("__multiscreen__event", {event: event_name, args: args, options: self.options});
48
51
  };
49
52
  this.io.on("__multiscreen__event", function(data){
50
53
  if(typeof data.selector === 'undefined') return;
@@ -1,7 +1,45 @@
1
+
2
+
1
3
  module Sinatra
2
4
 
3
5
  class Application
4
6
 
7
+ CometIO.on :__multiscreen__event do |data, from|
8
+ opts = data["options"]
9
+ raise ArgumentError, 'option is empty' if !opts or opts.empty?
10
+ raise ArgumentError, 'channel is empty' if opts["channel"].empty?
11
+ raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
12
+ unless MultiScreen.channels[opts["channel"]][opts["type"]].include? from
13
+ raise StandardError, "client <#{from}> is not member of channel <#{opts['channel']}>"
14
+ end
15
+ type = case opts["type"]
16
+ when "tv"
17
+ "remote"
18
+ when "remote"
19
+ "tv"
20
+ end
21
+ MultiScreen.channels[opts["channel"]][type].each do |session_id|
22
+ CometIO.push :__multiscreen__event, data, {:to => session_id}
23
+ end
24
+ end
25
+
26
+ CometIO.on :__multiscreen__options do |opts, from|
27
+ raise ArgumentError, 'channel is empty' if opts["channel"].empty?
28
+ raise ArgumentError, 'type must be "tv" or "remote"' unless ["tv","remote"].include? opts["type"]
29
+ MultiScreen.channels[opts["channel"]][opts["type"]] << from
30
+ MultiScreen.emit :connect, {:session => from, :channel => opts["channel"], :type => opts["type"]}
31
+ end
32
+
33
+ CometIO.on :disconnect do |session_id|
34
+ MultiScreen.channels.each do |channel_id, h|
35
+ ["tv", "remote"].each do |type|
36
+ next unless h[type].include? session_id
37
+ h[type].delete session_id
38
+ MultiScreen.emit :disconnect, {:session => session_id, :channel => channel_id, :type => type}
39
+ end
40
+ end
41
+ end
42
+
5
43
  helpers do
6
44
  def multi_screen_js
7
45
  "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['SCRIPT_NAME']}/cometio/multiscreen.js"
@@ -2,7 +2,17 @@ require File.expand_path '../sinatra-multi-screen', File.dirname(__FILE__)
2
2
  require 'sinatra/cometio'
3
3
  require File.expand_path 'application', File.dirname(__FILE__)
4
4
 
5
+ class MultiScreen
6
+
7
+ def self.channels
8
+ @@channels ||= Hash.new{|h,channel_id|
9
+ h[channel_id] = {
10
+ 'tv' => [],
11
+ 'remote' => []
12
+ }
13
+ }
14
+ end
5
15
 
6
- CometIO.on :__multiscreen__event do |data, from|
7
- CometIO.push :__multiscreen__event, data
8
16
  end
17
+
18
+ EventEmitter.apply MultiScreen
@@ -1,5 +1,3 @@
1
- module Sinatra
2
- module MultiScreen
3
- VERSION = "0.0.1"
4
- end
1
+ module SinatraMultiScreen
2
+ VERSION = "0.0.2"
5
3
  end
@@ -1,6 +1,4 @@
1
1
  require "sinatra-multi-screen/version"
2
2
 
3
- module Sinatra
4
- module MultiScreen
5
- end
3
+ module SinatraMultiScreen
6
4
  end
@@ -0,0 +1,58 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ backports (2.8.2)
5
+ daemons (1.1.9)
6
+ event_emitter (0.2.2)
7
+ eventmachine (1.0.0)
8
+ foreman (0.61.0)
9
+ thor (>= 0.13.6)
10
+ haml (4.0.0)
11
+ tilt
12
+ json (1.7.7)
13
+ rack (1.5.2)
14
+ rack-protection (1.3.2)
15
+ rack
16
+ rack-test (0.6.2)
17
+ rack (>= 1.0)
18
+ sass (3.2.5)
19
+ sinatra (1.3.4)
20
+ rack (~> 1.4)
21
+ rack-protection (~> 1.3)
22
+ tilt (~> 1.3, >= 1.3.3)
23
+ sinatra-cometio (0.1.3)
24
+ event_emitter (>= 0.2.0)
25
+ eventmachine (>= 1.0.0)
26
+ json (>= 1.7.0)
27
+ rack
28
+ sinatra (>= 1.3.3)
29
+ sinatra-contrib (>= 1.3.2)
30
+ sinatra-contrib (1.3.2)
31
+ backports (>= 2.0)
32
+ eventmachine
33
+ rack-protection
34
+ rack-test
35
+ sinatra (~> 1.3.0)
36
+ tilt (~> 1.3)
37
+ thin (1.5.0)
38
+ daemons (>= 1.0.9)
39
+ eventmachine (>= 0.12.6)
40
+ rack (>= 1.0.0)
41
+ thor (0.17.0)
42
+ tilt (1.3.3)
43
+ youtube_search (0.1.7)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ foreman
50
+ haml
51
+ json
52
+ rack
53
+ sass
54
+ sinatra
55
+ sinatra-cometio
56
+ sinatra-contrib
57
+ thin
58
+ youtube_search
data/sample/main.rb CHANGED
@@ -8,8 +8,14 @@ helpers do
8
8
  end
9
9
  end
10
10
 
11
- CometIO.on :connect do |session|
12
- puts "new client <#{session}>"
11
+ MultiScreen.on :connect do |client|
12
+ puts "new client #{client.inspect}"
13
+ p MultiScreen.channels
14
+ end
15
+
16
+ MultiScreen.on :disconnect do |client|
17
+ puts "client disconnect - #{client.inspect}"
18
+ p MultiScreen.channels
13
19
  end
14
20
 
15
21
  before '/*' do
@@ -20,11 +26,13 @@ get '/' do
20
26
  haml :index
21
27
  end
22
28
 
23
- get '/tv' do
29
+ get '/tv/:channel' do
30
+ @channel = params[:channel]
24
31
  haml :tv
25
32
  end
26
33
 
27
- get '/remote' do
34
+ get '/remote/:channel' do
35
+ @channel = params[:channel]
28
36
  haml :remote
29
37
  end
30
38
 
@@ -1,5 +1,5 @@
1
1
  var io = new CometIO().connect();
2
- var screen = new MultiScreen(io, {type: "remote"});
2
+ var screen = new MultiScreen(io, {type: "remote", channel: channel});
3
3
  var tv = screen.tv;
4
4
 
5
5
  io.on("connect", function(session){
@@ -11,8 +11,9 @@ io.on("connect", function(session){
11
11
  tv.$("#btn_search").click();
12
12
  });
13
13
 
14
- $("#text_search").keydown(function(e){
14
+ $("#text_search").keyup(function(e){
15
15
  var word = $("#text_search").val();
16
+ console.log(word);
16
17
  tv.$("#text_search").val(word);
17
18
  });
18
19
 
@@ -1,5 +1,5 @@
1
1
  var io = new CometIO().connect();
2
- var screen = new MultiScreen(io, {type: "tv"});
2
+ var screen = new MultiScreen(io, {type: "tv", channel: channel});
3
3
  var remote = screen.remote;
4
4
 
5
5
  io.on("connect", function(session){
@@ -6,6 +6,6 @@
6
6
  %div#main
7
7
  %ul
8
8
  %li
9
- %a{:href => "#{app_root}/tv"} TV
9
+ %a{:href => "#{app_root}/tv/1"} TV
10
10
  %li
11
- %a{:href => "#{app_root}/remote"} Remote
11
+ %a{:href => "#{app_root}/remote/1"} Remote
@@ -1,5 +1,7 @@
1
1
  - content_for :html_head do
2
2
  %title= @title
3
+ :javascript
4
+ var channel = "#{@channel}";
3
5
 
4
6
  - content_for :html_foot do
5
7
  %script{:src => "#{app_root}/js/jquery.js"}
data/sample/views/tv.haml CHANGED
@@ -2,6 +2,7 @@
2
2
  %title= @title
3
3
  :javascript
4
4
  var search_api = "#{app_root}/search.json";
5
+ var channel = "#{@channel}"
5
6
 
6
7
  - content_for :html_foot do
7
8
  %script{:src => "#{app_root}/js/jquery.js"}
@@ -1,11 +1,10 @@
1
- # -*- encoding: utf-8 -*-
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'sinatra-multi-screen/version'
5
4
 
6
5
  Gem::Specification.new do |gem|
7
6
  gem.name = "sinatra-multi-screen"
8
- gem.version = Sinatra::MultiScreen::VERSION
7
+ gem.version = SinatraMultiScreen::VERSION
9
8
  gem.authors = ["Sho Hashimoto"]
10
9
  gem.email = ["hashimoto@shokai.org"]
11
10
  gem.description = %q{Sinatra Plugin for Multi-Screen Application.}
@@ -17,5 +16,5 @@ Gem::Specification.new do |gem|
17
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
17
  gem.require_paths = ["lib"]
19
18
  gem.add_dependency 'sinatra', '>= 1.3.3'
20
- gem.add_dependency 'sinatra-cometio', '>= 0.1.1'
19
+ gem.add_dependency 'sinatra-cometio', '>= 0.1.3', '< 0.2.0'
21
20
  end
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.1
4
+ version: 0.0.2
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-16 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -34,7 +34,10 @@ dependencies:
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: 0.1.1
37
+ version: 0.1.3
38
+ - - <
39
+ - !ruby/object:Gem::Version
40
+ version: 0.2.0
38
41
  type: :runtime
39
42
  prerelease: false
40
43
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +45,10 @@ dependencies:
42
45
  requirements:
43
46
  - - ! '>='
44
47
  - !ruby/object:Gem::Version
45
- version: 0.1.1
48
+ version: 0.1.3
49
+ - - <
50
+ - !ruby/object:Gem::Version
51
+ version: 0.2.0
46
52
  description: Sinatra Plugin for Multi-Screen Application.
47
53
  email:
48
54
  - hashimoto@shokai.org
@@ -63,6 +69,7 @@ files:
63
69
  - lib/sinatra/multi_screen.rb
64
70
  - sample/.gitignore
65
71
  - sample/Gemfile
72
+ - sample/Gemfile.lock
66
73
  - sample/Procfile
67
74
  - sample/README.md
68
75
  - sample/config.ru