|
1 | 1 | <p align="center"> |
2 | | - <img height="128px" src="https://github.com/kixelated/moq-js/blob/main/.github/logo.svg" alt="Media over QUIC"> |
| 2 | + <img height="128px" src="https://github.com/englishm/moq-js/blob/main/.github/logo.svg" alt="Media over QUIC"> |
3 | 3 | </p> |
4 | 4 |
|
| 5 | +# Media over QUIC (MoQ) Player |
| 6 | + |
5 | 7 | Media over QUIC (MoQ) is a live media delivery protocol utilizing QUIC streams. |
6 | 8 | See the [MoQ working group](https://datatracker.ietf.org/wg/moq/about/) for more information. |
7 | 9 |
|
8 | | -This repository contains the a web library for MoQ. |
9 | | -It uses the browser APIs such as WebTransport and WebCodecs to support both contribution and distribution. |
10 | | -Check out [quic.video](https://quic.video) for a demo or [run it locally](https://github.com/kixelated/quic.video) as a UI. |
| 10 | +This repository provides a **web library for MoQ**. It uses browser APIs such as **WebTransport** and **WebCodecs** to support both contribution and distribution over MoQ. |
| 11 | + |
| 12 | +> **Note**: This library currently focuses on the **client side**. You’ll need a MoQ server or relay, such as [moq-rs](https://github.com/englishm/moq-rs) (for local usage). |
| 13 | +
|
| 14 | +This library offers **two main approaches** to playing MoQ streams in a browser: |
11 | 15 |
|
12 | | -This is a client only. |
13 | | -You'll either need to run a local server using [moq-rs](https://github.com/kixelated/moq-rs) or use a public server such as [relay.quic.video](https://quic.video/relay). |
| 16 | +1. **Web Component** – `<video-moq>` with simple built-in controls. |
| 17 | +2. **Simple Player** – A `Player` class that handles rendering and playback logic without built-in UI. |
14 | 18 |
|
15 | | -Join the [Discord](https://discord.gg/FCYF3p99mr) for updates and discussion. |
| 19 | +--- |
16 | 20 |
|
17 | | -## Setup |
| 21 | +## Installation |
18 | 22 |
|
19 | | -Install the dependencies with `npm`: |
| 23 | +Install the library from npm: |
20 | 24 |
|
21 | 25 | ```bash |
22 | | -npm install |
| 26 | +npm install moq-player |
| 27 | +``` |
| 28 | + |
| 29 | +Or include via a `<script>` tag (for the IIFE build): |
| 30 | + |
| 31 | +```html |
| 32 | +<script src="https://cdn.jsdelivr.net/npm/package@latest/dist/moq-player.iife.js"></script> |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +### Web Component: `<video-moq>` |
| 38 | + |
| 39 | +```html |
| 40 | +<video-moq |
| 41 | + src="https://example.com/my-moq-stream?namespace=demo" |
| 42 | + fingerprint="https://example.com/fingerprint" |
| 43 | + width="640" |
| 44 | + muted |
| 45 | + controls |
| 46 | +></video-moq> |
23 | 47 | ``` |
24 | 48 |
|
| 49 | +The built-in controls are basic. If you want more advanced controls or custom styling, see the [Styling & Media Chrome](#styling--media-chrome) section or our samples. |
| 50 | + |
| 51 | +### Simple Player |
| 52 | + |
| 53 | +If you’d prefer to implement your own UI or integrate the player logic differently, use the class-based Player: |
| 54 | + |
| 55 | +```javascript |
| 56 | +import { Player } from "moq-player"; |
| 57 | + |
| 58 | +async function initPlayer() { |
| 59 | + const canvas = document.getElementById("my-canvas"); |
| 60 | + const player = await Player.create({ |
| 61 | + url: "https://example.com/my-moq-stream", |
| 62 | + fingerprint: "https://example.com/fingerprint", |
| 63 | + namespace: "demo", |
| 64 | + canvas, |
| 65 | + }); |
| 66 | + |
| 67 | + player.play(); |
| 68 | + // Implement your own play/pause buttons, volume sliders, etc. |
| 69 | +} |
| 70 | +``` |
| 71 | + |
| 72 | +## Events |
| 73 | + |
| 74 | +Both the Web Component and the Class-Based Player emit a series of events to help track playback state: |
| 75 | + |
| 76 | +- `play` |
| 77 | +- `pause` |
| 78 | +- `loadeddata` |
| 79 | +- `volumechange` |
| 80 | +- `unsubscribestared` |
| 81 | +- `unsubscribedone` |
| 82 | +- `subscribestared` |
| 83 | +- `subscribedone` |
| 84 | +- `waitingforkeyframe` |
| 85 | +- `timeupdate` |
| 86 | + |
| 87 | +You can listen to these events in the usual way. For example: |
| 88 | + |
| 89 | +```javascript |
| 90 | +const videoMoq = document.querySelector("video-moq"); |
| 91 | +videoMoq.addEventListener("play", () => { |
| 92 | + console.log("Playback started!"); |
| 93 | +}); |
| 94 | +``` |
| 95 | + |
| 96 | +See `samples/event-handling` for complete examples. |
| 97 | + |
| 98 | +## Styling & Media Chrome |
| 99 | + |
| 100 | +When using the `<video-moq>` element, you can style it in various ways: |
| 101 | + |
| 102 | +- **Media Chrome:** Integrate `<video-moq>` inside a `<media-controller>` and use `<media-play-button>`, `<media-time-range>`, and other controls. See `samples/media-chrome` for an example. |
| 103 | + |
| 104 | +```html |
| 105 | +<script type="module" src="https://cdn.jsdelivr.net/npm/media-chrome@4/+esm"></script> |
| 106 | +<media-controller> |
| 107 | + <video-moq slot="media" src="..." controls></video-moq> |
| 108 | + <media-play-button></media-play-button> |
| 109 | + <media-mute-button></media-mute-button> |
| 110 | + |
| 111 | + <!-- more controls... --> |
| 112 | +</media-controller> |
| 113 | +``` |
| 114 | + |
| 115 | +- **player.style:** You can also use custom themes from [player.style](https://player.style/) to style the player. See `samples/media-chrome` for a working example. |
| 116 | + |
| 117 | +```html |
| 118 | +<script type="module" src="https://cdn.jsdelivr.net/npm/player.style/x-mas/+esm"></script> |
| 119 | +<media-theme-x-mas> |
| 120 | + <video-moq |
| 121 | + src="https://localhost:4443?namespace=bbb" |
| 122 | + fingerprint="https://localhost:4443/fingerprint" |
| 123 | + width="640px" |
| 124 | + slot="media" |
| 125 | + ></video-moq> |
| 126 | +</media-theme-x-mas> |
| 127 | +``` |
| 128 | + |
| 129 | +## Samples |
| 130 | + |
| 131 | +The `samples/` directory demonstrates: |
| 132 | + |
| 133 | +- **Web Component Basic** – A simple `<video-moq>` usage. |
| 134 | +- **Web Component Advanced** – Using the component as an ES module. |
| 135 | +- **Media Chrome** – Integrating `<video-moq>` with [player.style](https://player.style/) custom themes. |
| 136 | +- **Simple Player** – Using the class-based Player without built-in controls. |
| 137 | +- **Event Handling** – Listening for playback and subscription events in detail. |
| 138 | + |
25 | 139 | ## Development |
26 | 140 |
|
27 | | -Run the development web server: |
| 141 | +- Install dependencies |
| 142 | + |
| 143 | +``` |
| 144 | +npm install |
| 145 | +``` |
| 146 | + |
| 147 | +- Run the dev server for local testing: |
28 | 148 |
|
29 | 149 | ```bash |
30 | 150 | npm run dev |
31 | 151 | ``` |
32 | 152 |
|
| 153 | +In [localhost:3000](http://localhost:3000/) you will have the samples running. |
| 154 | + |
33 | 155 | ## License |
34 | 156 |
|
35 | 157 | Licensed under either: |
36 | 158 |
|
37 | | -- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
38 | | -- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 159 | +- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) |
| 160 | +- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) |
| 161 | + |
| 162 | +## Community & Support |
| 163 | + |
| 164 | +- Join our [Discord](https://discord.gg/FCYF3p99mr) for updates and discussion. |
| 165 | +- File issues or suggestions via GitHub Issues. |
| 166 | +- Pull requests are welcome! |
0 commit comments