Class: CPEE::Frames::NewFrameWait

Inherits:
Riddl::Implementation
  • Object
show all
Defined in:
lib/cpee-frames/implementation.rb

Instance Method Summary collapse

Instance Method Details

#headersObject



186
187
188
# File 'lib/cpee-frames/implementation.rb', line 186

def headers
  Riddl::Header.new('CPEE-CALLBACK', 'true')
end

#responseObject



139
140
141
142
143
144
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
# File 'lib/cpee-frames/implementation.rb', line 139

def response
  path = File.join('data',@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 doOverlap(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[7].value != ""
    urls = JSON::parse(@p[7].value);
    if @p[8].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, showbutton: @p[5].value, style: @p[6].value, 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, showbutton: @p[5].value, style: @p[6].value, default: JSON::parse(@p[8].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',@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',@r.last,'callback'),@h['CPEE_CALLBACK'])


    @a[0].send(JSON.dump(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", showbutton: @p[5].value, style: @p[6].value, default: "{}", callback: @h['CPEE_CALLBACK']};

    File.write(File.join('data',@r.last,'callback'),@h['CPEE_CALLBACK'])


    @a[0].send(JSON.dump(hash))

    Typhoeus.put(@h['CPEE_CALLBACK'], body: "No Frame Set")
  end
  nil

end