screenxtv 0.0.6 → 0.0.7

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.
Files changed (2) hide show
  1. data/lib/screenxtv.rb +45 -12
  2. metadata +2 -2
data/lib/screenxtv.rb CHANGED
@@ -10,13 +10,25 @@ require 'tempfile'
10
10
 
11
11
  HOST="screenx.tv"
12
12
 
13
-
13
+ def show_info(info)
14
+ broadcasting_url="http://#{HOST}/#{info['url']}"
15
+ private_flag=!!info['private']
16
+ authorized=info['authorized']
17
+ print "Broadcasting URL: \e[1m#{broadcasting_url}\e[m\n"
18
+ print "Chat page : \e[1m#{broadcasting_url}?chat\e[m\n"
19
+ if info['private']
20
+ print "This is a private casting.\n"
21
+ print "The only person who knows the URL can watch this screen.\n"
22
+ elsif !info['authorized']
23
+ print "This URL is not reserved and chat messages will be deleted after broadcasting.\n";
24
+ print "If you want to reserve this URL, please create your account.\n"
25
+ end
26
+ end
14
27
 
15
28
  if ENV['SCREENXTV_BROADCASTING']
16
- print "cannot broadcast inside broadcasting screen\n"
29
+ show_info(JSON.parse ENV['SCREENXTV_BROADCASTING'])
17
30
  exit
18
31
  end
19
- ENV['SCREENXTV_BROADCASTING']='1'
20
32
 
21
33
  Signal.trap(:INT){exit;}
22
34
 
@@ -30,7 +42,7 @@ def readpswd(prompt='> ')
30
42
  STDIN.raw{
31
43
  s=""
32
44
  loop do
33
- c=STDIN.getc
45
+ c=STDIN.getch
34
46
  case c
35
47
  when "\x03"
36
48
  print "\r\n"
@@ -108,6 +120,7 @@ conf_scan=[
108
120
  errmsg:'You can use only alphabets, numbers and underscore.'
109
121
  },
110
122
  {key:"screen",value:"screenxtv"},
123
+ {key:"screen_private",value:"screenxtv_private"},
111
124
  {
112
125
  key:"color",msg:"Terminal Color [BLACK/white/green/novel]",
113
126
  value:'black',
@@ -123,6 +136,7 @@ parser=OptionParser.new do |op|
123
136
  op.on("-c [color]"){|v|argv[:color]=v||true}
124
137
  op.on("-t [title]"){|v|argv[:title]=v||true}
125
138
  op.on("-reset"){|v|argv[:new]=true}
139
+ op.on("-private"){|v|argv[:private]=true}
126
140
  op.on("-f config_file"){|v|argv[:file]=v}
127
141
  end
128
142
  parser.parse(ARGV)
@@ -142,8 +156,11 @@ else
142
156
  conf['color']=argv[:color]==true ? nil : argv[:color] if argv[:color]
143
157
  end
144
158
 
159
+ conf_scan.delete :url if argv[:private]
160
+
145
161
  conf_scan.each do |item|
146
162
  key=item[:key]
163
+ next if key=='url'&&argv[:private]
147
164
  msg=item[:msg]
148
165
  value=item[:value]
149
166
  if !conf[key] then
@@ -157,26 +174,35 @@ conf_scan.each do |item|
157
174
  end
158
175
  end
159
176
  end
160
- conf['url'].gsub! /[^_a-zA-Z0-9]/,""
177
+ conf['url'].gsub! /[^_a-zA-Z0-9]/,"" if conf['url']
161
178
  conf['color'].downcase!
162
179
  File.write conf_file,conf.to_yaml
163
180
 
164
181
  print "connecting...\n"
165
182
  socket=nil
183
+ url=''
166
184
  loop do
167
185
  File.write conf_file,conf.to_yaml
168
186
  socket=kvconnect HOST,8000
169
187
  height,width=STDOUT.winsize
170
188
  initdata={
171
- width:width,height:height,slug:conf['url']+'#'+(conf['urlhash']||''),
189
+ width:width,height:height,slug:(conf['url']||'')+'#'+(conf['urlhash']||''),
172
190
  user:conf['user'],
173
191
  auth_key:conf['auth_key'],
192
+ private:argv[:private],
193
+ private_url:conf['private_url'],
174
194
  info:{color:conf['color'],title:conf['title']}
175
195
  }
176
196
  socket.send('init',initdata.to_json)
177
197
  key,value=socket.recv
178
- if key=='slug'
198
+ case key
199
+ when 'slug'
179
200
  conf['url'],conf['urlhash']=value.split("#")
201
+ url=conf['url']
202
+ break
203
+ when 'private_url'
204
+ conf['private_url']=value;
205
+ url='private/'+value.split("#")[0]
180
206
  break
181
207
  end
182
208
  socket.close
@@ -193,9 +219,15 @@ loop do
193
219
  end
194
220
 
195
221
  File.write conf_file,conf.to_yaml
222
+ info={
223
+ 'url'=>url,
224
+ 'authorized'=>conf['urlhash']==url+"/"+conf['auth_key'],
225
+ 'private'=>argv[:private]
226
+ }
227
+ ENV['SCREENXTV_BROADCASTING']=info.to_json
228
+ show_info(info)
196
229
 
197
- print "Your url is http://#{HOST}/"+conf['url'].split("#")[0]+"\n\n";
198
- print "Press Enter to start broadcasting\n"
230
+ print "\npress enter to start broadcasting"
199
231
  readline
200
232
 
201
233
  screenrc=Tempfile.new("screenrc");
@@ -206,11 +238,11 @@ begin
206
238
  }
207
239
  rescue
208
240
  end
209
- screenrc.write "hardstatus alwayslastline 'http://#{HOST}/#{conf['url']}'\n"
241
+ screenrc.write "hardstatus alwayslastline 'http://#{HOST}/#{url}'\n"
210
242
  screenrc.flush
211
243
  rescue
212
244
  end
213
- p ENV['SCREENRC']=screenrc.path
245
+ ENV['SCREENRC']=screenrc.path
214
246
 
215
247
  Thread.new{
216
248
  begin
@@ -227,7 +259,8 @@ begin
227
259
  ENV['TERM']='vt100'
228
260
  ENV['LANG']='en_US.UTF-8'
229
261
  master.winsize=STDOUT.winsize
230
- rr,ww,pid = PTY::getpty("screen -x #{conf['screen']} -R",in:slave,out:master)
262
+ screen_name=argv[:private] ? conf['screen_private'] : conf['screen']
263
+ rr,ww,pid = PTY::getpty("screen -x #{screen_name} -R",in:slave,out:master)
231
264
  winsize=->{
232
265
  height,width=master.winsize=rr.winsize=STDOUT.winsize
233
266
  socket.send 'winch',{width:width,height:height}.to_json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screenxtv
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-01-05 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json