Git Product home page Git Product logo

streambroker's Introduction

streambroker Build Status

Stream Broker

Description

This micro service implments business rules for a video stream server.

This service checks how many video streams a given user is watching and prevents a user watching more than 3 video streams concurrently.

This service does not implement any UI as such. It provides backend support for following functions for the accompanying UI:

  • provides a list of available video to stream
  • maintains a list of video streams being actively played by a user
    • start a stream
    • stop a stream
  • possibly expire an active stream after duration of the stream

Usage

$ git clone rehangit/streambroker.git
$ cd streambroker
$ npm start

Deployment

now

This microservice can be deployed to now by Zeit. Assuming you've got now installed and set up:

$ now rehangit/streambroker

One of the instance running on now: https://streambroker-uqidgkqhpc.now.sh/

Try https://streambroker-uqidgkqhpc.now.sh/videos to see some sample data

Using a JWT token (as explain below) you can use Postman to GET https://streambroker-uqidgkqhpc.now.sh/streams to list a user streams POST https://streambroker-uqidgkqhpc.now.sh/streams/video/:videoId start streaming a video DELETE https://streambroker-uqidgkqhpc.now.sh/streams/:streamId stop/remove a streaming video

Alternative, deploy right now without even leaving the browser:

Deploy to now

heroku

This microservice is also deployable on heroku using the config included.

Implementation Details

Interface

/videos 
  GET (public) - lists all available videos to stream

/streams
  GET (user) - lists videoIds for all active video streams being played by the user 
  
/streams/video/:videoId
  POST (user) - generates and returns the short lived stream url for the video associated with videoId. This stream is counted towards the active video streams being watched by the user until manually removed or expires

/streams/:streamId 
  DELETE (user) - removes streamId from the current list of streams for user

Data Modelling

The service maintains database of following models

video {
  id,
  name,
  confidentialLink
};

stream {
  id,
  userId,
  videoId,      
  transientLink,
  createdAt,
};

Token

Only signed users can access the user API except GET /video which is public. A signed user is one with JWT Bearer token that is signed with a secret (default: secret123). The following info is expected in the token:

Header: { "typ": "JWT", "alg": "HS256" }

Payload: { "sub": "user_id", "iat": "timestamp" }

(e.g. { "sub": "user_xyz", "iat": 1529888559 })

An example token:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1c2VyX3h5eiIsImlhdCI6MTUyOTg4ODU1OSwianRpIjoiNmZjYjBkZjMtYmU1Yy00NzJlLThjOTItYTczYjZhNWVkOGIzIiwiZXhwIjoxNTI5ODkyMTY1fQ.olRWZqpUnedb3jVxz_a81NeHnEEgWg9mCcAqz9NOPfw

Transient Link Strategy

When a stream is created for a signed in user against a videoId, a transientLink is generated to play the video. This link is mapped to the confidentialLink of the video which is normally not directly accessible.

Current raw implementation exposes the video.confidentialLink directly in the stream.transientLink, however a future improvement can be implmented to issue a short lived signed JWT token containing the videoId or the video confidential link. In this scenario when the user would request to play the stream the token could be decoded and played if still valid. Otherwise the stream would be considered to have expired and would be removed from the user's current list of playing streams.

License

MIT © Rehan Ahmad

streambroker's People

Contributors

rehangit 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.