Sha256: 99920addade2451fdb56fecb11e05e035f9a88957ed7839ff78dadc4332859fe

Contents?: true

Size: 941 Bytes

Versions: 37

Compression:

Stored size: 941 Bytes

Contents

class ChatComponent < Roda::Component
  comp_name :chat
  comp_html "../public/chat/index.html"

  def display
    return unless server?

    request.redirect 'login' unless current_user

    dom.find('.my-account .name span').html current_user.full_name

    component(:layout).display do
      dom.find('body').html
    end
  end

  on :server do
    def get_user_list

    end
  end

  on :reconnect do
    puts 'reconnected'
  end

  on :disconnect do
    puts 'disconnected'
  end

  on :connect do
    puts 'connected'
  end

  on :join do |data|
    if client?
      `console.log(#{data});`
      puts 'joined'
    else
      user_details
    end
  end

  on :leave do |data|
    if client?
      `console.log(#{data});`
      puts 'leave'
    else
      user_details
    end
  end

  def user_details
    {
      id: current_user.id,
      first_name: current_user.first_name,
      last_name: current_user.last_name
    }
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
roda-component-0.1.53 test/dummy/components/chat.rb
roda-component-0.1.52 test/dummy/components/chat.rb
roda-component-0.1.51 test/dummy/components/chat.rb
roda-component-0.1.50 test/dummy/components/chat.rb
roda-component-0.1.49 test/dummy/components/chat.rb
roda-component-0.1.48 test/dummy/components/chat.rb
roda-component-0.1.47 test/dummy/components/chat.rb
roda-component-0.1.46 test/dummy/components/chat.rb
roda-component-0.1.45 test/dummy/components/chat.rb
roda-component-0.1.44 test/dummy/components/chat.rb
roda-component-0.1.43 test/dummy/components/chat.rb
roda-component-0.1.42 test/dummy/components/chat.rb
roda-component-0.1.41 test/dummy/components/chat.rb
roda-component-0.1.40 test/dummy/components/chat.rb
roda-component-0.1.39 test/dummy/components/chat.rb
roda-component-0.1.38 test/dummy/components/chat.rb
roda-component-0.1.37 test/dummy/components/chat.rb