# webcodec_player

> ``` npm i webcodec_player ```

Latest version **1.0.7** (published 2023-02-13) · ISC license · 0 weekly downloads

## Install

```sh
npm install webcodec_player
pnpm add webcodec_player
yarn add webcodec_player
bun add webcodec_player
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2023-02-13 |
| First published | 2023-02-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | general252 |

## Links

- npm: https://www.npmjs.com/package/webcodec_player
- Repository: https://github.com/general252/webcodec_player
- Homepage: https://github.com/general252/webcodec_player#readme
- Issues: https://github.com/general252/webcodec_player/issues
- npm.io page: https://npm.io/package/webcodec_player

## Recent versions

- 1.0.7 (latest) — 2023-02-13
- 1.0.6 — 2023-02-13
- 1.0.5 — 2023-02-13
- 1.0.4 — 2023-02-10
- 1.0.3 — 2023-02-09
- 1.0.2 — 2023-02-09
- 1.0.0 — 2023-02-09

## README

```
npm i webcodec_player
```



##### demo

```
import { WebCodecPlayer } from "webcodec_player"

const h = new WebCodecPlayer({
    container: "myVideo1"
});
h.show();

let packetCount = 0;
setTimeout(() => {
    getPacketWorker(function (data) {
        packetCount++;
        h.decodeVideo(data, 0, packetCount === 1 ? true : false);
    })
}, 1000);

```

or

```
<script src="./dist/index.js"></script>
<script>
    const h = new GWebCodecPlayer({
        container: "myVideo1"
    });
    h.show();

    let packetCount = 0;
    setTimeout(() => {
        getPacketWorker(function (data) {
            packetCount++;
            h.decodeVideo(data, 0, packetCount === 1 ? true : false);
        })
    }, 1000);
</script>

```


###### getPacketWorker
```
<script>

    // getPacketWorker 获取packet数据(AnnexB格式Hevc数据, I帧前有vps sps pps帧)
    function getPacketWorker(cb) {
        //let wsURL = "ws://" + window.location.host + "/wsH265";
        let wsURL = "ws://127.0.0.1:5000/wsH265";

        // Blob => ArrayBuffer
        let reader = new FileReader();
        reader.onload = function (e) {
            cb(reader.result)
        }

        // websocket接收packet数据
        {
            console.log(wsURL)
            let ws = new WebSocket(wsURL);

            ws.onopen = function () {
                console.log("open");
                ws.send("hello"); //将消息发送到服务端
            }
            ws.onmessage = function (e) {
                reader.readAsArrayBuffer(e.data);
            }
            ws.onclose = function (e) {
                console.log("close");
            }
            ws.onerror = function (e) {
                console.log("on error", e);
            }
        }
    }
</script>
```

---
_Source: https://npm.io/package/webcodec_player · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
