@cycjimmy/jsmpeg-player 6.1.7 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # JSMpeg Player(TS Player)
2
2
 
3
- ![][workflows-badge-image]
3
+ ![Test CI][workflows-badge-image]
4
4
  [![libraries dependency status][libraries-status-image]][libraries-status-url]
5
5
  [![libraries sourcerank][libraries-sourcerank-image]][libraries-sourcerank-url]
6
6
  [![Release date][release-date-image]][release-url]
7
- [![rollup][rollup-image]][rollup-url]
7
+ [![vite][vite-image]][vite-url]
8
8
  [![semantic-release][semantic-image]][semantic-url]
9
9
  [![npm license][license-image]][download-url]
10
10
 
@@ -12,7 +12,7 @@
12
12
  * **[jsmpeg-player](https://github.com/cycdpo/jsmpeg-player) has been renamed to @cycjimmy/jsmpeg-player for scoped NPM package.**
13
13
  * JSMpeg player is based on [jsmpeg](https://github.com/phoboslab/jsmpeg).
14
14
  * The video must be compressed into the TS format of MPEG1 / MP2.
15
- * Apple device automatically plays without sound, you need to guide the user to click on the video in the lower right corner of the video icon to unlock the sound. (no similar problem in non-autoplay mode)
15
+ * Autoplay with sound is blocked by the browser until the page receives a user gesture: Apple device automatically plays without sound, you need to guide the user to click on the video in the lower right corner of the video icon to unlock the sound. Chrome and Safari follow the same autoplay policy, where the sound stays in sync with the picture and starts as soon as the user interacts with the page, or can be unlocked right away through the same icon. (no similar problem in non-autoplay mode)
16
16
  * [Demo][github-pages-url]
17
17
 
18
18
  ## How to use
@@ -29,13 +29,11 @@ $ yarn add @cycjimmy/jsmpeg-player
29
29
 
30
30
  ### Usage
31
31
  ```javascript
32
- import JSMpeg from '@cycjimmy/jsmpeg-player';
33
- # OR
34
- const JSMpeg = require('@cycjimmy/jsmpeg-player');
32
+ import JSMpeg from '@cycjimmy/jsmpeg-player'
35
33
  ```
36
34
 
37
35
  ```javascript
38
- new JSMpeg.VideoElement(videoWrapper, videoUrl [, options] [, overlayOptions])
36
+ // new JSMpeg.VideoElement(videoWrapper, videoUrl [, options] [, overlayOptions])
39
37
  ```
40
38
 
41
39
  * `JSMpeg.VideoElement` config:
@@ -74,10 +72,10 @@ The WebGL drawing buffer is cleared once a frame has been composited, so reading
74
72
  ```javascript
75
73
  const video = new JSMpeg.VideoElement('#videoWrapper', 'video.ts', {}, {
76
74
  preserveDrawingBuffer: true,
77
- });
75
+ })
78
76
 
79
77
  // Any time after the first frame has been rendered
80
- const dataUrl = video.els.canvas.toDataURL('image/png');
78
+ const dataUrl = video.els.canvas.toDataURL('image/png')
81
79
  ```
82
80
 
83
81
  * The flag is read when the WebGL context is created, so it must be passed at construction time — it can not be enabled on a player that is already running.
@@ -89,15 +87,15 @@ const dataUrl = video.els.canvas.toDataURL('image/png');
89
87
  A browser can not set an `Authorization` header on a WebSocket handshake — `new WebSocket(url, protocols)` is all the WebSocket API offers. The closest browser-native option is to send the token as a subprotocol, which arrives on the server as the `Sec-WebSocket-Protocol` request header (kept out of the URL and out of access logs):
90
88
 
91
89
  ```javascript
92
- new JSMpeg.VideoElement('#videoWrapper', 'wss://example.com/stream', {}, {
90
+ const video = new JSMpeg.VideoElement('#videoWrapper', 'wss://example.com/stream', {}, {
93
91
  protocols: ['Bearer.<token>'],
94
- });
92
+ })
95
93
  ```
96
94
 
97
95
  ```javascript
98
- new JSMpeg.Player('wss://example.com/stream', {
96
+ const player = new JSMpeg.Player('wss://example.com/stream', {
99
97
  protocols: ['Bearer.<token>'],
100
- });
98
+ })
101
99
  ```
102
100
 
103
101
  * The server must accept the subprotocol and **echo it back** in the handshake response (`Sec-WebSocket-Protocol`). If none of the requested subprotocols is echoed, the browser aborts the connection.
@@ -112,7 +110,7 @@ Each `JSMpeg.VideoElement` is a complete, independent player: it opens its own s
112
110
 
113
111
  **Call `destroy()` when a player goes away.** In a SPA, discarding the instance returned by the constructor — e.g. calling it in `componentDidMount` without storing the result — leaves the player running after its markup is gone: the socket, the WebGL context and the decode loop all survive. A few navigations are then enough to exhaust the page, and since nothing throws, a hard reload appears to be the only fix.
114
112
 
115
- ```javascript
113
+ ```text
116
114
  // React
117
115
  componentDidMount() {
118
116
  this.video = new JSMpeg.VideoElement('#videoWrapper', 'wss://example.com/stream');
@@ -146,9 +144,37 @@ To keep many cameras on screen:
146
144
  ## CDN
147
145
  To use via a CDN include this in your HTML:
148
146
  ```text
149
- <script src="https://cdn.jsdelivr.net/npm/@cycjimmy/jsmpeg-player@6/dist/jsmpeg-player.umd.min.js"></script>
147
+ <script src="https://cdn.jsdelivr.net/npm/@cycjimmy/jsmpeg-player@7/dist/jsmpeg-player.umd.min.js"></script>
150
148
  ```
151
149
 
150
+ ## Migrating to v7
151
+
152
+ v7 drops the CommonJS build and raises the Node and browser targets. `import` and the browser global are unchanged, so most consumers need no change at all.
153
+
154
+ * `dist/jsmpeg-player.cjs` is no longer produced and `exports` no longer exposes a `require` condition. `require('@cycjimmy/jsmpeg-player')` keeps working on Node >= 20.19, because Node can `require()` an ES module, but it returns the module namespace: use `require('@cycjimmy/jsmpeg-player').default`.
155
+ * `main` and `module` both point at `dist/jsmpeg-player.esm.js`. The `browser` field still points at the UMD build for CDN and legacy tooling.
156
+ * `engines.node` is now `^22.22.2 || >=24.15.0`, the floor of the new build toolchain. `engines` is stripped from the published tarball, so it only constrains contributors and CI, not consumers.
157
+ * The build targets `es2015` with the `defaults` browserslist, so IE is no longer supported. Babel down-leveling is gone, which makes `jsmpeg-player.esm.js` about 24% smaller and `jsmpeg-player.umd.min.js` slightly smaller than v6.
158
+ * Deep paths keep working through the `./dist/*` export.
159
+ * The runtime CSS is still injected as a `<style>` element; there is no stylesheet to import.
160
+
161
+ ```javascript
162
+ // CommonJS consumers: require() can load an ES module from Node 20.19 on
163
+ const JSMpeg = require('@cycjimmy/jsmpeg-player').default
164
+ ```
165
+
166
+ ## Development
167
+
168
+ ```shell
169
+ $ npm run dev # Vite dev server on top of the root index.html
170
+ $ npm run lint # ESLint (flat config, @antfu/eslint-config)
171
+ $ npm run lint:style # Stylelint for src/**/*.{css,scss}
172
+ $ npm test # node --test
173
+ $ npm run package # build dist/ and assemble .release/
174
+ ```
175
+
176
+ `index.html` in the repository root is the development entry: it imports `src/` through Vite, so changes show up without a build. `static/index.html` is the GitHub Pages demo and loads the pre-built `jsmpeg-player.umd.js` with a plain `<script>` tag; `npm run build:deployment` assembles it in `.publish/`. See [CONTRIBUTING.md](CONTRIBUTING.md) for the checks the CI runs.
177
+
152
178
  ## Encoding Video/Audio for [jsmpeg](https://github.com/phoboslab/jsmpeg) by [ffmpeg](https://ffmpeg.org/). E.g:
153
179
  ```shell
154
180
  $ ffmpeg -i input.mp4 -f mpegts \
@@ -187,8 +213,8 @@ $ ffmpeg -i input.mp4 -f mpegts \
187
213
  [release-date-image]: https://img.shields.io/github/release-date/cycjimmy/jsmpeg-player
188
214
  [release-url]: https://github.com/cycjimmy/jsmpeg-player/releases
189
215
 
190
- [rollup-image]: https://img.shields.io/github/package-json/dependency-version/cycjimmy/jsmpeg-player/dev/rollup
191
- [rollup-url]: https://github.com/rollup/rollup
216
+ [vite-image]: https://img.shields.io/github/package-json/dependency-version/cycjimmy/jsmpeg-player/dev/vite
217
+ [vite-url]: https://github.com/vitejs/vite
192
218
 
193
219
  [semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg
194
220
  [semantic-url]: https://github.com/semantic-release/semantic-release