Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

osc and socket.io #172

Open
davigega opened this issue Aug 26, 2020 · 3 comments
Open

osc and socket.io #172

davigega opened this issue Aug 26, 2020 · 3 comments

Comments

@davigega
Copy link

Hello!
I am trying to rewrite the "Bidirectionl UDP <-> Web Browser" example (https://github.com/colinbdclark/osc.js-examples/blob/master/udp-browser/index.js) using the "socket.io" library instead of the "ws" one.
The differences are pretty small:

server side

const io = require('socket.io')(server) // being the server an https server

io.on('connection', (socket)=> {
  socket.send("hello");
  var socketPort = new osc.WebSocketPort({socket:socket});
  socketPort.send({address: "/id", args: [{type: "s", value: "something"}]})
  var relay = new osc.Relay(udpPort, socketPort, { })
})

the udpPort is declared exactly as in the example and it is listening: it fires on readyand it receives osc messages. The https communication works like charm using ws

client side

var port = io()
port.on("message", (oscMessage) => {
  console.log(oscMessage);
})

The clients prints the hello message but the socketPort sends an error:

'Can\'t send packets on a closed osc.Port object. Please open (or reopen) this Port by calling open().'

I tried adding socketPort.open() after its declaration, but socketPort.on("ready", ... never fires.
I'm sure that this is not a problem of your library, but are you maybe willing to help me?
By the way: Great job!

@colinbdclark
Copy link
Owner

Hi @davigega. I'm not a socket.io user, so I don't have a lot of background information to help with here. My best guess from reading your code and looking briefly at the documentation for socket.io is that you're trying to pass an instance of socket io's Socket class to osc.js's WebSocketPort. However, osc.js expects to receive a ws WebSocket object. Unless I'm misunderstanding something, you'll likely need to implement your own custom Port instance that uses socket.io to make this work.

@KonVas
Copy link

KonVas commented Jan 8, 2021

Is there any update on this @davigega ? I would also like to use socket.io for OSC communication instead of ws as I am already using it in my app

@davigega
Copy link
Author

@KonVas Unfortunately, this was out of my league. I didn't manage do implement a custom Port instance on my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants