screenxtv 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/screenxtv.rb +66 -10
  2. metadata +2 -18
data/lib/screenxtv.rb CHANGED
@@ -8,7 +8,7 @@ require 'optparse'
8
8
  require 'readline'
9
9
  require 'tempfile'
10
10
 
11
-
11
+ HOST="screenx.tv"
12
12
 
13
13
 
14
14
 
@@ -20,11 +20,40 @@ ENV['SCREENXTV_BROADCASTING']='1'
20
20
 
21
21
  Signal.trap(:INT){exit;}
22
22
 
23
- def readline
24
- s=Readline.readline("> ",true)
23
+ def readline(prompt="> ")
24
+ s=Readline.readline(prompt,true)
25
25
  if !s then exit end
26
26
  s.strip
27
27
  end
28
+ def readpswd(prompt='> ')
29
+ print prompt
30
+ STDIN.raw{
31
+ s=""
32
+ loop do
33
+ c=STDIN.getc
34
+ case c
35
+ when "\x03"
36
+ print "\r\n"
37
+ return nil
38
+ when "\r","\n"
39
+ print "\r\n"
40
+ return s
41
+ when "\x7f"
42
+ if s.length>0
43
+ s=s.slice 0,s.length-1
44
+ else
45
+ print "\a"
46
+ end
47
+ when 'a'..'z','A'..'Z','0'..'9','_'
48
+ s+=c
49
+ else
50
+ print "\a"
51
+ end
52
+ print "\r\e[K#{prompt}#{s.gsub /./,'*'}"
53
+ end
54
+ }
55
+ end
56
+
28
57
 
29
58
  def kvconnect(host,port)
30
59
  socket=TCPSocket.open host, port
@@ -52,11 +81,28 @@ def stop msg
52
81
  exit
53
82
  end
54
83
 
84
+ def auth(conf)
85
+ loop do
86
+ username=readline "user name> "
87
+ return false if username.size==0
88
+ password=readpswd "password> "
89
+ return false if password.nil? || password.size==0
90
+
91
+ socket=kvconnect HOST,8000
92
+ socket.send('init',{user:username,password:password}.to_json)
93
+ key,value=socket.recv
94
+ if key=='auth'
95
+ conf['user']=username
96
+ conf['auth_key']=value
97
+ return true
98
+ end
99
+ end
100
+ end
55
101
 
56
102
  conf_scan=[
57
103
  {
58
104
  key:"url",
59
- msg:"Create a new URL. If given \"foo\", your URL will be \"http://screenx.tv/foo\".",
105
+ msg:"Create a new URL. If given \"foo\", your URL will be \"http://#{HOST}/foo\".",
60
106
  value:"",
61
107
  match:/^[_a-zA-Z0-9]*$/,
62
108
  errmsg:'You can use only alphabets, numbers and underscore.'
@@ -119,10 +165,12 @@ print "connecting...\n"
119
165
  socket=nil
120
166
  loop do
121
167
  File.write conf_file,conf.to_yaml
122
- socket=kvconnect "screenx.tv",8000
168
+ socket=kvconnect HOST,8000
123
169
  height,width=STDOUT.winsize
124
170
  initdata={
125
171
  width:width,height:height,slug:conf['url']+'#'+(conf['urlhash']||''),
172
+ user:conf['user'],
173
+ auth_key:conf['auth_key'],
126
174
  info:{color:conf['color'],title:conf['title']}
127
175
  }
128
176
  socket.send('init',initdata.to_json)
@@ -131,13 +179,22 @@ loop do
131
179
  conf['url'],conf['urlhash']=value.split("#")
132
180
  break
133
181
  end
134
- print "Specified url '"+conf['url']+"' is alerady in use. Please set another url.\n"
135
- conf['url']=readline
182
+ socket.close
183
+ if value.match /reserved|auth_key/
184
+ print "The url '"+conf['url']+"' is reserved. Please sign in.\n"
185
+ if !auth(conf)
186
+ print "Please set another url.\n"
187
+ conf['url']=readline
188
+ end
189
+ else
190
+ print "Specified url '"+conf['url']+"' is alerady in use. Please set another url.\n"
191
+ conf['url']=readline
192
+ end
136
193
  end
137
194
 
138
195
  File.write conf_file,conf.to_yaml
139
196
 
140
- print "Your url is http://screenx.tv/"+conf['url'].split("#")[0]+"\n\n";
197
+ print "Your url is http://#{HOST}/"+conf['url'].split("#")[0]+"\n\n";
141
198
  print "Press Enter to start broadcasting\n"
142
199
  readline
143
200
 
@@ -149,7 +206,7 @@ begin
149
206
  }
150
207
  rescue
151
208
  end
152
- screenrc.write "hardstatus alwayslastline 'http://screenx.tv/#{conf['url']}'\n"
209
+ screenrc.write "hardstatus alwayslastline 'http://#{HOST}/#{conf['url']}'\n"
153
210
  screenrc.flush
154
211
  rescue
155
212
  end
@@ -200,4 +257,3 @@ begin
200
257
  rescue
201
258
  end
202
259
  stop "broadcast end"
203
-
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.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,24 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-17 00:00:00.000000000 Z
12
+ date: 2013-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: io-console
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
14
  - !ruby/object:Gem::Dependency
31
15
  name: json
32
16
  requirement: !ruby/object:Gem::Requirement