RocketChat/Rocket.Chat

View on GitHub
apps/meteor/client/lib/voip/VoIPUser.ts

Summary

Maintainability
F
5 days
Test Coverage

File VoIPUser.ts has 702 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Class representing SIP UserAgent
 * @remarks
 * This class encapsulates all the details of sip.js and exposes
 * a very simple functions and callback handlers to the outside world.
Severity: Major
Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 day to fix

    VoIPUser has 50 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class VoIPUser extends Emitter<VoipEvents> {
        state: IState = {
            isReady: false,
            enableVideo: false,
        };
    Severity: Minor
    Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 7 hrs to fix

      Function handleHoldUnhold has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private async handleHoldUnhold(holdState: boolean): Promise<void> {
              const { session } = this;
              if (this._held === holdState) {
                  return Promise.resolve();
              }
      Severity: Minor
      Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

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

            async init(): Promise<void> {
                const sipUri = `sip:${this.config.authUserName}@${this.config.sipRegistrarHostnameOrIP}`;
                const transportOptions = {
                    server: this.config.webSocketURI,
                    connectionTimeout: 100, // Replace this with config
        Severity: Minor
        Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

          Function handleMuteUnmute has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private async handleMuteUnmute(muteState: boolean): Promise<void> {
                  const { session } = this;
                  if (this._held === muteState) {
                      return Promise.resolve();
                  }
          Severity: Minor
          Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

            Function setupSessionEventHandlers has 34 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected setupSessionEventHandlers(session: Session): void {
                    this.session?.stateChange.addListener((state: SessionState) => {
                        if (this.session !== session) {
                            return; // if our session has changed, just return
                        }
            Severity: Minor
            Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

              Function endCall has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async endCall(): Promise<OutgoingByeRequest | void> {
                      if (!this.session) {
                          throw new Error('Session does not exist.');
                      }
                      if (!this.canEndOrHoldCall()) {
              Severity: Minor
              Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

                Function attemptReconnection has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    async attemptReconnection(reconnectionAttempt = 0, checkRegistration = false): Promise<void> {
                        const reconnectionAttempts = this.connectionRetryCount;
                        this._connectionState = 'SERVER_RECONNECTING';
                        if (!this.userAgent) {
                            return;
                Severity: Minor
                Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

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

                      async attemptPostRecoveryRegistrationRoutine(): Promise<void> {
                          /**
                           * It might happen that the whole network loss can happen
                           * while there is ongoing call. In that case, we want to maintain
                           * the call.
                  Severity: Minor
                  Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

                    Function sendKeepAliveAndWaitForResponse has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        async sendKeepAliveAndWaitForResponse(withDebounce = false): Promise<boolean> {
                            const promise = new Promise<boolean>((resolve, reject) => {
                                let keepAliveAccepted = false;
                                let responseWaitTime = this.optionsKeepaliveInterval / 2;
                                if (withDebounce) {
                    Severity: Minor
                    Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 1 hr to fix

                      Function endCall has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          async endCall(): Promise<OutgoingByeRequest | void> {
                              if (!this.session) {
                                  throw new Error('Session does not exist.');
                              }
                              if (!this.canEndOrHoldCall()) {
                      Severity: Minor
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 55 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

                      Function handleHoldUnhold has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                      Open

                          private async handleHoldUnhold(holdState: boolean): Promise<void> {
                              const { session } = this;
                              if (this._held === holdState) {
                                  return Promise.resolve();
                              }
                      Severity: Minor
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts - About 45 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

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

                          async acceptCall(mediaRenderer: IMediaStreamRenderer): Promise<void> {
                              if (mediaRenderer) {
                                  this.mediaStreamRendered = mediaRenderer;
                              }
                              // Call state must be in offer_received.
                      Severity: Minor
                      Found in apps/meteor/client/lib/voip/VoIPUser.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

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

                              return this.session
                                  ?.invite(options)
                                  .then(() => {
                                      toggleMediaStreamTracks(!this._held, session, 'receiver');
                                      toggleMediaStreamTracks(!this._held, session, 'sender');
                      Severity: Major
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts and 1 other location - About 4 hrs to fix
                      apps/meteor/client/lib/voip/VoIPUser.ts on lines 456..468

                      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 131.

                      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

                              return this.session
                                  ?.invite(options)
                                  .then(() => {
                                      toggleMediaStreamTracks(!this._held, session, 'receiver');
                                      toggleMediaStreamTracks(!this._held, session, 'sender');
                      Severity: Major
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts and 1 other location - About 4 hrs to fix
                      apps/meteor/client/lib/voip/VoIPUser.ts on lines 529..541

                      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 131.

                      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

                                  const callerInfo: ICallerInfo = {
                                      callerId: invitation.remoteIdentity.uri.user ? invitation.remoteIdentity.uri.user : '',
                                      callerName: invitation.remoteIdentity.displayName,
                                      host: invitation.remoteIdentity.uri.host,
                                  };
                      Severity: Major
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts and 1 other location - About 2 hrs to fix
                      apps/meteor/ee/client/lib/voip/EEVoipClient.ts on lines 55..59

                      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 79.

                      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 (this._opInProgress === Operation.OP_REGISTER) {
                                  this._callState = 'REGISTERED';
                                  this.emit('registered');
                                  this.emit('stateChanged');
                              }
                      Severity: Minor
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts and 1 other location - About 50 mins to fix
                      apps/meteor/client/lib/voip/VoIPUser.ts on lines 277..281

                      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 52.

                      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 (this._opInProgress === Operation.OP_UNREGISTER) {
                                  this._callState = 'UNREGISTERED';
                                  this.emit('unregistered');
                                  this.emit('stateChanged');
                              }
                      Severity: Minor
                      Found in apps/meteor/client/lib/voip/VoIPUser.ts and 1 other location - About 50 mins to fix
                      apps/meteor/client/lib/voip/VoIPUser.ts on lines 272..276

                      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 52.

                      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