21
Aplicações WEB - Realtime E falaram que AJAX era uma revolução.

Aplicações web realtime

Embed Size (px)

Citation preview

Aplicações WEB - RealtimeE falaram que AJAX era uma revolução.

O que éThe real-time web is a set of technologies and pratices that

enable users to receive information as soon as it is published by

its authors, rather than requiring that they or their software

check a source periodicaly for updates.

O que fazer● Chat

● Feeds

● Chamadas API

● Modo Colaborativo

Abordagens durante o tempo● Abordagem da netscape

○ Content type: multipart/x-mixed-replace; boundary=separator

● IE e o Iframe

○ Connection: keep-alive

● AJAX Pooling e LongPooling

○ setInterval({ url: ‘/collection’, success: function(data){

//DoIT

}}, 5000);

● JavaApplet

● FlashSocket

● WebSocket

Basicamente como tudo funciona - PUB SUB

Soluções

HTTP 2.0 O WebSocket vai estar dentro da camada de conexão HTTP,

sem precisar criar uma nova conexão.

Vagrant neles!

Criando o projetorails > laravel

vagrant up

vagrant ssh

rails new /var/vagrant/

cd /var/vagrant/

echo “gem ‘therubyracer’, platforms: :

ruby” >> Gemfile

git add .

git commit -m ‘rails > laravel’

rails s -b 0.0.0.0

Experimentando AJAXVer a diferença só melhora o objetivo

CRUDE você levando 1h para criar uma

tela de cadastro ai...

cd /var/vagrant

rails g scaffold Person name:string

birthday:date age:integer

rake db:migrate

git add .

git commit -m ‘rails generate is

awesome!’

GET http://localhost:3000/persons

ops!

GET http://localhost:3000/people

SYNC, FAYE e RailsSopa!

Dependênciasah essas gemas preciosas!

echo “gem ‘faye’, ‘~> 1.1.1” >> Gemfile

echo “gem ‘sync’, ‘~> 0.3.5” >>

Gemfile

echo “gem ‘thin’, ‘~> 1.5.1” >> Gemfile

bundle install

rails g sync:install

git commit -m ‘Sync is awesome!’

Rodando o servidor

Aquele que vai enviar as

notificações

vagrant ssh

cd /var/vagrant

# Added require sync in application.js

# Added Sync tag in application.html

rackup sync.ru -E prodution --host

0.0.0.0

Verificando o FayeAntes de testar, verifica se não deu

problema!

GET http://localhost:9292/faye/faye.js

# Connect channel (client)

var client = new Faye.Client('http://localhost:9292/faye');

client.subscribe('/messages', function(message) {

alert('Got a message: ' + message.text);

});

# Send message

client.publish('/messages', {

text: 'Hello world'

});

Realtime finalmente :3E ainda falaram que iframe era muito legal...

Onde aprender mais?