Closed jellohouse closed 6 months ago
You can listen for error events, there are some examples in the documentation:
https://github.com/colinbdclark/osc.js?tab=readme-ov-file#handling-errors
I tried both adding a listener for error and a try/catch block... neither seems to actually catch this error.
To be clear i'm using this in an Electron app. And the dialog that opens looks like this:
This is a snippet of my code currently:
var oscPort = new osc.WebSocketPort({
url: 'ws://127.0.0.1:8081',
metadata: true,
});
oscPort.open();
oscPort.on('message', function (oscMsg) {
console.log('An OSC message just arrived!', oscMsg);
});
oscPort.on('error', function (err) {
console.log('ERROR OSC', err); // -- - - - -- - - The error never shows up here...
});
oscPort.on('ready', function () {
console.log('Connected to OSC server. Ready.');
});
....
function sendMessage(message) {
try {
oscPort.send(message);
} catch (e) {
console.log("error", e); // -- - - - -- - - The error never shows up here either...
}
}
It looks like you’re opening the port before registering the event; also, are you waiting for the ready event before trying to send a message?
Yes I am waiting for the port to be ready. I also just changed the order and open the port after registering the events and still doesn't work.
var oscPort = new osc.WebSocketPort({
url: 'ws://127.0.0.1:8081',
metadata: true,
});
oscPort.on('message', function (oscMsg) {
console.log('An OSC message just arrived!', oscMsg);
});
oscPort.on('error', function (err) {
console.log('ERROR OSC', err); // -- - - - -- - - The error never shows up here...
});
oscPort.on('ready', function () {
console.log('Connected to OSC server. Ready.');
});
oscPort.open(); // I open the port here now...
....
function sendMessage(message) {
try {
oscPort.send(message);
} catch (e) {
console.log("error", e); // -- - - - -- - - The error never shows up here either...
}
}
// ... Assume the port is ready .... //
// This works normally because there is a software on port 21600 listening to OSC
sendMessage({
address: '/palette/*/*/deactivate',
args: [
{
type: 's',
value: '192.168.2.39',
},
{
type: 's',
value: '21600',
},
{
type: 'f',
value: 0,
},
],
});
// This does NOT work (AND it should NOT) because there is no software listening on port 7000 currently
// Assume the software that usually listens on port 7000 is quit.
// Now this throws an error, but i'm unable to catch/handle the error by myself without this Electron error dialog opening...
sendMessage({
address: '/clip/connect',
args: [
{
type: 's',
value: '192.168.2.39',
},
{
type: 's',
value: '7000',
},
{
type: 'f',
value: 0,
},
],
});
Ok, your example code has me very confused now. It looks like you’re sending a different set of IP addresses and port numbers as string arguments to a websocket port. How does this involve an error in osc.js? I must be missing some context here.
My bad, the issue was on my side.
I forgot i was sending OSC by WS from my Front End to a local node server which was then sending out the OSC by UDP.
I was using those 2 first args as parameters i was reading in my server side to forward the mssages.
So the error was happening on the server side...
Closing this issue now. Thanks!
Right now there is no way to properly handle send message errors.
I tried to send an OSC message to a server which i know is down/not working (192.168.2.39:7000) but i would like to still handle the error myself...
Currently my electron app opens a dialog/alert with this error when the message fails to send:
This stops my whole app from working until i close the dialog/alert.
I tried doing something like:
But the error is never caught by this try/catch block...