项目作者: Arjunumesh11

项目描述 :
Video streaming service uisng chunk encoding
高级语言: C++
项目地址: git://github.com/Arjunumesh11/offline_streamer.git
创建时间: 2020-06-10T20:34:09Z
项目社区:https://github.com/Arjunumesh11/offline_streamer

开源协议:

下载


Offline streamer

A simple video streaming service implemented from scratch using c++

HTTP

Transfer encoding used Chunked

Methods

  1. std::vector<char> chunk::make_chunk(std::string data,int size)

create chunks specified by http standard

  1. 5\r\n
  2. chunk\r\n
  3. 8\r\n
  4. encoding\r\n
  5. 8\r\n
  6. for data\r\n
  7. 8\r\n
  8. chunking\r\n
  9. 0\r\n
  10. \r\n

Directory Listing

Methods

  1. int create_directory(std::string root_folder)

Recursively iterate through and create a hash map

  1. std::vector<std::string> get_filelist();

Returns the List of all files in the directory

  1. std::string get_file(std::string filename);

Returns the filepath of a specific

Router

Methods

  1. std::map<std::string, std::string> get(std::string path, std::string url);

example

  1. get(" /video/:name/:filetype " , " /video/dance/mp4 ")
  1. returns map
  2. video : dance
  3. filetype : mp4

Serve static files

Methods

  1. int serve_static::servestatic::serve(std::string path, int new_socket)
  2. serve_static::servestatic::servestatic(std::string folder)

example

  1. servestatic server("./public");
  2. server.serve("/index.html",sock_fd);

Handle connection

Methods

  1. void use(void *object, int (*func)(void *context, std::string response, int new_socket))
  2. int call(std::string response, int new_socket)

Use function works similar to express.js use method

example

  1. handle_connection::handleconnection routes;
  2. routes.use(&public_folder, serve_static::servestatic::serve);
  3. routes.use(&test_folder, serve_static::servestatic::serve);

Handle Connection has a middleware stack

  1. std::vector<std::pair<void *, int (*)(void *, std::string, int)>> funclist;

Middleware can be added using use function The call function execute all the function in middleware stack in sequential order of their addition