Class: BrowserTestChannel

Inherits:
Object
  • Object
show all
Includes:
EventMachine::Deferrable
Defined in:
lib/browser_test_channel.rb

Defined Under Namespace

Classes: Server

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ BrowserTestChannel

Returns a new instance of BrowserTestChannel.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/browser_test_channel.rb', line 47

def initialize request
  @html_data_type = request.GET['TYPE'] == 'html'
  headers = {'Cache-Control' => 'no-cache'}
  headers['Content-Type'] = @html_data_type ? 'text/html' : 'application/javascript'
  request.env['async.callback'].call [200, headers, self]
  if @html_data_type
    @body_callback.call "<html><body>\n"
    if domain = request.GET['DOMAIN']
      @body_callback.call "<script>try{document.domain=#{domain.dump};}catch(e){}</script>\n"
    end
  end
  call '11111'
  EventMachine.add_timer(2) do
    call '2'
    if @html_data_type
      @body_callback.call "<script>try{parent.d();}catch(e){}</script>\n</body></html>\n"
    end
    succeed
  end
end

Instance Method Details

#call(chunk) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/browser_test_channel.rb', line 72

def call chunk
  if @html_data_type
    @body_callback.call "<script>try{parent.m(#{chunk.dump});}catch(e){}</script>\n"
  else
    @body_callback.call chunk
  end
end

#each(&blk) ⇒ Object



68
69
70
# File 'lib/browser_test_channel.rb', line 68

def each &blk
  @body_callback = blk
end