项目作者: TeaFlex

项目描述 :
NodeJS module that allows streaming the raspberry pi camera module output over websocket to a webpage using a modified version of 131/h264-live-player.
高级语言: TypeScript
项目地址: git://github.com/TeaFlex/PiStreamer.git
创建时间: 2020-11-07T16:54:50Z
项目社区:https://github.com/TeaFlex/PiStreamer

开源协议:ISC License

下载


PiStreamer 🎥

PiStreamer is a nodeJS module that allows streaming the raspberry pi camera module output over websocket to a webpage using a modified version of 131/h264-live-player.

License NPM version NPM downloads

Origin

PiStreamer has been created due to a need of a streaming module for my end-of-studies work. When looking for a suitable one that could fulfill my expectations, I’ve found the amazing 131’s repository. I reworked and simplified the server side in Typescript and modded the client decoder (not anymore!!) according to my needs.

Installation

  1. npm i pistreamer

Example

To run an example of the project, enter the following commands:

  1. git clone https://github.com/TeaFlex/PiStreamer.git
  2. cd PiStreamer
  3. npm i
  4. npm run test

Usage

Server configuration:

  1. const http = require('http');
  2. const {createClient, createServer} = require('pistreamer');
  3. const port = 8000;
  4. /*
  5. Create a server with an instance of PiStreamerServer with
  6. the given options. Here, it will stream a 244x352 video at 15 fps,
  7. the stream will end if there's no viewers left and there's a limit of 5 viewers.
  8. */
  9. const piStreamer = createServer(http,{
  10. videoOptions: {
  11. framerate: 15,
  12. height: 244,
  13. width: 352
  14. },
  15. dynamic: true,
  16. limit: 5
  17. });
  18. //Put some routing here
  19. piStreamer.listen(port, () => {
  20. //create a http-live-player.js file in your static folder.
  21. createClient('./some-static-folder');
  22. console.log(`App running and listening to port ${port}`);
  23. });

Client configuration:

  1. <!--Call the script that you generated earlier.-->
  2. <script src="/http-live-player.js"></script>
  1. var canvas = document.createElement("canvas");
  2. //Pass a canvas to de decoder.
  3. var player = new WSAvcPlayer(canvas, "webgl", 1, 35);
  4. //Connect to your server.
  5. player.connect('ws://your-ip-or-domain-name');
  6. window.player = player;
  7. //Call any function of the player.
  8. document.getElementById('startStream').addEventListener('click', () => {
  9. player.playStream();
  10. document.body.appendChild(canvas);
  11. });
  12. document.getElementById('stopStream').addEventListener('click', () => {
  13. player.stopStream();
  14. document.body.removeChild(canvas);
  15. });
  16. document.getElementById('disconnect').addEventListener('click', () => {
  17. player.disconnet();
  18. document.body.removeChild(canvas);
  19. });

If you want to send personnalized messages, you can also do like this:

  1. var canvas = document.createElement("canvas");
  2. var player = new WSAvcPlayer(canvas, "webgl", 1, 35);
  3. player.connect('ws://your-ip-or-domain-name');
  4. //We take the ws client from the player;
  5. var wsClient = player.ws;
  6. window.player = player;
  7. document.getElementById('myaction').addEventListener('click', () => {
  8. wsClient.send("my personnalized action");
  9. });
  10. //*Do stuff with player methods*

Documentation

You can access the documentation of PiStreamer there:

Credits