Enables a web browser to receive push-like notifications from a server • New EventSource Javascript API • Implemented in Web XMS - web.xms.me Server ... what?
Resource Sharing (CORS) • http://an.example.com can directly connect to http://other.example.org • Destination server must add some response headers: Access-Control-Allow-Origin: http://an.example.org Access-Control-Request-Method: GET, POST Access-Control-Request-Headers: X-Requested-With Host: other.example.org • More event handlers for tracking the progress of the request
socket server and sends and receives messages real- time • “Upgrades” an HTTP connection to a WebSocket connection over the same TCP/IP channel • Works over firewalls and gateways
Client subscribes to server and waits (long-lived HTTP channel) • When there’s data, server generates event and pushes the data to client • No special server protocol implementation • New EventSource HTML5 api
is the first message. ! event: notification data: This is the second message, it data: has two lines. ! id: 12345 data: This is the third message with an id
connected }); source.addEventListener(“error”, function(e) { switch (this.readyState) { case EventSource.CONNECTING: // trying to reconnect ... break; case EventSource.CLOSE: // connection closed break; } }); source.addEventListener(“message”, function(e) { // message received }); source.addEventListener(“bind_result”, function(e) { var session = JSON.parse(e.data); }); • No HTTP overhead - one single subscribe request • Updates are streamed real-time • Publish is done via regular XHR with CORS support EventSource
Load balancer Node.js service LOGIN Application server 1 Application server 2 Application server N Cassandra 1. authorize 2. loadbalance 3. get_client_settings 4. etc. POLL {server_address} access_token server_address settings access_token
Application server 1 Application server 2 Application server N Cassandra 1. authorize 2. loadbalance 3. get_client_settings 4. etc. EventSource {server_address} access_token server_address settings
keep-alive messages to keep the channel open • Internet Explorer can emulate EventSource using regular XMLHttpRequest (XDomainRequest in IE9 and below) - polyfill libraries • Safari doesn’t support EventSource with CORS Error handling