sinatra-multi-screen 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -1
- data/README.md +20 -0
- data/lib/js/multiscreen.js +4 -4
- data/lib/sinatra-multi-screen/version.rb +1 -1
- data/lib/sinatra/application.rb +1 -0
- data/sample/main.rb +4 -0
- metadata +1 -1
data/History.txt
CHANGED
data/README.md
CHANGED
@@ -92,6 +92,26 @@ remote.on("mode", function(data){
|
|
92
92
|
});
|
93
93
|
```
|
94
94
|
|
95
|
+
|
96
|
+
### Events on Server
|
97
|
+
|
98
|
+
Sinatra Side
|
99
|
+
```ruby
|
100
|
+
MultiScreen.on :connect do |client|
|
101
|
+
puts "new client #{client.inspect}"
|
102
|
+
p MultiScreen.channels
|
103
|
+
end
|
104
|
+
|
105
|
+
MultiScreen.on :disconnect do |client|
|
106
|
+
puts "client disconnect - #{client.inspect}"
|
107
|
+
p MultiScreen.channels
|
108
|
+
end
|
109
|
+
|
110
|
+
MultiScreen.on :ui_event do |data, from|
|
111
|
+
puts "Remote --(dispatch UI Event)--> TV"
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
95
115
|
Samples
|
96
116
|
-------
|
97
117
|
* https://github.com/shokai/sinatra-multi-screen/tree/master/sample
|
data/lib/js/multiscreen.js
CHANGED
@@ -31,8 +31,8 @@ var MultiScreen = function(cometio, options){
|
|
31
31
|
})
|
32
32
|
|
33
33
|
if(options.type == "remote"){
|
34
|
-
this.tv.event = function(selector, event_name,
|
35
|
-
self.tv.push("ui_event", {selector: selector, event: event_name,
|
34
|
+
this.tv.event = function(selector, event_name, arg){
|
35
|
+
self.tv.push("ui_event", {selector: selector, event: event_name, arg: arg});
|
36
36
|
};
|
37
37
|
this.tv.$ = function(selector){
|
38
38
|
return {
|
@@ -65,10 +65,10 @@ var MultiScreen = function(cometio, options){
|
|
65
65
|
self.remote.on("ui_event", function(data){
|
66
66
|
if(typeof data.selector === 'undefined' ||
|
67
67
|
typeof data.event === 'undefined') return;
|
68
|
-
if(typeof data.
|
68
|
+
if(typeof data.arg === 'undefined'){
|
69
69
|
$(data.selector)[data.event]();
|
70
70
|
}else{
|
71
|
-
$(data.selector)[data.event](data.
|
71
|
+
$(data.selector)[data.event](data.arg);
|
72
72
|
}
|
73
73
|
});
|
74
74
|
}
|
data/lib/sinatra/application.rb
CHANGED
@@ -10,6 +10,7 @@ module Sinatra
|
|
10
10
|
unless MultiScreen.channels[opts["channel"]][opts["type"]].include? from
|
11
11
|
raise StandardError, "client <#{from}> is not member of channel <#{opts['channel']}>"
|
12
12
|
end
|
13
|
+
MultiScreen.emit data["event"], data["data"], {:session => from, :channel => opts["channel"], :type => opts["type"]}
|
13
14
|
type = case opts["type"]
|
14
15
|
when "tv"
|
15
16
|
"remote"
|
data/sample/main.rb
CHANGED
@@ -18,6 +18,10 @@ MultiScreen.on :disconnect do |client|
|
|
18
18
|
p MultiScreen.channels
|
19
19
|
end
|
20
20
|
|
21
|
+
MultiScreen.on :ui_event do |data, from|
|
22
|
+
puts "UI Event $('#{data['selector']}').#{data['event']}(#{data['arg']}) -- from #{from.inspect}"
|
23
|
+
end
|
24
|
+
|
21
25
|
before '/*' do
|
22
26
|
@title = app_name
|
23
27
|
end
|