simple-signal
simple-signal copied to clipboard
[ISSUE] Getting a UnhandledPromiseRejectionWarning when calling .accept()
Hi, I'm trying to do a p2p connection where one peer is the browser, and the other peer is the server. So basically, my browser client code is handling a SimpleSignalClient, and the server is handling both the SimpleSignalServer and the other SimpleSignalClient. The reason is because I'm trying to pass my video/audio stream (mediaStream) from browser to server, which once I have established that connection I will then do some more work on the server side to eventually get it converted + sent to a RTMP endpoint. The issue is that when I try to establish this relationship, when I have all the code set up with the discover/request/connect/etc, when my server's SignalClient calls request.accept({}, { wrtc: wrtc }) inside the .on('request, ...) then I get this error:
(node:35795) UnhandledPromiseRejectionWarning: #<Object>
(Use node --trace-warnings ...
to show where the warning was created)
(node:35795) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict
(see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:35795) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
When I use a try/catch then I get this: metadata: {code: "ERR_CONNECTION_TIMEOUT"}
Is there a reason why this is failing to connect? Is there something else I'm missing here? I can share more of my code if it helps. Thanks!
Code snippets:
Server's SignalServer:
var signalServer = require('simple-signal-server')(io);
var signalClient = require('simple-signal-client')(socket);
...
signalServer.on('discover', (request) => {
request.discover(signalClient.socket.id);
})
signalServer.on('disconnect', (socket) => {
})
signalServer.on('request', (request) => {
request.forward();
})
Server's SignalClient:
signalClient.on('request', (request) => {
try {
request.accept({}, { wrtc: wrtc }) // Accept the incoming request
} catch (e) {
console.error(e);
}
})
Client's SignalClient:
import io from 'socket.io-client';
import SimpleSignalClient from 'simple-signal-client';
...
const signalClient = new SimpleSignalClient(io('localhost:1234'));
signalClient.on('discover', (id) => {
signalClient.connect(id); // connect to target client
});
signalClient.discover();