NativeWebSocket icon indicating copy to clipboard operation
NativeWebSocket copied to clipboard

Ability to determine if a message is binary or text

Open aroman opened this issue 5 years ago • 5 comments

Currently, the API only has OnMessage(byte[] bytes), but this doesn't allow us to determine if the message was encoded as binary or text. This data is known to the library via WebSocketMessageType, so I suggest this be exposed to clients as well.

Some options:

  1. Add a second parameter, like: OnMessage(byte[] bytes, WebSocketMessageType messageType)
  2. Create separate events, like: OnMessageText(string data) and OnMessageBinary(byte[] bytes).

I'd be happy to submit a PR implementing either approach, let me know what you think!

Thanks again for this great library.

aroman avatar Jan 03 '21 07:01 aroman

how about this library? @aroman https://github.com/psygame/UnityWebSocket

psygames avatar Jan 12 '21 02:01 psygames

Thanks for sharing your library! Actually I ended up only needing binary messages, but if I end up needing this feature I will look more closely into it.

aroman avatar Jan 13 '21 06:01 aroman

Yes, this would be important to seperate data from commands.

jeffrson avatar Nov 24 '21 10:11 jeffrson