Skip to content

Commit

Permalink
Merge pull request #16 from Techming/develop
Browse files Browse the repository at this point in the history
Added unmount method and update documentation
  • Loading branch information
haoming29 authored Jan 1, 2023
2 parents d47033c + 6809332 commit 4aa0693
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

For change log from mjpegcanvas, please refer to: https://github.com/rctoris/mjpegcanvasjs/blob/develop/CHANGELOG.md

For change log starting from version 0.1.6, please refer to the [release page](https://github.com/Techming/web-video-canvas/releases).

2022-11-17 - **0.1.5**

- Fix type declaration
Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# web-video-canvas [![Build Status](https://img.shields.io/github/workflow/status/techming/web-video-canvas/CI)](https://github.com/Techming/web-video-canvas/actions) [![NPM Version](https://img.shields.io/npm/v/@techming/web-video-canvas)](https://www.npmjs.com/package/@techming/web-video-canvas) ![License](https://img.shields.io/npm/l/@techming/web-video-canvas)
# web-video-canvas [![Build Status](https://img.shields.io/github/actions/workflow/status/techming/web-video-canvas/main.yml?branch=master)](https://github.com/Techming/web-video-canvas/actions) [![NPM Version](https://img.shields.io/npm/v/@techming/web-video-canvas)](https://www.npmjs.com/package/@techming/web-video-canvas) ![License](https://img.shields.io/npm/l/@techming/web-video-canvas)

**Display a Video Stream from the ROS web_video_server Inside of a HTML5 Canvas**

This repo is a fork from and developed based on [mjpegcanvas](https://github.com/rctoris/mjpegcanvasjs) by [Russell Toris](https://github.com/rctoris) ([email protected]). Thanks for all the previous effort.

JSDoc can be found in [here](https://techming.github.io/web-video-canvas).

For full documentation, see [the ROS wiki](https://wiki.ros.org/web_video_canvas).
For full documentation, see [the ROS wiki](https://wiki.ros.org/web_video_canvas). JSDoc can be found [here](https://techming.github.io/web-video-canvas/).

## Usage

Expand Down Expand Up @@ -35,6 +34,10 @@ const viewer = new Viewer({
});
```

- To close HTTP connection and clear any timer used internally before unmount the viewer object, you can call `viewer.unmount()` method.
- `canvas` parameter in the construtor can be used to pass a canvas element to draw the video feed on.
- For other parameters usage, please refer to the [JSDoc](https://techming.github.io/web-video-canvas/).

### Static Import

Pre-built files can be found in [webvideocanvas.js](build/webvideocanvas.js) and [webvideocanvas.min.js](build/webvideocanvas.min.js)
Expand Down
10 changes: 9 additions & 1 deletion build/webvideocanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@ class Viewer extends (eventemitter2_default()) {
this.changeStream(this.topic);

// call draw with the given interval or rate
setInterval(this.draw.bind(this), drawInterval);
this.timer = setInterval(this.draw.bind(this), drawInterval);
}

/**
Expand Down Expand Up @@ -2776,6 +2776,14 @@ class Viewer extends (eventemitter2_default()) {
// emit an event for the change
this.emit('change', topic);
}

/**
* Remove interval and image src to close HTTP connection.
*/
unmount() {
clearInterval(this.timer);
this.image.src = '';
}
}
/* harmony default export */ const visualization_Viewer = (Viewer);
;// CONCATENATED MODULE: ./src/visualization/models/Button.js
Expand Down
2 changes: 1 addition & 1 deletion build/webvideocanvas.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@techming/web-video-canvas",
"homepage": "http://robotwebtools.org",
"description": "Display a Video Stream from the ROS web_video_server Inside of a HTML5 Canvas",
"version": "0.2.0",
"version": "0.2.1",
"license": "BSD-3-Clause",
"repository": "https://github.com/Techming/web-video-canvas",
"bugs": {
Expand Down
10 changes: 9 additions & 1 deletion src/visualization/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Viewer extends EventEmitter2 {
this.changeStream(this.topic);

// call draw with the given interval or rate
setInterval(this.draw.bind(this), drawInterval);
this.timer = setInterval(this.draw.bind(this), drawInterval);
}

/**
Expand Down Expand Up @@ -141,6 +141,14 @@ class Viewer extends EventEmitter2 {
// emit an event for the change
this.emit('change', topic);
}

/**
* Remove interval and image src to close HTTP connection.
*/
unmount() {
clearInterval(this.timer);
this.image.src = '';
}
}

export default Viewer;

0 comments on commit 4aa0693

Please sign in to comment.