mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-23 20:29:37 +00:00
Update jsdocs
This commit is contained in:
parent
09bcc1191f
commit
903b685e1a
3 changed files with 37 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
|||
const uuidv4 = require("uuid").v4
|
||||
const uuidv4 = require('uuid').v4
|
||||
const Path = require('path')
|
||||
const serverVersion = require('../../package.json').version
|
||||
const Logger = require('../Logger')
|
||||
|
|
@ -25,10 +25,10 @@ class PlaybackSessionManager {
|
|||
}
|
||||
|
||||
getSession(sessionId) {
|
||||
return this.sessions.find(s => s.id === sessionId)
|
||||
return this.sessions.find((s) => s.id === sessionId)
|
||||
}
|
||||
getUserSession(userId) {
|
||||
return this.sessions.find(s => s.userId === userId)
|
||||
return this.sessions.find((s) => s.userId === userId)
|
||||
}
|
||||
getStream(sessionId) {
|
||||
const session = this.getSession(sessionId)
|
||||
|
|
@ -59,6 +59,12 @@ class PlaybackSessionManager {
|
|||
return deviceInfo
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('express').Request} req
|
||||
* @param {import('express').Response} res
|
||||
* @param {string} [episodeId]
|
||||
*/
|
||||
async startSessionRequest(req, res, episodeId) {
|
||||
const deviceInfo = await this.getDeviceInfo(req)
|
||||
Logger.debug(`[PlaybackSessionManager] startSessionRequest for device ${deviceInfo.deviceDescription}`)
|
||||
|
|
@ -94,7 +100,7 @@ class PlaybackSessionManager {
|
|||
|
||||
async syncLocalSession(user, sessionJson, deviceInfo) {
|
||||
const libraryItem = await Database.libraryItemModel.getOldById(sessionJson.libraryItemId)
|
||||
const episode = (sessionJson.episodeId && libraryItem && libraryItem.isPodcast) ? libraryItem.media.getEpisode(sessionJson.episodeId) : null
|
||||
const episode = sessionJson.episodeId && libraryItem && libraryItem.isPodcast ? libraryItem.media.getEpisode(sessionJson.episodeId) : null
|
||||
if (!libraryItem || (libraryItem.isPodcast && !episode)) {
|
||||
Logger.error(`[PlaybackSessionManager] syncLocalSession: Media item not found for session "${sessionJson.displayTitle}" (${sessionJson.id})`)
|
||||
return {
|
||||
|
|
@ -209,9 +215,18 @@ class PlaybackSessionManager {
|
|||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('../objects/user/User')} user
|
||||
* @param {DeviceInfo} deviceInfo
|
||||
* @param {import('../objects/LibraryItem')} libraryItem
|
||||
* @param {string|null} episodeId
|
||||
* @param {{forceDirectPlay?:boolean, forceTranscode?:boolean, mediaPlayer:string, supportedMimeTypes?:string[]}} options
|
||||
* @returns {Promise<PlaybackSession>}
|
||||
*/
|
||||
async startSession(user, deviceInfo, libraryItem, episodeId, options) {
|
||||
// Close any sessions already open for user and device
|
||||
const userSessions = this.sessions.filter(playbackSession => playbackSession.userId === user.id && playbackSession.deviceId === deviceInfo.id)
|
||||
const userSessions = this.sessions.filter((playbackSession) => playbackSession.userId === user.id && playbackSession.deviceId === deviceInfo.id)
|
||||
for (const session of userSessions) {
|
||||
Logger.info(`[PlaybackSessionManager] startSession: Closing open session "${session.displayTitle}" for user "${user.username}" (Device: ${session.deviceDescription})`)
|
||||
await this.closeSession(user, session, null)
|
||||
|
|
@ -231,7 +246,7 @@ class PlaybackSessionManager {
|
|||
}
|
||||
}
|
||||
const newPlaybackSession = new PlaybackSession()
|
||||
newPlaybackSession.setData(libraryItem, user, mediaPlayer, deviceInfo, userStartTime, episodeId)
|
||||
newPlaybackSession.setData(libraryItem, user.id, mediaPlayer, deviceInfo, userStartTime, episodeId)
|
||||
|
||||
if (libraryItem.mediaType === 'video') {
|
||||
if (shouldDirectPlay) {
|
||||
|
|
@ -328,12 +343,12 @@ class PlaybackSessionManager {
|
|||
}
|
||||
|
||||
async removeSession(sessionId) {
|
||||
const session = this.sessions.find(s => s.id === sessionId)
|
||||
const session = this.sessions.find((s) => s.id === sessionId)
|
||||
if (!session) return
|
||||
if (session.stream) {
|
||||
await session.stream.close()
|
||||
}
|
||||
this.sessions = this.sessions.filter(s => s.id !== sessionId)
|
||||
this.sessions = this.sessions.filter((s) => s.id !== sessionId)
|
||||
Logger.debug(`[PlaybackSessionManager] Removed session "${sessionId}"`)
|
||||
}
|
||||
|
||||
|
|
@ -345,8 +360,9 @@ class PlaybackSessionManager {
|
|||
try {
|
||||
const streamsInPath = await fs.readdir(this.StreamsPath)
|
||||
for (const streamId of streamsInPath) {
|
||||
if (/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(streamId)) { // Ensure is uuidv4
|
||||
const session = this.sessions.find(se => se.id === streamId)
|
||||
if (/[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/.test(streamId)) {
|
||||
// Ensure is uuidv4
|
||||
const session = this.sessions.find((se) => se.id === streamId)
|
||||
if (!session) {
|
||||
const streamPath = Path.join(this.StreamsPath, streamId)
|
||||
Logger.debug(`[PlaybackSessionManager] Removing orphan stream "${streamPath}"`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue