Skip to content

Commit

Permalink
Blocked users must not be able to live stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocobozzz committed Feb 15, 2024
1 parent 5f09fde commit ba38209
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
31 changes: 22 additions & 9 deletions packages/tests/src/api/live/live.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,16 @@ describe('Test live', function () {
rtmpUrl = 'rtmp://' + servers[0].hostname + ':' + servers[0].rtmpPort + ''
})

async function createLiveWrapper () {
const liveAttributes = {
name: 'user live',
channelId: servers[0].store.channel.id,
privacy: VideoPrivacy.PUBLIC,
saveReplay: false
}

const { uuid } = await commands[0].create({ fields: liveAttributes })
async function createLiveWrapper (token?: string, channelId?: number) {
const { uuid } = await commands[0].create({
token,
fields: {
name: 'user live',
channelId: channelId ?? servers[0].store.channel.id,
privacy: VideoPrivacy.PUBLIC,
saveReplay: false
}
})

const live = await commands[0].get({ videoId: uuid })
const video = await servers[0].videos.get({ id: uuid })
Expand Down Expand Up @@ -349,6 +350,18 @@ describe('Test live', function () {
await testFfmpegStreamError(command, true)
})

it('Should not allow a stream on if the owner has been blocked', async function () {
this.timeout(60000)

const { token, userId, userChannelId } = await servers[0].users.generate('user1')
liveVideo = await createLiveWrapper(token, userChannelId)

await servers[0].users.banUser({ userId })

const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl + '/live', streamKey: liveVideo.streamKey })
await testFfmpegStreamError(command, true)
})

it('Should not allow a stream on a live that was deleted', async function () {
this.timeout(60000)

Expand Down
15 changes: 12 additions & 3 deletions server/core/lib/live/live-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { VideoLiveSessionModel } from '@server/models/video/video-live-session.j
import { VideoLiveModel } from '@server/models/video/video-live.js'
import { VideoStreamingPlaylistModel } from '@server/models/video/video-streaming-playlist.js'
import { VideoModel } from '@server/models/video/video.js'
import { MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models/index.js'
import { MUser, MVideo, MVideoLiveSession, MVideoLiveVideo, MVideoLiveVideoWithSetting } from '@server/types/models/index.js'
import {
ffprobePromise,
getVideoStreamBitrate,
Expand Down Expand Up @@ -250,6 +250,12 @@ class LiveManager {
return this.abortSession(sessionId)
}

const user = await UserModel.loadByLiveId(videoLive.id)
if (user.blocked) {
logger.warn('User is blocked. Refusing stream %s.', streamKey, lTags(sessionId, video.uuid))
return this.abortSession(sessionId)
}

if (this.videoSessions.has(video.uuid)) {
logger.warn('Video %s has already a live session. Refusing stream %s.', video.uuid, streamKey, lTags(sessionId, video.uuid))
return this.abortSession(sessionId)
Expand Down Expand Up @@ -295,6 +301,8 @@ class LiveManager {
sessionId,
videoLive,

user,

inputLocalUrl,
inputPublicUrl,
fps,
Expand All @@ -309,6 +317,8 @@ class LiveManager {
sessionId: string
videoLive: MVideoLiveVideoWithSetting

user: MUser

inputLocalUrl: string
inputPublicUrl: string

Expand All @@ -318,13 +328,12 @@ class LiveManager {
allResolutions: number[]
hasAudio: boolean
}) {
const { sessionId, videoLive } = options
const { sessionId, videoLive, user } = options
const videoUUID = videoLive.Video.uuid
const localLTags = lTags(sessionId, videoUUID)

const liveSession = await this.saveStartingSession(videoLive)

const user = await UserModel.loadByLiveId(videoLive.id)
LiveQuotaStore.Instance.addNewLive(user.id, sessionId)

const muxingSession = new MuxingSession({
Expand Down

0 comments on commit ba38209

Please sign in to comment.