aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/videos/live.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2022-05-03 11:38:07 +0200
committerChocobozzz <me@florianbigard.com>2022-05-03 14:49:15 +0200
commit26e3e98ff0e222a9fb9226938ac6902af77921bd (patch)
tree73d1c6f2524e380862d3365f12043fc319d40841 /server/controllers/api/videos/live.ts
parent86c5229b4d726202378ef46854383bcafca22310 (diff)
downloadPeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.gz
PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.tar.zst
PeerTube-26e3e98ff0e222a9fb9226938ac6902af77921bd.zip
Support live session in server
Diffstat (limited to 'server/controllers/api/videos/live.ts')
-rw-r--r--server/controllers/api/videos/live.ts36
1 files changed, 35 insertions, 1 deletions
diff --git a/server/controllers/api/videos/live.ts b/server/controllers/api/videos/live.ts
index e51658927..ec4c073b5 100644
--- a/server/controllers/api/videos/live.ts
+++ b/server/controllers/api/videos/live.ts
@@ -1,13 +1,21 @@
1import express from 'express' 1import express from 'express'
2import { exists } from '@server/helpers/custom-validators/misc' 2import { exists } from '@server/helpers/custom-validators/misc'
3import { createReqFiles } from '@server/helpers/express-utils' 3import { createReqFiles } from '@server/helpers/express-utils'
4import { getFormattedObjects } from '@server/helpers/utils'
4import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants' 5import { ASSETS_PATH, MIMETYPES } from '@server/initializers/constants'
5import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url' 6import { getLocalVideoActivityPubUrl } from '@server/lib/activitypub/url'
6import { federateVideoIfNeeded } from '@server/lib/activitypub/videos' 7import { federateVideoIfNeeded } from '@server/lib/activitypub/videos'
7import { Hooks } from '@server/lib/plugins/hooks' 8import { Hooks } from '@server/lib/plugins/hooks'
8import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video' 9import { buildLocalVideoFromReq, buildVideoThumbnailsFromReq, setVideoTags } from '@server/lib/video'
9import { videoLiveAddValidator, videoLiveGetValidator, videoLiveUpdateValidator } from '@server/middlewares/validators/videos/video-live' 10import {
11 videoLiveAddValidator,
12 videoLiveFindReplaySessionValidator,
13 videoLiveGetValidator,
14 videoLiveListSessionsValidator,
15 videoLiveUpdateValidator
16} from '@server/middlewares/validators/videos/video-live'
10import { VideoLiveModel } from '@server/models/video/video-live' 17import { VideoLiveModel } from '@server/models/video/video-live'
18import { VideoLiveSessionModel } from '@server/models/video/video-live-session'
11import { MVideoDetails, MVideoFullLight } from '@server/types/models' 19import { MVideoDetails, MVideoFullLight } from '@server/types/models'
12import { buildUUID, uuidToShort } from '@shared/extra-utils' 20import { buildUUID, uuidToShort } from '@shared/extra-utils'
13import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models' 21import { HttpStatusCode, LiveVideoCreate, LiveVideoLatencyMode, LiveVideoUpdate, UserRight, VideoState } from '@shared/models'
@@ -28,6 +36,13 @@ liveRouter.post('/live',
28 asyncRetryTransactionMiddleware(addLiveVideo) 36 asyncRetryTransactionMiddleware(addLiveVideo)
29) 37)
30 38
39liveRouter.get('/live/:videoId/sessions',
40 authenticate,
41 asyncMiddleware(videoLiveGetValidator),
42 videoLiveListSessionsValidator,
43 asyncMiddleware(getLiveVideoSessions)
44)
45
31liveRouter.get('/live/:videoId', 46liveRouter.get('/live/:videoId',
32 optionalAuthenticate, 47 optionalAuthenticate,
33 asyncMiddleware(videoLiveGetValidator), 48 asyncMiddleware(videoLiveGetValidator),
@@ -41,6 +56,11 @@ liveRouter.put('/live/:videoId',
41 asyncRetryTransactionMiddleware(updateLiveVideo) 56 asyncRetryTransactionMiddleware(updateLiveVideo)
42) 57)
43 58
59liveRouter.get('/:videoId/live-session',
60 asyncMiddleware(videoLiveFindReplaySessionValidator),
61 getLiveReplaySession
62)
63
44// --------------------------------------------------------------------------- 64// ---------------------------------------------------------------------------
45 65
46export { 66export {
@@ -55,6 +75,20 @@ function getLiveVideo (req: express.Request, res: express.Response) {
55 return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res))) 75 return res.json(videoLive.toFormattedJSON(canSeePrivateLiveInformation(res)))
56} 76}
57 77
78function getLiveReplaySession (req: express.Request, res: express.Response) {
79 const session = res.locals.videoLiveSession
80
81 return res.json(session.toFormattedJSON())
82}
83
84async function getLiveVideoSessions (req: express.Request, res: express.Response) {
85 const videoLive = res.locals.videoLive
86
87 const data = await VideoLiveSessionModel.listSessionsOfLiveForAPI({ videoId: videoLive.videoId })
88
89 return res.json(getFormattedObjects(data, data.length))
90}
91
58function canSeePrivateLiveInformation (res: express.Response) { 92function canSeePrivateLiveInformation (res: express.Response) {
59 const user = res.locals.oauth?.token.User 93 const user = res.locals.oauth?.token.User
60 if (!user) return false 94 if (!user) return false