RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/webrtc/client/WebRTCClass.js

Summary

Maintainability
F
1 wk
Test Coverage

File WebRTCClass.js has 829 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { Emitter } from '@rocket.chat/emitter';
import { Meteor } from 'meteor/meteor';
import { ReactiveVar } from 'meteor/reactive-var';
import { Tracker } from 'meteor/tracker';

Severity: Major
Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 1 day to fix

    WebRTCClass has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class WebRTCClass {
        /*
              @param seldId {String}
              @param room {String}
       */
    Severity: Minor
    Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 4 hrs to fix

      Function getUserMedia has 100 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getUserMedia(media, onSuccess, onError = this.onError) {
              if (media.desktop !== true) {
                  this._getUserMedia(media, onSuccess, onError);
                  return;
              }
      Severity: Major
      Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 4 hrs to fix

        Function getUserMedia has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            getUserMedia(media, onSuccess, onError = this.onError) {
                if (media.desktop !== true) {
                    this._getUserMedia(media, onSuccess, onError);
                    return;
                }
        Severity: Minor
        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 3 hrs 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 getScreen has 73 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                const getScreen = (audioStream) => {
                    const refresh = function () {
                        imperativeModal.open({
                            component: GenericModal,
                            props: {
        Severity: Major
        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 2 hrs to fix

          Function constructor has 60 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              constructor(selfId, room, autoAccept = false) {
                  this.config = {
                      iceServers: [],
                  };
                  this.debug = false;
          Severity: Major
          Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 2 hrs to fix

            Function getPeerConnection has 59 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                getPeerConnection(id) {
                    if (this.peerConnections[id] != null) {
                        return this.peerConnections[id];
                    }
                    const peerConnection = new RTCPeerConnection(this.config);
            Severity: Major
            Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 2 hrs to fix

              Function onRemoteCall has 58 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  onRemoteCall(data) {
                      if (this.autoAccept === true) {
                          setTimeout(() => {
                              this.joinCall({
                                  to: data.from,
              Severity: Major
              Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 2 hrs to fix

                Function onRemoteJoin has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    onRemoteJoin(data, ...args) {
                        if (this.active !== true) {
                            return;
                        }
                        this.log('onRemoteJoin', [data, ...args]);
                Severity: Minor
                Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 1 hr to fix

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

                      getInstanceByRoomId(rid, visitorId = null) {
                          let enabled = false;
                          if (!visitorId) {
                              const subscription = ChatSubscription.findOne({ rid });
                              if (!subscription) {
                  Severity: Minor
                  Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 1 hr to fix

                    Function onRemoteOffer has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        onRemoteOffer(data, ...args) {
                            if (this.active !== true) {
                                return;
                            }
                    
                    
                    Severity: Minor
                    Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 1 hr to fix

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

                          updateRemoteItems() {
                              const items = [];
                              const itemsById = {};
                              const { peerConnections } = this;
                      
                      
                      Severity: Minor
                      Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 1 hr to fix

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

                            getInstanceByRoomId(rid, visitorId = null) {
                                let enabled = false;
                                if (!visitorId) {
                                    const subscription = ChatSubscription.findOne({ rid });
                                    if (!subscription) {
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - 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 onRemoteCall has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            onRemoteCall(data) {
                                if (this.autoAccept === true) {
                                    setTimeout(() => {
                                        this.joinCall({
                                            to: data.from,
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - 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 constructor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            constructor(selfId, room, autoAccept = false) {
                                this.config = {
                                    iceServers: [],
                                };
                                this.debug = false;
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 25 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 onRemoteJoin has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            onRemoteJoin(data, ...args) {
                                if (this.active !== true) {
                                    return;
                                }
                                this.log('onRemoteJoin', [data, ...args]);
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js - About 25 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

                            sendCandidate(data) {
                                data.from = this.webrtcInstance.selfId;
                                data.room = this.webrtcInstance.room;
                                this.log('WebRTCTransportClass - sendCandidate', data);
                                sdk.publish('notify-user', [`${data.to}/${WEB_RTC_EVENTS.WEB_RTC}`, WEB_RTC_EVENTS.CANDIDATE, data]);
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 3 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 90..95

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

                        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

                            sendDescription(data) {
                                data.from = this.webrtcInstance.selfId;
                                data.room = this.webrtcInstance.room;
                                this.log('WebRTCTransportClass - sendDescription', data);
                                sdk.publish('notify-user', [`${data.to}/${WEB_RTC_EVENTS.WEB_RTC}`, WEB_RTC_EVENTS.DESCRIPTION, data]);
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 3 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 83..88

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

                        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

                                    sdk.publish('notify-room-users', [
                                        `${this.webrtcInstance.room}/${WEB_RTC_EVENTS.WEB_RTC}`,
                                        WEB_RTC_EVENTS.JOIN,
                                        {
                                            from: this.webrtcInstance.selfId,
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 2 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 44..53

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

                        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

                                sdk.publish('notify-room-users', [
                                    `${this.webrtcInstance.room}/${WEB_RTC_EVENTS.WEB_RTC}`,
                                    WEB_RTC_EVENTS.CALL,
                                    {
                                        from: this.webrtcInstance.selfId,
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 2 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 70..79

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

                        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

                            setAudioEnabled(enabled = true) {
                                if (this.localStream != null) {
                                    this.localStream.getAudioTracks().forEach((audio) => {
                                        audio.enabled = enabled;
                                    });
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 2 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 593..600

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

                        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

                            setVideoEnabled(enabled = true) {
                                if (this.localStream != null) {
                                    this.localStream.getVideoTracks().forEach((video) => {
                                        video.enabled = enabled;
                                    });
                        Severity: Major
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 2 hrs to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 569..576

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

                        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

                            toggleAudio() {
                                if (this.audioEnabled.get()) {
                                    return this.disableAudio();
                                }
                                return this.enableAudio();
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 35 mins to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 633..638

                        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

                            toggleVideo() {
                                if (this.videoEnabled.get()) {
                                    return this.disableVideo();
                                }
                                return this.enableVideo();
                        Severity: Minor
                        Found in apps/meteor/app/webrtc/client/WebRTCClass.js and 1 other location - About 35 mins to fix
                        apps/meteor/app/webrtc/client/WebRTCClass.js on lines 586..591

                        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