OSC over Websocket

Hey there!

This is my first post on in_thread - looks like a wonderful community!
The short version of my question: It seems Sonic-Pi is only listening for OSC via UDP. Is there any way to make it accept Websocket-connections instead?

This would be relevant when sending data per UDP is not possible in your environment, like a browser.

I’m building a web-app that basically serves as an ergonomic keyboard.
As a new feature I’m hoping to send user-input from my keyboard via OSC to sonic-pi. Now since this is a web-app I need to use a websocket for OSC communication (because JS doesn’t allow sending UDP data). But it looks to me like Sonic-Pi is listening only for OSC-over-UDP.

  • lsof -i | grep TCP returns no results for Sonic-Pi or beam, whereas the UDP-port 4560 is definitely there and open.
  • In the source-code I’ve only found the configuration-variable osc_cues_port which is used by Tau. I cannot quite make out, though, if Tau opens a Websocket at any point.

But there might still be hope! I can see from the source-code that Sonic-Pi makes use of websocket-ruby. Maybe one could use that library to open a port and accept Websocket-connections directly from a Sonic-pi script, or maybe from ‘init.rb’.

Has anybody managed to get OSC-over-Websockets to work?

Btw: in this post (Method of communicating with the server - #3 by robin.newman) I saw that there used to be a websocket on 4562, but I couldn’t connect to one there. Will check in a bit if that port is still mentioned in the source code anywhere…

Alright, after a little research:

  • Indeed, ~/.sonic-pi/log/server-output.log shows the line ‘Websocket port: 4562 OK’
  • However, I cannot reach ws://localhost:4562 (tried using osc.js in a short node-script)
  • It seems, however, that I can give cli-arguments to sonic-pi to make it use TCP as its primary protocol … but I think that serves only for the communication between the sonic-pi GUI and the sonic-pi-server, not towards an external websocket.

I have recently been setting up comms from Sonic Pi to hydra.ojack This is done with the addition of a node server.js file which provides a bridge between them, and seems to work well. SP can send OSC calls to port 41234.
See github.com/ojack/hydra.osc. I’m using this in fact in the opposite direction to which you want to go but might be useful. It can also send back to the the node server on port 41235, although I haven’t use this, but that might be useful for you.
Post Sonic Pi 4.0 (nearing release) I think there may be further work in this area, as it includes code to run phoenix within SP. This is a web framework which uses elixir and should enable comms of the type you are looking for. Historically there was a web sockets interface a long time ago with SP, and at that state SP could use TCP internal comms OR UDP (switchable), but TCP was abandoned as there were speed issues. I think this is accurate, but @samaaron may care to comment further.

Hi @robin.newman !
Thanks a lot for the reply - that’s very helpful. Also really useful to see your node.js proxy! This is indeed a simple solution to manage communication between a browser and a SP backend.

That said, in the long term it would be nice to be able to communicate with SP directly - just because that means not having to maintain a node-server (you know, another point of failure, maintenance costs, …). I’m pretty excited about SP 4.0 - certainly will play around with those new networking features!

Thanks a lot!