2

I am working on react class component socket-related project. I have implemented different components with socket and everything seems to work fine. But now I am trying to call multiple sockets inside the componentDidMount. But only the first socket is giving me a response. After that socket call none of the functions is working.

This is the code of compomentDidMount:

componentDidMount = async () => {
    AsyncStorage.getItem('userType').then((value) => {
      console.log('userType', value);
      this.setState({ isDoctor: value === 'doctor' ? true : false });
    });
    appointmentCallConnected((data) => {
      const { callData } = this.props.route.params;
      callData.isHealthData = this.state.isHealthData;
      const { consultUserData } = this.props;
      const roomData = {
        userID: consultUserData.id,
        roomID: data.consultation.id,
      };
      //socketRoom init
      socketRoomInit(roomData);
      this.props.doctorObj(data);
      this.setState({ isConnecting: false });
    });

    //socketDisconnectOn
    const { callData, drObj } = this.props.route.params;
    callConnecting(callData);
    //socketRoomDisconnectOn
    socketRoomDisconnectOn(() => {
      readyEmit();
    });
    // healthData on
    healthData((data) => {
      this.onTapHealthRequest();
    });
    //Share healthData
    const { isShareHealthData } = this.state;
    if (isShareHealthData) {
      this.onHealth();
    }
    this.setState(
      {
        startCallTime: moment(),
      },
      () => {
        this.startDurationTimer();
      },
    );
    //config header
    this.configureHeader();
    //config media
    this.getMediaDevice();
    //Sound config
    this.initSoundConfig();
    if (Platform.OS === 'android') {
      const channelConfig = {
        id: 'callingChannel',
        name: 'Calling Channel',
        description: 'Calling channel description',
        enableVibration: false,
      };
      await this.foregroundService.createNotificationChannel(channelConfig);
      await this.startForegroundService();
    }
    this.appStateValue = AppState.addEventListener('change', this._handleAppStateChange);
    BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
    this.talkLaterTimer();
  };

In the above code, I am getting responses up to appointmentCallConnected. After that non of the sockets, functions and even console.log is not working. Is there a specific reason why this is happening?

Can anyone please help me with this? I am trying to find a solution for this for more than a week. If any further details are needed I am ready to provide them.

Thank you in advance.

hassansuhaib
  • 267
  • 3
  • 14

0 Answers0