Chocobozzz/PeerTube

View on GitHub
server/core/lib/live/live-manager.ts

Summary

Maintainability
F
4 days
Test Coverage

File live-manager.ts has 510 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { pick, wait } from '@peertube/peertube-core-utils'
import {
  ffprobePromise,
  getVideoStreamBitrate,
  getVideoStreamDimensionsInfo,
Severity: Major
Found in server/core/lib/live/live-manager.ts - About 1 day to fix

    Function handleSession has 80 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      private async handleSession (options: {
        sessionId: string
        inputLocalUrl: string
        inputPublicUrl: string
        streamKey: string
    Severity: Major
    Found in server/core/lib/live/live-manager.ts - About 3 hrs to fix

      Function runMuxingSession has 66 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private async runMuxingSession (options: {
          sessionId: string
          videoLive: MVideoLiveVideoWithSetting
      
          user: MUser
      Severity: Major
      Found in server/core/lib/live/live-manager.ts - About 2 hrs to fix

        Function onAfterMuxingCleanup has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private async onAfterMuxingCleanup (options: {
            videoUUID: string
            liveSession?: MVideoLiveSession
            cleanupNow?: boolean // Default false
          }) {
        Severity: Minor
        Found in server/core/lib/live/live-manager.ts - About 1 hr to fix

          Function run has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async run () {
              this.running = true
          
              if (CONFIG.LIVE.RTMP.ENABLED) {
                logger.info('Running RTMP server on port %d', CONFIG.LIVE.RTMP.PORT, lTags())
          Severity: Minor
          Found in server/core/lib/live/live-manager.ts - About 1 hr to fix

            Function init has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              init () {
                const events = this.getContext().nodeEvent
                events.on('postPublish', (sessionId: string, streamPath: string) => {
                  logger.debug('RTMP received stream', { id: sessionId, streamPath, ...lTags(sessionId) })
            
            
            Severity: Minor
            Found in server/core/lib/live/live-manager.ts - About 1 hr to fix

              Function handleSession has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                private async handleSession (options: {
                  sessionId: string
                  inputLocalUrl: string
                  inputPublicUrl: string
                  streamKey: string
              Severity: Minor
              Found in server/core/lib/live/live-manager.ts - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function onAfterMuxingCleanup has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                private async onAfterMuxingCleanup (options: {
                  videoUUID: string
                  liveSession?: MVideoLiveSession
                  cleanupNow?: boolean // Default false
                }) {
              Severity: Minor
              Found in server/core/lib/live/live-manager.ts - About 35 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Avoid too many return statements within this function.
              Open

                    return this.abortSession(sessionId)
              Severity: Major
              Found in server/core/lib/live/live-manager.ts - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return this.runMuxingSession({
                      sessionId,
                      videoLive,
                
                      user,
                Severity: Major
                Found in server/core/lib/live/live-manager.ts - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                        return this.abortSession(sessionId)
                  Severity: Major
                  Found in server/core/lib/live/live-manager.ts - About 30 mins to fix

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          this.rtmpServer = createServer(socket => {
                            const session = new NodeRtmpSession(config, socket)
                    
                            session.inputOriginLocalUrl = 'rtmp://127.0.0.1:' + CONFIG.LIVE.RTMP.PORT
                            session.inputOriginPublicUrl = WEBSERVER.RTMP_URL
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 145..151

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 71.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                      rtmp: {
                        port: CONFIG.LIVE.RTMP.PORT,
                        chunk_size: VIDEO_LIVE.RTMP.CHUNK_SIZE,
                        gop_cache: VIDEO_LIVE.RTMP.GOP_CACHE,
                        ping: VIDEO_LIVE.RTMP.PING,
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/controllers/api/accounts.ts on lines 167..173

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 71.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          this.rtmpsServer = createServerTLS(serverOptions, socket => {
                            const session = new NodeRtmpSession(config, socket)
                    
                            session.inputOriginLocalUrl = 'rtmps://127.0.0.1:' + CONFIG.LIVE.RTMPS.PORT
                            session.inputOriginPublicUrl = WEBSERVER.RTMPS_URL
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 121..127

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 71.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        muxingSession.on('quota-exceeded', ({ videoUUID }) => {
                          logger.info('Stopping session of %s: user quota exceeded.', videoUUID, localLTags)
                    
                          this.stopSessionOfVideo({ videoUUID, error: LiveVideoError.QUOTA_EXCEEDED })
                        })
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 420..424

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 63.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        muxingSession.on('duration-exceeded', ({ videoUUID }) => {
                          logger.info('Stopping session of %s: max duration exceeded.', videoUUID, localLTags)
                    
                          this.stopSessionOfVideo({ videoUUID, error: LiveVideoError.DURATION_EXCEEDED })
                        })
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 426..430

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 63.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        if (!hasAudio && !hasVideo) {
                          logger.warn(
                            'Not audio and video streams were found for video %s. Refusing stream %s.',
                            video.uuid, streamKey, lTags(sessionId, video.uuid)
                          )
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 321..329

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 61.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                        if (!hasAudio && allResolutions.length === 1 && allResolutions[0] === VideoResolution.H_NOVIDEO) {
                          logger.warn(
                            'Cannot stream live to audio only because no video stream is available for video %s. Refusing stream %s.',
                            video.uuid, streamKey, lTags(sessionId, video.uuid)
                          )
                    Severity: Major
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 1 hr to fix
                    server/core/lib/live/live-manager.ts on lines 300..308

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 61.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          this.rtmpServer.on('error', err => {
                            logger.error('Cannot run RTMP server.', { err, ...lTags() })
                          })
                    Severity: Minor
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 35 mins to fix
                    server/core/lib/live/live-manager.ts on lines 153..155

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 46.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          this.rtmpsServer.on('error', err => {
                            logger.error('Cannot run RTMPS server.', { err, ...lTags() })
                          })
                    Severity: Minor
                    Found in server/core/lib/live/live-manager.ts and 1 other location - About 35 mins to fix
                    server/core/lib/live/live-manager.ts on lines 129..131

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 46.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    There are no issues that match your filters.

                    Category
                    Status