fix: compat for mobile streaming
fix: docker fix for seperate convex package fix fix: better support ig fix finish fix
This commit is contained in:
1 parent
827e71f833
commit
f6c4049dd1
6 files changed
+101
-11
No files matched your search
@@ -20,6 +20,7 @@ WORKDIR /app
|
||||
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
|
||||
COPY apps/web/package.json ./apps/web/
|
||||
COPY packages/convex/package.json ./packages/convex/
|
||||
|
||||
RUN --mount=type=cache,target=/root/.local/share/pnpm/store \
|
||||
corepack enable pnpm && \
|
||||
@@ -37,6 +38,8 @@ COPY --from=dependencies /app/node_modules ./node_modules
|
||||
COPY --from=dependencies /app/apps/web/node_modules ./apps/web/node_modules
|
||||
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml .npmrc ./
|
||||
COPY apps/web ./apps/web
|
||||
COPY packages/convex ./packages/convex
|
||||
COPY --from=dependencies /app/packages/convex/node_modules ./packages/convex/node_modules
|
||||
|
||||
ENV NODE_ENV=production
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import { toast } from "sonner"
|
||||
import { api } from "@otunes/convex/_generated/api"
|
||||
import type { Id } from "@otunes/convex/_generated/dataModel"
|
||||
import type { BrowseSong } from "@otunes/convex/types"
|
||||
import { playbackStreamPlan } from "@otunes/convex/playback-stream"
|
||||
import { supportsDolbyAtmosPlayback } from "@/lib/dolby-atmos-support"
|
||||
import { songHlsPlaylistUrl, songPlayUrl } from "@/lib/song-play-url"
|
||||
|
||||
@@ -126,12 +127,17 @@ function playbackLoadSettings(
|
||||
preferAtmos?: boolean
|
||||
playbackQuality?: "low" | "medium" | "high" | "lossless"
|
||||
},
|
||||
dolbyAtmosSupported: boolean | null
|
||||
dolbyAtmosSupported: boolean | null,
|
||||
files: Record<string, string>
|
||||
): PlaybackLoadSettings {
|
||||
const preferAtmos = dolbyAtmosSupported === true && (user.preferAtmos ?? false)
|
||||
const playbackQuality = user.playbackQuality ?? "medium"
|
||||
const useHls = playbackQuality !== "lossless" && !preferAtmos
|
||||
return { preferAtmos, playbackQuality, useHls }
|
||||
const preferAtmos =
|
||||
dolbyAtmosSupported === true && (user.preferAtmos ?? false)
|
||||
const plan = playbackStreamPlan(files, user.playbackQuality, preferAtmos)
|
||||
return {
|
||||
preferAtmos: plan.preferAtmos,
|
||||
playbackQuality: plan.playbackQuality,
|
||||
useHls: plan.useHls,
|
||||
}
|
||||
}
|
||||
|
||||
function songLoadKey(songId: string, settings: PlaybackLoadSettings) {
|
||||
@@ -290,12 +296,20 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}, [])
|
||||
|
||||
const currentSong = playback?.currentSong ?? null
|
||||
const currentSongDoc = useQuery(
|
||||
api.library.getSong,
|
||||
currentSong ? { id: currentSong.id } : "skip"
|
||||
)
|
||||
const isPlaybackActive = Boolean(currentSong && isPlaying)
|
||||
const repeatEnabled = playback?.repeatEnabled ?? "none"
|
||||
const queueLength = playback?.queueSongIds.length ?? 0
|
||||
const queueSongIds = playback?.queueSongIds ?? []
|
||||
const nextQueueSongId =
|
||||
queueSongIds.length > 1 ? queueSongIds[1] : null
|
||||
const nextQueueSongDoc = useQuery(
|
||||
api.library.getSong,
|
||||
nextQueueSongId ? { id: nextQueueSongId } : "skip"
|
||||
)
|
||||
|
||||
const seekTo = useCallback(
|
||||
(seconds: number) => {
|
||||
@@ -547,11 +561,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
return
|
||||
}
|
||||
|
||||
if (user === undefined || !user) {
|
||||
if (user === undefined || !user || !currentSongDoc) {
|
||||
return
|
||||
}
|
||||
|
||||
const settings = playbackLoadSettings(user, dolbyAtmosSupported)
|
||||
const settings = playbackLoadSettings(
|
||||
user,
|
||||
dolbyAtmosSupported,
|
||||
currentSongDoc.files
|
||||
)
|
||||
const loadKey = songLoadKey(currentSong.id, settings)
|
||||
|
||||
if (loadedSongKeyRef.current === loadKey) {
|
||||
@@ -605,6 +623,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
}, [
|
||||
currentSong?.id,
|
||||
currentSongDoc,
|
||||
user === undefined,
|
||||
user?.playbackQuality,
|
||||
user?.preferAtmos,
|
||||
@@ -622,11 +641,15 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
return
|
||||
}
|
||||
|
||||
if (user === undefined || !user) {
|
||||
if (user === undefined || !user || !nextQueueSongDoc) {
|
||||
return
|
||||
}
|
||||
|
||||
const settings = playbackLoadSettings(user, dolbyAtmosSupported)
|
||||
const settings = playbackLoadSettings(
|
||||
user,
|
||||
dolbyAtmosSupported,
|
||||
nextQueueSongDoc.files
|
||||
)
|
||||
const loadKey = songLoadKey(nextQueueSongId, settings)
|
||||
|
||||
if (preloadedSongKeyRef.current === loadKey) {
|
||||
@@ -662,6 +685,7 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}, [
|
||||
currentSong?.id,
|
||||
nextQueueSongId,
|
||||
nextQueueSongDoc,
|
||||
user === undefined,
|
||||
user?.playbackQuality,
|
||||
user?.preferAtmos,
|
||||
@@ -726,8 +750,12 @@ export function PlaybackProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
|
||||
const preloadAudio = preloadAudioRef.current
|
||||
if (shouldContinuePlaying && preloadAudio && nextQueueSongId && user) {
|
||||
const settings = playbackLoadSettings(user, dolbyAtmosSupported)
|
||||
if (shouldContinuePlaying && preloadAudio && nextQueueSongId && user && nextQueueSongDoc) {
|
||||
const settings = playbackLoadSettings(
|
||||
user,
|
||||
dolbyAtmosSupported,
|
||||
nextQueueSongDoc.files
|
||||
)
|
||||
const nextLoadKey = songLoadKey(nextQueueSongId, settings)
|
||||
|
||||
if (
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
.env.local
|
||||
+2
@@ -16,6 +16,7 @@ import type * as http from "../http.js";
|
||||
import type * as library from "../library.js";
|
||||
import type * as playback from "../playback.js";
|
||||
import type * as playlists from "../playlists.js";
|
||||
import type * as types from "../types.js";
|
||||
import type * as users from "../users.js";
|
||||
|
||||
import type {
|
||||
@@ -33,6 +34,7 @@ declare const fullApi: ApiFromModules<{
|
||||
library: typeof library;
|
||||
playback: typeof playback;
|
||||
playlists: typeof playlists;
|
||||
types: typeof types;
|
||||
users: typeof users;
|
||||
}>;
|
||||
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
"./types": {
|
||||
"types": "./convex/types.ts",
|
||||
"default": "./convex/types.ts"
|
||||
},
|
||||
"./playback-stream": {
|
||||
"types": "./playback-stream.ts",
|
||||
"default": "./playback-stream.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
export type PlaybackQuality = "low" | "medium" | "high" | "lossless"
|
||||
|
||||
export function qualityKbps(quality: PlaybackQuality | null | undefined) {
|
||||
if (quality === "low") {
|
||||
return 64
|
||||
}
|
||||
|
||||
if (quality === "high") {
|
||||
return 256
|
||||
}
|
||||
|
||||
if (quality === "medium") {
|
||||
return 128
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
export type PlaybackStreamPlan = {
|
||||
playbackQuality: PlaybackQuality
|
||||
preferAtmos: boolean
|
||||
transcodeNeeded: boolean
|
||||
useHls: boolean
|
||||
}
|
||||
|
||||
export function playbackStreamPlan(
|
||||
files: Record<string, string>,
|
||||
quality: PlaybackQuality | undefined,
|
||||
preferAtmos: boolean
|
||||
): PlaybackStreamPlan {
|
||||
const playbackQuality = quality ?? "medium"
|
||||
const kbps =
|
||||
playbackQuality === "lossless" ? 0 : qualityKbps(playbackQuality)
|
||||
|
||||
let transcodeNeeded = true
|
||||
|
||||
if (preferAtmos && "atmos" in files) {
|
||||
transcodeNeeded = false
|
||||
} else if (kbps === 0 && "lossless" in files) {
|
||||
transcodeNeeded = false
|
||||
} else if (kbps === 0 || (kbps === 256 && "normal" in files)) {
|
||||
transcodeNeeded = false
|
||||
}
|
||||
|
||||
return {
|
||||
playbackQuality,
|
||||
preferAtmos,
|
||||
transcodeNeeded,
|
||||
useHls: transcodeNeeded && !preferAtmos,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user