可能未处理的承诺拒绝React Native

时间:2020-10-11 20:02:31

标签: react-native agora.io

我们正在尝试使用Agora API和React Native发送摩尔斯电码,当我们在启动通道中时,它可以工作,但是一旦切换通道,它将停止工作。 我们使用以下方法发送摩尔斯电码,并在您自己的设备上听到它:

engine.sendStreamMessage(dataStreamId, 'dash');
beep.setCurrentTime(9.7);
beep.play();

切换通道时,数据流ID保持不变。我们收到以下错误消息:

    Possible Unhandled Promise Rejection (id: 1):
Error: invalid argument
promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2242:45
sendStreamMessage@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:100044:47
dotMorsePressedFunc@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:98684:33
onPress@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:98876:46
onPress@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:69663:35
_performTransitionSideEffects@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:54930:22
_receiveSignal@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:54872:45
onResponderRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:54781:34
invokeGuardedCallbackImpl@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9137:21
invokeGuardedCallback@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9231:42
invokeGuardedCallbackAndCatchFirstError@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9235:36
executeDispatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9307:48
executeDispatchesInOrder@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9327:26
executeDispatchesAndRelease@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10402:35
forEach@[native code]
forEachAccumulated@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:9469:22
runEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10426:27
runExtractedPluginEventsInBatch@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10505:25
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10481:42
batchedUpdates$1@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:21130:20
batchedUpdates@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10388:36
_receiveRootNodeIDEvent@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10480:23
receiveTouches@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:10533:34
__callFunction@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2765:36
http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2497:31
__guard@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2719:15
callFunctionReturnFlushedQueue@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false:2496:21
callFunctionReturnFlushedQueue@[native code]

不清楚哪种方法中的哪个参数无效?我们如何检查呢?

1 个答案:

答案 0 :(得分:0)

如Agora文档中所述,createDataStream和sendStreamMessage返回承诺。它们的类型声明为:

createDataStream(reliable: boolean, ordered: boolean): Promise<number>
sendStreamMessage(streamId: number, message: string): Promise<void>

您应该添加一个then和catch方法来处理您的诺言行为。

var streamPromise = engine.sendStreamMessage(dataStreamId, 'dash')
streamPromise.then(() => { ...do something})
streamPromise.catch(error => ...handle error)