Coder Social home page Coder Social logo

cloudfront-private's Introduction

Cloudfront-Private

Streaming all media private contents from amazon cloudfront

Installation

Add this line to your application's Gemfile:

gem 'cloudfront-private'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cloudfront-private

Getting started

Generate initializer cloudfront-private

 $ rails generate cloudfront:install

this should generated a file called cloudfront-private.rb in config/initializers

checkout this file to add amazon cloudfront credentials

	Cloudfront::Private.configure do |config|
		config.key_pair_id = 'your-key-pair-id'
		config.pem_file = 'your-private.pem'
	end

Edit above file with your amazon cloudfront private key pair id and pem file name

The private pem file should placed in 'certs' directory under Rails root

Access private content in your view

	<% filename = "folder-name/filename.mp4 %> 
	<% file = Cloudfront::Private.get_url(request,filename) %>
	<div id='media_player'></div>

Here, folder-name is hierarchy in your amazon bucket

Write javascript file to stream your private in jwplayer with jquery

	function private_streaming(){
		var flashvars = {
	    file: media,
	    provider:'rtmp',
	    streamer: 'rtmp://xxxxx.cloudfront.net/cfx/st'    
	  };
	  var params = {
	  	allowfullscreen: 'false', 
	  	allowscriptaccess:'always'
	  };
	  var attributes ={
	  	id: 'jwplayer',
	  	name: 'jwplayer'
	  }
	  swfobject.embedSWF('/jwplayer/player.swf','media_player','300','24','9.0.115','false', 
	  	flashvars, params, attributes);  	
	}
	
	$(document).ready(private_streaming);

Udate 'xxxxx.cloudfront.net' with your cloudfront distribution url

Restart your server to get update cloudfront configuration

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

cloudfront-private's People

Contributors

krishnasrihari avatar iloveitaly avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.