项目作者: TeaFlex

项目描述 :
A Typescript portage of 131/h264-live-player.
高级语言: TypeScript
项目地址: git://github.com/TeaFlex/ts-h264-live-player.git
创建时间: 2021-04-22T15:49:36Z
项目社区:https://github.com/TeaFlex/ts-h264-live-player

开源协议:MIT License

下载


ts-h264-live-player

Typescript portage of 131/h264-live-player, the client-side h264 video player using WebSocket.

This package needs to be used with either the server-side of 131/h264-live-player or either with the package pistreamer.

Installation

Via your favorite package manager:

  1. #npm
  2. npm i ts-h264-live-player
  1. #yarn
  2. yarn add ts-h264-live-player

Or by downloading the Javascript file (see releases on Github):

  1. <script src="path/to/ts-h264-live-player.js"></script>

Usage

Create an instance of the player:

  1. // Create a canvas element
  2. let canvas = document.createElement("canvas");
  3. // Or select an existing one
  4. canvas = document.getElementById("mycanvas");
  5. // And pass it to the player.
  6. const player = new WSAvcPlayer(canvas);

Connect the player to the server:

  1. // By directly giving the address
  2. player.connectByUrl("ws://someAddress.lan");
  3. // Or by giving an Websocket object
  4. const ws = new WebSocket("ws://someAddress.lan");
  5. player.connectWithCustomClient(ws);

And control your video stream:

  1. // Using directly the methods
  2. player.startStream();
  3. player.stopStream();
  4. // Or just by sending directly the request.
  5. player.send("REQUESTSTREAM");
  6. player.send("STOPSTREAM");

Note that certain requests may not work depending on the server-side app you are using. Please, refer to the server-side app documentation.

Build it !

You can build your player js file by building it directly from the repo. To do so, clone the repo as such:

  1. git clone https://github.com/TeaFlex/ts-h264-live-player

Install all the dependencies:

  1. npm i #or "yarn"

Then build it with the following command:

  1. npm run build #or "yarn build"

The compiled file will appear in the public folder.

If you want to contribute to the project, you can also run it with:

  1. npm start #or "yarn start"

That command will compile the project and serve the content of the public folder.