Update more vars

This commit is contained in:
advplyr 2022-12-12 17:52:20 -06:00
parent ea42ab7624
commit 41e192c6a5

View File

@ -31,7 +31,7 @@ class PlaybackSessionManager {
return this.sessions.find(s => s.userId === userId) return this.sessions.find(s => s.userId === userId)
} }
getStream(sessionId) { getStream(sessionId) {
var session = this.getSession(sessionId) const session = this.getSession(sessionId)
return session ? session.stream : null return session ? session.stream : null
} }
@ -54,7 +54,7 @@ class PlaybackSessionManager {
} }
async syncSessionRequest(user, session, payload, res) { async syncSessionRequest(user, session, payload, res) {
var result = await this.syncSession(user, session, payload) const result = await this.syncSession(user, session, payload)
if (result) { if (result) {
res.json(session.toJSONForClient(result.libraryItem)) res.json(session.toJSONForClient(result.libraryItem))
} }
@ -66,7 +66,7 @@ class PlaybackSessionManager {
return res.status(500).send('Local session is locked and already syncing') return res.status(500).send('Local session is locked and already syncing')
} }
var libraryItem = this.db.getLibraryItem(sessionJson.libraryItemId) const libraryItem = this.db.getLibraryItem(sessionJson.libraryItemId)
if (!libraryItem) { if (!libraryItem) {
Logger.error(`[PlaybackSessionManager] syncLocalSessionRequest: Library item not found for session "${sessionJson.libraryItemId}"`) Logger.error(`[PlaybackSessionManager] syncLocalSessionRequest: Library item not found for session "${sessionJson.libraryItemId}"`)
return res.status(500).send('Library item not found') return res.status(500).send('Library item not found')
@ -74,7 +74,7 @@ class PlaybackSessionManager {
this.localSessionLock[sessionJson.id] = true // Lock local session this.localSessionLock[sessionJson.id] = true // Lock local session
var session = await this.db.getPlaybackSession(sessionJson.id) let session = await this.db.getPlaybackSession(sessionJson.id)
if (!session) { if (!session) {
// New session from local // New session from local
session = new PlaybackSession(sessionJson) session = new PlaybackSession(sessionJson)
@ -96,10 +96,10 @@ class PlaybackSessionManager {
progress: session.progress, progress: session.progress,
lastUpdate: session.updatedAt // Keep media progress update times the same as local lastUpdate: session.updatedAt // Keep media progress update times the same as local
} }
var wasUpdated = user.createUpdateMediaProgress(libraryItem, itemProgressUpdate, session.episodeId) const wasUpdated = user.createUpdateMediaProgress(libraryItem, itemProgressUpdate, session.episodeId)
if (wasUpdated) { if (wasUpdated) {
await this.db.updateEntity('user', user) await this.db.updateEntity('user', user)
var itemProgress = user.getMediaProgress(session.libraryItemId, session.episodeId) const itemProgress = user.getMediaProgress(session.libraryItemId, session.episodeId)
SocketAuthority.clientEmitter(user.id, 'user_item_progress_updated', { SocketAuthority.clientEmitter(user.id, 'user_item_progress_updated', {
id: itemProgress.id, id: itemProgress.id,
data: itemProgress.toJSON() data: itemProgress.toJSON()
@ -149,14 +149,14 @@ class PlaybackSessionManager {
// HLS not supported for video yet // HLS not supported for video yet
} }
} else { } else {
var audioTracks = [] let audioTracks = []
if (shouldDirectPlay) { if (shouldDirectPlay) {
Logger.debug(`[PlaybackSessionManager] "${user.username}" starting direct play session for item "${libraryItem.id}"`) Logger.debug(`[PlaybackSessionManager] "${user.username}" starting direct play session for item "${libraryItem.id}"`)
audioTracks = libraryItem.getDirectPlayTracklist(episodeId) audioTracks = libraryItem.getDirectPlayTracklist(episodeId)
newPlaybackSession.playMethod = PlayMethod.DIRECTPLAY newPlaybackSession.playMethod = PlayMethod.DIRECTPLAY
} else { } else {
Logger.debug(`[PlaybackSessionManager] "${user.username}" starting stream session for item "${libraryItem.id}"`) Logger.debug(`[PlaybackSessionManager] "${user.username}" starting stream session for item "${libraryItem.id}"`)
var stream = new Stream(newPlaybackSession.id, this.StreamsPath, user, libraryItem, episodeId, userStartTime) const stream = new Stream(newPlaybackSession.id, this.StreamsPath, user, libraryItem, episodeId, userStartTime)
await stream.generatePlaylist() await stream.generatePlaylist()
stream.start() // Start transcode stream.start() // Start transcode
@ -182,7 +182,7 @@ class PlaybackSessionManager {
} }
async syncSession(user, session, syncData) { async syncSession(user, session, syncData) {
var libraryItem = this.db.libraryItems.find(li => li.id === session.libraryItemId) const libraryItem = this.db.libraryItems.find(li => li.id === session.libraryItemId)
if (!libraryItem) { if (!libraryItem) {
Logger.error(`[PlaybackSessionManager] syncSession Library Item not found "${session.libraryItemId}"`) Logger.error(`[PlaybackSessionManager] syncSession Library Item not found "${session.libraryItemId}"`)
return null return null
@ -197,11 +197,11 @@ class PlaybackSessionManager {
currentTime: syncData.currentTime, currentTime: syncData.currentTime,
progress: session.progress progress: session.progress
} }
var wasUpdated = user.createUpdateMediaProgress(libraryItem, itemProgressUpdate, session.episodeId) const wasUpdated = user.createUpdateMediaProgress(libraryItem, itemProgressUpdate, session.episodeId)
if (wasUpdated) { if (wasUpdated) {
await this.db.updateEntity('user', user) await this.db.updateEntity('user', user)
var itemProgress = user.getMediaProgress(session.libraryItemId, session.episodeId) const itemProgress = user.getMediaProgress(session.libraryItemId, session.episodeId)
SocketAuthority.clientEmitter(user.id, 'user_item_progress_updated', { SocketAuthority.clientEmitter(user.id, 'user_item_progress_updated', {
id: itemProgress.id, id: itemProgress.id,
data: itemProgress.toJSON() data: itemProgress.toJSON()
@ -236,7 +236,7 @@ class PlaybackSessionManager {
} }
async removeSession(sessionId) { async removeSession(sessionId) {
var session = this.sessions.find(s => s.id === sessionId) const session = this.sessions.find(s => s.id === sessionId)
if (!session) return if (!session) return
if (session.stream) { if (session.stream) {
await session.stream.close() await session.stream.close()
@ -249,13 +249,13 @@ class PlaybackSessionManager {
async removeOrphanStreams() { async removeOrphanStreams() {
await fs.ensureDir(this.StreamsPath) await fs.ensureDir(this.StreamsPath)
try { try {
var streamsInPath = await fs.readdir(this.StreamsPath) const streamsInPath = await fs.readdir(this.StreamsPath)
for (let i = 0; i < streamsInPath.length; i++) { for (let i = 0; i < streamsInPath.length; i++) {
var streamId = streamsInPath[i] const streamId = streamsInPath[i]
if (streamId.startsWith('play_')) { // Make sure to only remove folders that are a stream if (streamId.startsWith('play_')) { // Make sure to only remove folders that are a stream
var session = this.sessions.find(se => se.id === streamId) const session = this.sessions.find(se => se.id === streamId)
if (!session) { if (!session) {
var streamPath = Path.join(this.StreamsPath, streamId) const streamPath = Path.join(this.StreamsPath, streamId)
Logger.debug(`[PlaybackSessionManager] Removing orphan stream "${streamPath}"`) Logger.debug(`[PlaybackSessionManager] Removing orphan stream "${streamPath}"`)
await fs.remove(streamPath) await fs.remove(streamPath)
} }