Class: CPEE::Frames::NewFrameWait
- Inherits:
-
Riddl::Implementation
- Object
- Riddl::Implementation
- CPEE::Frames::NewFrameWait
- Defined in:
- lib/cpee-frames/implementation.rb
Overview
}}}
Instance Method Summary collapse
- #headers ⇒ Object
-
#response ⇒ Object
{{{NewFrameWait.
Instance Method Details
#headers ⇒ Object
191 192 193 |
# File 'lib/cpee-frames/implementation.rb', line 191 def headers Riddl::Header.new('CPEE-CALLBACK', 'true') end |
#response ⇒ Object
{{{NewFrameWait
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cpee-frames/implementation.rb', line 145 def response data_dir = @a[1] path = File.join(data_dir,@r.last,'frames.json') file = File.read(path) data_hash = JSON::parse(file) # check if new frame overlaps others if it does, delete overlapped frames data_hash["data"].each do | c | if CPEE::Frames::overlap?(c['lx'], c['ly'], c['rx'], c['ry'], @p[1].value.to_i, @p[2].value.to_i, (@p[1].value.to_i + @p[3].value.to_i - 1), (@p[2].value.to_i + @p[4].value.to_i - 1)) data_hash["data"].delete(c) end end # check if url is set if @p[5].value != "" urls = JSON::parse(@p[5].value); if @p[6].value == "" hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, default: "{}", callback: @h['CPEE_CALLBACK']}; else hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: urls, default: JSON::parse(@p[6].value), callback: @h['CPEE_CALLBACK']}; end data_hash['data'].push(hash) File.write(path, JSON.dump(data_hash)) # only send active url to client infofile = File.join(data_dir,@r.last,'info.json') infojson = JSON::parse(File.read(infofile)) hash["url"] = urls.find{ |h| h['lang'] == infojson["lang"]}['url'] File.write(File.join(data_dir,@r.last,'callback'),@h['CPEE_CALLBACK']) @a[0].send(JSON.dump({ message: 'display', content: hash })) else File.write(path, JSON.dump(data_hash)) hash = {lx: @p[1].value.to_i, ly: @p[2].value.to_i, rx: (@p[1].value.to_i + @p[3].value.to_i - 1), ry: (@p[2].value.to_i + @p[4].value.to_i - 1), url: "empty", default: "{}", callback: @h['CPEE_CALLBACK']}; File.write(File.join(data_dir,@r.last,'callback'),@h['CPEE_CALLBACK']) @a[0].send(JSON.dump({ message: 'display', content: hash })) Typhoeus.put(@h['CPEE_CALLBACK'], body: "No Frame Set") end nil end |