endel / NativeWebSocket

🔌 WebSocket client for Unity - with no external dependencies (WebGL, Native, Android, iOS, UWP)
Other
1.28k stars 161 forks source link

Ability to determine if a message is binary or text #26

Open aroman opened 3 years ago

aroman commented 3 years ago

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.

psygames commented 3 years ago

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

aroman commented 3 years ago

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.

jeffrson commented 3 years ago

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