aplicações web realtime
Post on 12-Apr-2017
250 Views
Preview:
TRANSCRIPT
Alessandro Dias
@adbatista
alessandrodbatista@gmail.com
Fabio L Janiszevski
@fabiosammy
fabiosammy@gmail.com
fabio@pontogestor.com
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.
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
HTTP 2.0 O WebSocket vai estar dentro da camada de conexão HTTP,
sem precisar criar uma nova conexão.
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
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
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'
});
top related