screenxtv 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/lib/screenxtv.rb +35 -31
- metadata +1 -1
data/lib/screenxtv.rb
CHANGED
@@ -4,6 +4,7 @@ require 'io/console'
|
|
4
4
|
require 'socket'
|
5
5
|
require 'json'
|
6
6
|
require 'yaml'
|
7
|
+
require 'optparse'
|
7
8
|
|
8
9
|
def kvconnect(host,port)
|
9
10
|
socket=TCPSocket.open host, port
|
@@ -18,9 +19,6 @@ def kvconnect(host,port)
|
|
18
19
|
self.write value
|
19
20
|
}
|
20
21
|
end
|
21
|
-
def socket.lockhoge
|
22
|
-
sleep 1
|
23
|
-
end
|
24
22
|
def socket.recv
|
25
23
|
[self.readline.chop,JSON.parse("["+self.readline+"]")[0]]
|
26
24
|
end
|
@@ -55,22 +53,33 @@ conf_scan=[
|
|
55
53
|
errmsg:'unknown color.'
|
56
54
|
},
|
57
55
|
{key:"title",msg:"Title",value:"no title"},
|
58
|
-
# {
|
59
|
-
# key:"private",msg:"Would you like to make it private? [NO/yes]",
|
60
|
-
# value:'no',
|
61
|
-
# option:['no','yes'],
|
62
|
-
# errmsg:'please answer yes or no'
|
63
|
-
# },
|
64
56
|
]
|
65
57
|
|
66
|
-
|
58
|
+
argv={}
|
59
|
+
parser=OptionParser.new do |op|
|
60
|
+
op.on("-u [url]"){|v|argv[:url]=v||true}
|
61
|
+
op.on("-c [color]"){|v|argv[:color]=v||true}
|
62
|
+
op.on("-t [title]"){|v|argv[:title]=v||true}
|
63
|
+
op.on("-reset"){|v|argv[:new]=true}
|
64
|
+
op.on("-f config_file"){|v|argv[:file]=v}
|
65
|
+
end
|
66
|
+
parser.parse(ARGV)
|
67
67
|
|
68
|
+
conf_file=argv[:file] || "#{ENV['HOME']}/.screenxtv.yml"
|
68
69
|
conf={}
|
69
70
|
begin
|
70
71
|
conf=YAML.load_file conf_file
|
71
72
|
rescue
|
72
73
|
end
|
73
74
|
|
75
|
+
if argv[:new]
|
76
|
+
conf={}
|
77
|
+
else
|
78
|
+
conf['url']=argv[:url]==true ? nil : argv[:url] if argv[:url]
|
79
|
+
conf['title']=argv[:title]==true ? nil : argv[:title] if argv[:title]
|
80
|
+
conf['color']=argv[:color]==true ? nil : argv[:color] if argv[:color]
|
81
|
+
end
|
82
|
+
|
74
83
|
conf_scan.each do |item|
|
75
84
|
key=item[:key]
|
76
85
|
msg=item[:msg]
|
@@ -86,40 +95,36 @@ conf_scan.each do |item|
|
|
86
95
|
end
|
87
96
|
end
|
88
97
|
end
|
89
|
-
conf['url'].gsub! /[^a-z^A-Z^0-9
|
98
|
+
conf['url'].gsub! /[^a-z^A-Z^0-9]/,""
|
90
99
|
conf['color'].downcase!
|
91
|
-
#conf['private'].downcase!
|
92
100
|
File.write conf_file,conf.to_yaml
|
93
101
|
|
94
102
|
print "connecting...\n"
|
95
|
-
|
96
|
-
socket=kvconnect "screenx.tv",8000
|
97
|
-
height,width=STDOUT.winsize
|
98
|
-
initdata={
|
99
|
-
width:width,height:height,slug:conf['url'],
|
100
|
-
info:{color:conf['color'],title:conf['title']}
|
101
|
-
}
|
102
|
-
#if(conf['private']=='yes')then initdata[:info][:private]='yes' end
|
103
|
-
socket.send('init',initdata.to_json)
|
104
|
-
url=nil
|
103
|
+
socket=nil
|
105
104
|
loop do
|
105
|
+
File.write conf_file,conf.to_yaml
|
106
|
+
socket=kvconnect "screenx.tv",8000
|
107
|
+
height,width=STDOUT.winsize
|
108
|
+
initdata={
|
109
|
+
width:width,height:height,slug:conf['url']+'#'+(conf['urlhash']||''),
|
110
|
+
info:{color:conf['color'],title:conf['title']}
|
111
|
+
}
|
112
|
+
socket.send('init',initdata.to_json)
|
106
113
|
key,value=socket.recv
|
107
|
-
if key=='error'
|
108
|
-
print 'An error occured: '+value
|
109
|
-
exit
|
110
|
-
end
|
111
114
|
if key=='slug'
|
112
|
-
url=value
|
115
|
+
conf['url'],conf['urlhash']=value.split("#")
|
113
116
|
break
|
114
117
|
end
|
118
|
+
print "Specified url '"+conf['url']+"' is alerady in use. Please set another url.\n> "
|
119
|
+
conf['url']=STDIN.readline.strip
|
115
120
|
end
|
116
121
|
|
117
|
-
conf['url']=url
|
118
122
|
File.write conf_file,conf.to_yaml
|
119
123
|
|
120
|
-
print "
|
124
|
+
print "Your url is http://screenx.tv/"+conf['url'].split("#")[0]+"\n\n";
|
121
125
|
print "Press Enter to start broadcasting\n> "
|
122
126
|
STDIN.readline
|
127
|
+
|
123
128
|
start
|
124
129
|
Thread.new{
|
125
130
|
begin
|
@@ -137,7 +142,7 @@ begin
|
|
137
142
|
ENV['TERM']='vt100'
|
138
143
|
ENV['LANG']='en_US.UTF-8'
|
139
144
|
master.winsize=STDOUT.winsize
|
140
|
-
rr,ww,pid = PTY::getpty("screen -x
|
145
|
+
rr,ww,pid = PTY::getpty("screen -x #{conf['screen']} -R",in:slave,out:master)
|
141
146
|
winsize=->{
|
142
147
|
height,width=master.winsize=rr.winsize=STDOUT.winsize
|
143
148
|
socket.send 'winch',{width:width,height:height}.to_json
|
@@ -158,4 +163,3 @@ rescue
|
|
158
163
|
end
|
159
164
|
stop "broadcast end"
|
160
165
|
|
161
|
-
|