Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10 - Web component #16

Merged
merged 25 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13daae8
Feat #10: Added temporary workspace to host web component. This commi…
santipuppoQualabs Dec 9, 2024
875482d
Feat #10: Added auto generated web component draft.
santipuppoQualabs Dec 9, 2024
a8ed3c2
Feat #10: Added config to run on https as in web workspace
santipuppoQualabs Dec 9, 2024
20dffae
Feat #10: Added web component code replicating UI work so far in plai…
santipuppoQualabs Dec 9, 2024
950b54f
Feat #10: Renamed player-component to video-moq
santipuppoQualabs Dec 10, 2024
80ebe4f
Feat #10: Added height, width and aspect-ratio attributes
santipuppoQualabs Dec 10, 2024
be369fc
Feat #10: Deleted main.ts and moved style to video-moq.css
santipuppoQualabs Dec 10, 2024
56ce720
Feat #10: CSS and comments cleanup
santipuppoQualabs Dec 10, 2024
aeda6eb
Feat #10: Added play() and pause() functions to follow HTMLMediaEleme…
santipuppoQualabs Dec 11, 2024
b943ba8
Feat #10: Added /*html*/ and created an auxiliary load function
santipuppoQualabs Dec 11, 2024
6fe9c74
Feat #10: Fixed track selection
santipuppoQualabs Dec 11, 2024
7d86c0d
feat #10: Modified show/hide controls to delete them and add them to …
santipuppoQualabs Dec 11, 2024
107c545
feat #10: Modified src attributes. Now we can either have src namespa…
santipuppoQualabs Dec 11, 2024
b5af481
feat #10: Moved controls creation so they are only created if present…
santipuppoQualabs Dec 11, 2024
45d9dcd
feat #10: Reordered css sheet
santipuppoQualabs Dec 14, 2024
5585586
feat #10: Added trackNum attribute
santipuppoQualabs Dec 14, 2024
9f2366b
feat #10: Implemented fail function to work like in current watch tsx…
santipuppoQualabs Dec 14, 2024
139b467
feat #10: Added advanced example and getter and setter for some attri…
santipuppoQualabs Dec 14, 2024
8a73722
feat #10: Moved code to lib/video-moq
santipuppoQualabs Dec 14, 2024
c47a620
feat #10: Cleanup
santipuppoQualabs Dec 18, 2024
18d9328
feat #10: Cleaned up some package json lock
santipuppoQualabs Dec 18, 2024
5c5c6eb
Merge with main: add dual builds (player without controls and web com…
JoaquinBCh Jan 14, 2025
a8e0e89
fix: added terser plugin in rollup build
JoaquinBCh Jan 16, 2025
9509e74
Merge branch 'main' into feature/web-component
englishm Jan 16, 2025
7d4a64e
Update package-lock.json
englishm Jan 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@
"version": "0.0.1",
"description": "Media over QUIC library",
"license": "(MIT OR Apache-2.0)",
"entry": "playback/index.ts",
"main": "dist/moq-player.cjs.js",
"module": "dist/moq-player.esm.js",
"wc-player": "video-moq/index.ts",
"simple-player": "playback/index.ts",
"exports": {
".": {
"import": "./dist/moq-player.esm.js",
"require": "./dist/moq-player.cjs.js"
},
"./simple-player": {
"import": "./dist/moq-simple-player.esm.js",
"require": "./dist/moq-simple-player.cjs.js"
}
},
"iife": "dist/moq-player.iife.js",
"iife-simple": "dist/moq-simple-player.iife.js",
"types": "dist/types/moq-player.d.ts",
"scripts": {
"build": "rollup -c",
Expand Down Expand Up @@ -36,6 +46,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^3.0.1",
"rollup": "^4.28.0",
"rollup-plugin-import-css": "^3.5.8",
"rollup-plugin-sourcemaps": "^0.6.2",
"rollup-plugin-web-worker-loader": "github:montevideo-tech/rollup-plugin-web-worker-loader",
"tslib": "^2.8.1",
Expand Down
29 changes: 25 additions & 4 deletions lib/playback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ export default class Player {
const kind = Catalog.isVideoTrack(track) ? "video" : Catalog.isAudioTrack(track) ? "audio" : "unknown"
if (kind == "audio" && this.#muted) return

const sub = await this.#connection.subscribe(track.namespace, track.name)

if (kind == "audio") {
// Save ref to last audio track we subscribed to for unmuting
this.#audioTrackName = track.name
Expand All @@ -140,6 +138,8 @@ export default class Player {
this.#videoTrackName = track.name
}

const sub = await this.#connection.subscribe(track.namespace, track.name)

try {
for (;;) {
const segment = await Promise.race([sub.data(), this.#running])
Expand Down Expand Up @@ -216,6 +216,14 @@ export default class Player {
return this.#paused
}

get muted(): boolean {
return this.#muted
}

get videoTrackName(): string {
return this.#videoTrackName
}

async switchTrack(trackname: string) {
const currentTrack = this.getCurrentTrack()
if (this.#paused) {
Expand Down Expand Up @@ -298,6 +306,15 @@ export default class Player {
}
*/

// Added this to divide play and pause into two different functions
async togglePlayPause() {
if (this.#paused) {
await this.play()
} else {
await this.pause()
}
}

async play() {
if (this.#paused) {
this.#paused = false
Expand All @@ -307,12 +324,16 @@ export default class Player {
await this.#backend.unmute()
}
this.#backend.play()
} else {
}
}

async pause() {
if (!this.#paused) {
this.#paused = true
this.#backend.pause()
const mutePromise = this.#backend.mute()
const audioPromise = this.unsubscribeFromTrack(this.#audioTrackName)
const videoPromise = this.unsubscribeFromTrack(this.#videoTrackName)
this.#backend.pause()
await Promise.all([mutePromise, audioPromise, videoPromise])
}
}
Expand Down
106 changes: 53 additions & 53 deletions lib/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,61 @@ const workerLoader = require("rollup-plugin-web-worker-loader")
const babel = require("@rollup/plugin-babel")
const terser = require("@rollup/plugin-terser")
const sourceMaps = require("rollup-plugin-sourcemaps")
const css = require("rollup-plugin-import-css")
const pkg = require("./package.json")

const config = []
const basePlugins = [
resolve(),
commonjs({
include: [/node_modules/, /src/],
transformMixedEsModules: true,
}),
workerLoader({ preserveSource: true }),
typescript({
typescript: require("typescript"),
}),
sourceMaps(),
babel({
babelHelpers: "bundled",
presets: ["@babel/preset-env", "@babel/preset-typescript"],
exclude: "./node_modules/*",
}),
terser(),
]

config.push({
input: pkg.entry,
output: {
file: pkg.iife,
format: "iife",
name: "moqplayer",
sourcemap: true,
module.exports = [
{
input: pkg["wc-player"],
output: [
{
file: pkg.iife,
format: "iife",
name: "MoqPlayer",
sourcemap: true,
},
{
file: pkg.exports["."].import,
format: "esm",
sourcemap: true,
},
],
plugins: [...basePlugins, css()],
},
plugins: [
resolve(),
commonjs({
include: [/node_modules/, /src/],
transformMixedEsModules: true,
}),
workerLoader({ preserveSource: true }),
typescript({
typescript: require("typescript"),
}),
sourceMaps(),
babel({
babelHelpers: "bundled",
presets: ["@babel/preset-env", "@babel/preset-typescript"],
exclude: "./node_modules/*",
}),
terser(),
],
})

config.push({
input: pkg.entry,
output: {
file: pkg.module,
format: "esm",
sourcemap: true,
{
input: pkg["simple-player"],
output: [
{
file: pkg["iife-simple"],
format: "iife",
name: "MoqSimplePlayer",
sourcemap: true,
},
{
file: pkg.exports["./simple-player"].import,
format: "esm",
sourcemap: true,
},
],
plugins: basePlugins,
},
external: [],
plugins: [
resolve(),
commonjs(),
workerLoader({ preserveSource: true }),
typescript({
typescript: require("typescript"),
}),
sourceMaps(),
babel({
babelHelpers: "bundled",
presets: ["@babel/preset-env", "@babel/preset-typescript"],
exclude: "./node_modules/*",
}),
terser(),
],
})

module.exports = config
]
4 changes: 4 additions & 0 deletions lib/types/css.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module "*.css" {
const content: string
export default content
}
Loading