2022-03-16 01:28:54 +01:00
|
|
|
const Path = require('path')
|
|
|
|
const PlaybackSession = require('./objects/PlaybackSession')
|
2022-03-16 00:57:15 +01:00
|
|
|
|
|
|
|
class PlaybackSessionManager {
|
2022-03-16 01:28:54 +01:00
|
|
|
constructor(db, emitter, clientEmitter) {
|
|
|
|
this.db = db
|
|
|
|
this.StreamsPath = Path.join(global.MetadataPath, 'streams')
|
|
|
|
this.emitter = emitter
|
|
|
|
this.clientEmitter = clientEmitter
|
|
|
|
|
|
|
|
this.sessions = []
|
|
|
|
}
|
|
|
|
|
2022-03-17 01:15:25 +01:00
|
|
|
async startSessionRequest(req, res) {
|
2022-03-16 01:28:54 +01:00
|
|
|
var user = req.user
|
|
|
|
var libraryItem = req.libraryItem
|
2022-03-17 01:15:25 +01:00
|
|
|
var options = req.query || {}
|
|
|
|
const session = await this.startSession(user, libraryItem, options)
|
2022-03-16 01:28:54 +01:00
|
|
|
res.json(session)
|
|
|
|
}
|
2022-03-16 00:57:15 +01:00
|
|
|
|
2022-03-17 01:15:25 +01:00
|
|
|
async startSession(user, libraryItem, options) {
|
2022-03-16 01:28:54 +01:00
|
|
|
// TODO: Determine what play method to use and setup playback session
|
2022-03-17 01:15:25 +01:00
|
|
|
// temporary client can pass direct=1 in query string for direct play
|
|
|
|
if (options.direct) {
|
|
|
|
var tracks = libraryItem.media.getDirectPlayTracklist(options)
|
|
|
|
}
|
|
|
|
|
2022-03-16 01:28:54 +01:00
|
|
|
const newPlaybackSession = new PlaybackSession()
|
2022-03-17 01:15:25 +01:00
|
|
|
newPlaybackSession.setData(libraryItem, user)
|
2022-03-16 01:28:54 +01:00
|
|
|
this.sessions.push(newPlaybackSession)
|
|
|
|
return newPlaybackSession
|
2022-03-16 00:57:15 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = PlaybackSessionManager
|