screenxtv 0.0.0

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 (3) hide show
  1. data/bin/screenxtv +2 -0
  2. data/lib/screenxtv.rb +161 -0
  3. metadata +47 -0
data/bin/screenxtv ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require 'screenxtv'
data/lib/screenxtv.rb ADDED
@@ -0,0 +1,161 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'pty'
3
+ require 'io/console'
4
+ require 'socket'
5
+ require 'json'
6
+ require 'yaml'
7
+
8
+ def kvconnect(host,port)
9
+ socket=TCPSocket.open host, port
10
+ @@mutex=Mutex.new
11
+ def socket.send(key,value)
12
+ @@mutex.synchronize{
13
+ keylen=key.bytesize
14
+ vallen=value.bytesize
15
+ self.write keylen.chr
16
+ self.write key
17
+ self.write (vallen>>8).chr+(vallen&0xff).chr
18
+ self.write value
19
+ }
20
+ end
21
+ def socket.lockhoge
22
+ sleep 1
23
+ end
24
+ def socket.recv
25
+ [self.readline.chop,JSON.parse("["+self.readline+"]")[0]]
26
+ end
27
+ socket
28
+ end
29
+
30
+ def start
31
+ @sttyoption=`stty -g`
32
+ end
33
+ def stop msg
34
+ height,width=STDOUT.winsize
35
+ print "\e[?1l\e[>\e[1;#{height}r\e[#{height};1H"
36
+ system "stty "+@sttyoption
37
+ print msg+"\n"
38
+ exit
39
+ end
40
+
41
+
42
+ conf_scan=[
43
+ {
44
+ key:"url",
45
+ msg:"Create a new URL. If given \"foo\", your URL will be \"http://screenx.tv/foo\".",
46
+ value:"",
47
+ match:/^[a-zA-Z0-9]*$/,
48
+ errmsg:'You can use only alphabets, numbers and underscore.'
49
+ },
50
+ {key:"screen",value:"screenxtv"},
51
+ {
52
+ key:"color",msg:"Terminal Color [BLACK/white/green/novel]",
53
+ value:'black',
54
+ option:['black','white','green','novel'],
55
+ errmsg:'unknown color.'
56
+ },
57
+ {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
+ ]
65
+
66
+ conf_file=ARGV[0]||"screenxtv.yml"
67
+
68
+ conf={}
69
+ begin
70
+ conf=YAML.load_file conf_file
71
+ rescue
72
+ end
73
+
74
+ conf_scan.each do |item|
75
+ key=item[:key]
76
+ msg=item[:msg]
77
+ value=item[:value]
78
+ if !conf[key] then
79
+ if msg then
80
+ print item[:msg]+"\n> "
81
+ s=STDIN.readline.strip
82
+ if s=="" then s=value end
83
+ conf[key]=s
84
+ else
85
+ conf[key]=value
86
+ end
87
+ end
88
+ end
89
+ conf['url'].gsub! /[^a-z^A-Z^0-9^_^#]/,""
90
+ conf['color'].downcase!
91
+ #conf['private'].downcase!
92
+ File.write conf_file,conf.to_yaml
93
+
94
+ 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
105
+ loop do
106
+ key,value=socket.recv
107
+ if key=='error'
108
+ print 'An error occured: '+value
109
+ exit
110
+ end
111
+ if key=='slug'
112
+ url=value
113
+ break
114
+ end
115
+ end
116
+
117
+ conf['url']=url
118
+ File.write conf_file,conf.to_yaml
119
+
120
+ print "your url is http://screenx.tv/"+url.split("#")[0]+"\n\n";
121
+ print "Press Enter to start broadcasting\n> "
122
+ STDIN.readline
123
+ start
124
+ Thread.new{
125
+ begin
126
+ loop do
127
+ key,value=socket.recv
128
+ end
129
+ rescue
130
+ end
131
+ stop "connection closed"
132
+ }
133
+
134
+ begin
135
+ system "stty raw"
136
+ master,slave=PTY.open
137
+ ENV['TERM']='vt100'
138
+ ENV['LANG']='en_US.UTF-8'
139
+ master.winsize=STDOUT.winsize
140
+ rr,ww,pid = PTY::getpty("screen -x hoge -R",in:slave,out:master)
141
+ winsize=->{
142
+ height,width=master.winsize=rr.winsize=STDOUT.winsize
143
+ socket.send 'winch',{width:width,height:height}.to_json
144
+ }
145
+ winsize.call
146
+ Signal.trap("SIGWINCH"){Thread.new{winsize.call}}
147
+ Signal.trap("SIGCHLD"){stop "broadcast end"}
148
+ Thread.new{
149
+ loop do
150
+ master.write STDIN.getc
151
+ end
152
+ }
153
+ while(data=master.readpartial 1024)
154
+ print data
155
+ socket.send 'data',data
156
+ end
157
+ rescue
158
+ end
159
+ stop "broadcast end"
160
+
161
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: screenxtv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tomoya Ishida
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-05 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A software for broadcasting your terminal to http://screenx.tv/
15
+ email: tomoyapenguin@gmail.com
16
+ executables:
17
+ - screenxtv
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/screenxtv.rb
22
+ - bin/screenxtv
23
+ homepage: http://screenx.tv/
24
+ licenses: []
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 1.8.24
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: ScreenX TV client
47
+ test_files: []