Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Full-Stack React Projects

You're reading from   Full-Stack React Projects Modern web development using React 16, Node, Express, and MongoDB

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781788835534
Length 470 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Shama Hoque Shama Hoque
Author Profile Icon Shama Hoque
Shama Hoque
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Unleashing React Applications with MERN FREE CHAPTER 2. Preparing the Development Environment 3. Building a Backend with MongoDB, Express, and Node 4. Adding a React Frontend to Complete MERN 5. Starting with a Simple Social Media Application 6. Exercising New MERN Skills with an Online Marketplace 7. Extending the Marketplace for Orders and Payments 8. Building a Media Streaming Application 9. Customizing the Media Player and Improving SEO 10. Developing a Web-Based VR Game 11. Making the VR Game Dynamic Using MERN 12. Following Best Practices and Developing MERN Further 13. Other Books You May Enjoy

Retrieve and stream media


On the server, we will set up a route to retrieve a single video file, which we will then use as a source in a React media player to render the streaming video.

Get video API

We will add a route in the media routes to fetch a video when a GET request is received at '/api/medias/video/:mediaId'.

mern-mediastream/server/routes/media.routes.js:

router.route('/api/medias/video/:mediaId')
        .get(mediaCtrl.video)
router.param('mediaId', mediaCtrl.mediaByID)

The :mediaId parameter in the route URL will be processed in the mediaByID controller to fetch the associated document from the Media collection and attached to the request object, so it may be used in the video controller method as required.

mern-mediastream/server/controllers/media.controller.js:

const mediaByID = (req, res, next, id) => {
  Media.findById(id).populate('postedBy', '_id name').exec((err, media) => {
    if (err || !media)
      return res.status('400').json({
        error: "Media not found"...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at R$50/month. Cancel anytime