CSC/ECE 517 Spring 2015/ch1a 12 LS

From Expertiza_Wiki
Jump to navigation Jump to search

Live Streaming

Introduction

The purpose of live streaming is to send data over the Internet in real-time. This requires a data source, a data encoder, a media publisher and a proper network. The concept of streaming first appeared in Rails 3.1, and became more optimus with the publish of Rails 4. Now Rails 4 supports live streaming using handling I/O object and can send data from server to client in real-time.

Background

Template streaming

Streaming module has been added to ActionController since Rail 3.1. In a traditional Rails client-side profile is like this:

This is because that layouts are rendered before the content of the page. The control flow must thus be altered to render the page in the order the client needs to receive it - layout first. But for some resources which are static, If they could be loaded while waiting for the server response, it would save lots of time. The module Streaming inverts the regular Rails process of rendering the layout and template. Using streaming, Rails could render template first and then the layout. it first runs method yield and loads up the template, then renders the assets and layouts. So the profile with streaming is like this: