Cramp websockets
Upcoming SlideShare
Loading in...5
×
 

Cramp websockets

on

  • 1,855 views

Slides da palestra ocorrida no dia 29/06 sobre CRAMP e WebSockets

Slides da palestra ocorrida no dia 29/06 sobre CRAMP e WebSockets

Statistics

Views

Total Views
1,855
Views on SlideShare
1,854
Embed Views
1

Actions

Likes
0
Downloads
7
Comments
0

1 Embed 1

http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Cramp websockets Cramp websockets Presentation Transcript

  • Encheção de linguiça :D @dev_ton
  • Olá! @dev_ton
  • eu Antônio Roberto ( ton ) e você @dev_ton
  • 2009 @dev_ton
  • @dev_ton
  • Leroy eu @dev_ton
  • @dev_ton
  • @dev_ton
  • apoio @dev_ton
  • Introdução ao CRAMP e WebSockets apoio @dev_ton
  • CRAMP @dev_ton
  • CRAMP - O que é? - Quando usar? @dev_ton
  • CRAMP Controller & Model @dev_ton
  • CRAMP Cramp::Controller Os 4 estágios após uma requisição: Initialization Response Initialization Starting Finishing @dev_ton
  • CRAMP Cramp::Controller Helpers: on_start before_start on_finish periodic_timer keep_connection_alive respond_with request_limit_exceeded @dev_ton
  • CRAMP Cramp::Controller on_start class Hello < Cramp::Controller::Action   on_start :say_hello   def say_hello     render "Hello World! :)"     finish   end end @dev_ton
  • CRAMP Cramp::Controller before_start before_start :valid_param def valid_user   if param[:id] =~ /[^a-zA-Z](.*)/     yield   else     halt 500, {'Content-Type' => 'text/plain'}, "Invalid ID"   end end @dev_ton
  • CRAMP Cramp::Controller on_finish class PollUserAction < Cramp::Controller::Action   on_start :start_polling   on_finish :stop_polling   def start_polling     # Call find_user every 10 seconds     @timer = EventMachine::PeriodicTimer.new(2) { find_user }   end   def find_user     User.first {|u| render "#{u.inspect}n" }   end   def stop_polling     puts "Cancelling the timer.."     @timer.cancel   end end @dev_ton
  • CRAMP Cramp::Controller periodic_timer class PollUserAction < Cramp::Controller::Action periodic_timer :poll_user, :every => 2 def poll_user User.first {|u| render "#{u.inspect}n" } end end @dev_ton
  • CRAMP Cramp::Controller keep_connection_alive class PollUserAction < Cramp::Controller::Action   periodic_timer :poll_user, :every => 2   keep_connection_alive, :every => 30 end @dev_ton
  • CRAMP Cramp::Controller respond_with def respond_with   content_type = params[:format] == 'xml' ? 'application/xml' : 'application/json'   [200, {'Content-Type' => content_type}] end @dev_ton
  • CRAMP Cramp::Controller request_limit_exceeded class PollUserAction < Cramp::Controller::Action   periodic_timer :poll_user, :every => 2   periodic_timer :check_limit_exceed, :every => 10   def poll_user     ..   end   def check_limit_exceed     finish if request_limit_exceeded   end end @dev_ton
  • CRAMP Cramp::Model @dev_ton
  • CRAMP Cramp::Model :( @dev_ton
  • CRAMP Cramp::Model Cramp::Model.init(:username => 'root', :database => 'cramp_development') class User < Cramp::Model::Base attribute :id, :type => Integer, :primary_key => true attribute :name validates_presence_of :name end @dev_ton
  • CRAMP Cramp::Model EM.run do User.select(:id, :name).limit(10).offset(20).first {|u| .. } User.where(User[:name].eq('Lush')).limit(2).all {|users| ... } User.each {|user| .. } def lush_users_found(users) ... end User.where(User[:name].eq('Lush'), User[:id].gt(5)).all method(:lush_users_found) end @dev_ton
  • CRAMP Cramp::Model EM.run do def user_saved(status) if status.success? ... else user = status.record puts "Oops. Found errors : #{status.record.errors.inspect}" end end user = User.new user.save method(:user_saved) end @dev_ton
  • WebSocket @dev_ton
  • WebSocket A mágica! @dev_ton
  • WebSocket 4 passos var location = 'http://localhost:8080/backend'; var socket = new WebSocket(location); socket.onopen = function(data) { ... }; socket.onmessage = function(data) {... }; socket.onclose = function(data) { ... }; socket.send(data); https://gist.github.com/98c8448ba054b7992aff#file_example.js @dev_ton
  • WebSocket & CRAMP @dev_ton
  • WebSocket & CRAMP Cramp::Controller::Websocket Cramp::Controller::Websocket.backend = :thin on_data @dev_ton
  • WebSocket & CRAMP on_data Cramp::Controller::Websocket.backend = :thin class WelcomeController < Cramp::Controller::Websocket   on_data :received_data   def received_data(data)     render "Got your #{data}"   end end https://gist.github.com/d04affd72e2ea57039eb @dev_ton
  • Ajax & WebSockets @dev_ton
  • DEMO :D @dev_ton
  • Obrigado! :) email: forevertonny@gmail.com twitter: @dev_ton
  • links Indrodução ao CRAMP & WebSockets ( patrik ) http://m.onkey.org/2010/1/7/introducing-cramp http://m.onkey.org/2010/1/15/websockets-made-easy-with-cramp WebSockets API http://dev.w3.org/html5/websockets/ Video ( pubsubhubbub ) http://www.youtube.com/watch?v=B5kHx0rGkec App Apresentação http://github.com/devton/socketchat @dev_ton
  • Obrigado! @dev_ton