ArduinoWebsockets
ArduinoWebsockets copied to clipboard
Implement Arduino Print's methods in WebsocketsClient
Is your feature request related to a problem? Please describe. I want to recievce/send OSC messages over a websocket connection using this OSC library. But the OSC library is using a more low level way of recieving/sending messages. Receiving messages works fine with a bit of casting:
WebsocketsMessage msg = client.readBlocking();
OSCMessage oscMsg;
oscMsg.fill(
reinterpret_cast<uint8_t*>(const_cast<char*>(msg .c_str())),
msg.length()
);
But sending requires a class that extends Arduino's Print class.
Describe the solution you'd like
Maybe we can implement the relevant Arduino Print's methods in the WebsocketsClient client class?
Than it would be as easy as oscMessage.send(myWebsocketsClient)
The methods would be:
size_t write(const uint8_t *buffer, size_t size)
and
size_t write(uint8_t)
I'm not sure if its enough to just implement these methods or do we really have to extend the Print class?
Describe alternatives you've considered
Maybe I can also create an intermediate class that extends Arduino's Print class. But than the problem would be that I can't access the write methods of the protected underlying Ethernet or Wifi client of a WebsocketsClient.
Another alternative would be to somehow write the OSC message to a WSInterfaceString or a char buffer und send this, though I don't how to do this
I don't really know the library you linked, but I find it really odd that it depends on Arduino's Printable shenanigans. I'm opening this for contributions, but I am really against adding any printing-related code into the client class (it's already so heavy)...
I agree that this part of the osc library API is really odd, but it is developed by the inventors of OSC so it seems to be the best choice. Would it be possible to have low-level access to the send(const char* data) and send(const char* data, const size_t len) methods of WebsocketClient's _client? So I could create a wrapper class around the WebsocketClient for my project that writes the OSC message manually byte by byte, instead of collecting the whole message in a WSString object first?