反应本机可能发生的未处理的承诺拒绝错误

时间:2020-10-11 19:47:55

标签: react-native

我正在使用Agora通过数据流发送消息,当我尝试切换到另一个通道(例如通道1和2)后尝试发送此消息时,会引发此错误。谁能帮助解释这个错误的含义以及如何解决?我一直在搜寻,但似乎什么也找不到。谢谢你!

Error: invalid argument
promiseMethodWrapper@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2275:45
sendStreamMessage@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:99747:47
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:98393:35
onPress@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:98579:46
onPress@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:68941:35
_performTransitionSideEffects@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:54979:22
_receiveSignal@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:54921:45
onResponderRelease@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:54830:34
invokeGuardedCallbackImpl@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:12804:21
invokeGuardedCallback@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:12898:42
invokeGuardedCallbackAndCatchFirstError@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:12902:36
executeDispatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:12974:48
executeDispatchesInOrder@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:12994:26
executeDispatchesAndRelease@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14069:35
forEach@[native code]
forEachAccumulated@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:13136:22
runEventsInBatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14093:27
runExtractedPluginEventsInBatch@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14172:25
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14148:42
batchedUpdates$1@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:24797:20
batchedUpdates@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14055:36
_receiveRootNodeIDEvent@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14147:23
receiveTouches@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:14200:34
__callFunction@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2798:36
http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2530:31
__guard@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2752:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false:2529:21
callFunctionReturnFlushedQueue@[native code]

编辑: 课

  // States for buttons (touchable highlights).
  state = {
    micPressed: false,
    dotMorsePressed: false,
    dashMorsePressed: false,
    channel1Pressed: false,
    channel2Pressed: false,
  };

  componentDidMount() {
      SplashScreen.hide();
      this.init()
  }

  init = async () => {
    // Initialize RtcEngine and event listeners.
      engine = await RtcEngine.create('74a529c906e84fe8bfe4a236869b736f');
      try {
          dataStreamId = await engine.createDataStream(true, true);
      } catch(error) {
          console.log(error.message);
      }
      console.log("dataStream: ", dataStreamId);
      Sound.setCategory('Playback');
      beep = new Sound('beep.wav', Sound.MAIN_BUNDLE, (error) => {
          if (error) {
              console.log('failed to load the sound', error);
              return;
          }
      })
      engine.addListener('StreamMessage', (uid, streamId, data) => {
          console.log('stream message was received: ', data, ' from: ', streamId )
          receivedMorse = data;
          console.log(receivedMorse);
          if(receivedMorse == 'dot'){
              beep.setCurrentTime(9.9);
              beep.play();
          } else {
              beep.setCurrentTime(9.7);
              beep.play();
          }
      })
      engine.addListener('StreamMessageError', (uid, streamId, err, missed, cached) => {
          console.log('StreamMessageError: ', err)
      })
      engine.addListener('JoinChannelSuccess', (channel, uid, elapsed) => {
          console.log('channel was joined succesfully')
      })
      engine.addListener('LeaveChannel', (channel, uid, elapsed) => {
          console.log('channel was left succesfully')
      })
      engine.addListener('Warning', (warn) => {
          console.log('Warning', warn)
      })
      engine.addListener('Error', (err) => {
          console.log('Error', err)
      })
  }

功能:

 // Functions.
  micPressedFunc = () => {
    // Function to enable microphone and mute speaker when mic button is pressed.
    engine.adjustRecordingSignalVolume(100);
    engine.adjustAudioMixingVolume(0);
  };

  micReleasedFunc = () => {
    // Function to mute microphone and enable speaker when mic button is released.
    engine.adjustRecordingSignalVolume(0);
    engine.adjustAudioMixingVolume(100);
  };

  dotMorsePressedFunc = () => {
    // Function to send dot to other users in the channel.
    engine.sendStreamMessage(dataStreamId, 'dot');
    beep.setCurrentTime(9.9);
    beep.play();
  };

  dashMorsePressedFunc = () => {
    // Function to send dash to other users in the channel.
    engine.sendStreamMessage(dataStreamId, 'dash');
    beep.setCurrentTime(9.7);
    beep.play();
  };

  channel1PressedFunc = () => {
    // Function to leave previous channel and join channel 1.
    engine.leaveChannel();
    engine.joinChannel(null, 'walt-channel-1', null, 0);
    engine.adjustRecordingSignalVolume(0);
    engine.adjustAudioMixingVolume(100);
    isConnected = true;
    this.setState({
      channel1Pressed: true,
      channel2Pressed: false,
    });
  };

  channel2PressedFunc = () => {
    // Function to leave previous channel and join channel 2.
    engine.leaveChannel();
    engine.joinChannel(null, 'walt-channel-2', null, 0);
    engine.adjustRecordingSignalVolume(0);
    engine.adjustAudioMixingVolume(100);
    isConnected = true;
    this.setState({
      channel2Pressed: true,
      channel1Pressed: false,
    });
  };

1 个答案:

答案 0 :(得分:0)

通过查看文档,您似乎在以错误的方式处理事件和顺序。例如,请假通道说:

“加入频道后,用户必须先调用LeaveChannel方法才能结束调用,然后再加入另一个频道。如果用户离开频道并释放了与该调用相关的所有资源,则此方法返回0。此方法调用是异步的,并且方法调用返回时用户尚未退出通道。用户退出通道后,SDK会触发onLeaveChannel回调。”

因此,基本上,加入/离开频道的用户不是立即开始的,您必须对其进行处理。我不能说确切的问题,但是我不能说您认为生命周期处理不正确。

至少,您可以尝试等待引擎中的方法,但是仅此一项可能还不够。您可能需要离开频道,然后在获得确认后加入新频道。