Possible unhandled promise rejection React Native

713 Views Asked by At

We are trying to send morse code with the use of Agora API and React Native, it works when we are in the start-up channel but as soon as we switch channels it will stop working. We use the following method to send morse code and to also hear it on your own device:

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

The datastream ID remains the same when switching channels. We get the following error message:

    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]

It is not clear what argument in what method is invalid? How can we check this?

1

There are 1 best solutions below

0
On

As stated in Agora documentation createDataStream and sendStreamMessage return promises. Their types are declared:

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

You should add a then and catch methods to handle your promise behavior.

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