armeria icon indicating copy to clipboard operation
armeria copied to clipboard

Add WebSocketService

Open minwoox opened this issue 2 years ago • 3 comments

Motivation: It would be nice if we can provide a service that supports The WebSocket Protocol

Modifications:

  • Add WebSocketService and WebSocketHandler to implement the service using back pressure.
  • Add WebSocketFrame that represents the web socket frames.
  • Add the interface BinaryData and its implementation:
    • ByteBufBinaryData and ByteArrayBinaryData which, previously, were ByteArrayHttpData and ByteBufHttpData.
    • WebSocketFrame also uses BinaryData to store the application data.

Result:

  • You can now use WebSocketService to send WebSocket messages.
    ServerBuilder sb = ...
    WebSocketHandler backpressureHandler = (ctx, messages) -> { 
        WebSocketWriter webSocketWriter = WebSocket.streaming();
        // Write frames using back pressure.
        return webSocketWriter;
    };
    sb.service("/chat", WebSocketService.of(backpressureHandler));
    

Todos:

  • Provide another abstract class for the WebSocketHandler so that a user can implement WebSocket easily without considering back pressure. (next PR)
  • Support WebSocketClient. (next PR)
  • Support extensions. (next PR)

minwoox avatar Oct 29 '21 06:10 minwoox

Codecov Report

:exclamation: No coverage uploaded for pull request base (main@62349ab). Click here to learn what that means. Patch has no changes to coverable lines.

:exclamation: Current head d35ec9a differs from pull request most recent head e518594. Consider uploading reports for the commit e518594 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3904   +/-   ##
=======================================
  Coverage        ?   73.28%           
  Complexity      ?    15860           
=======================================
  Files           ?     1394           
  Lines           ?    60933           
  Branches        ?     7771           
=======================================
  Hits            ?    44653           
  Misses          ?    12355           
  Partials        ?     3925           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

codecov[bot] avatar Oct 29 '21 07:10 codecov[bot]

I think this is ready for review. 😉

minwoox avatar Nov 02 '21 14:11 minwoox

@ikhoon All fixed. PTAL. 😉

minwoox avatar Nov 05 '21 02:11 minwoox

I think this is ready. 😄 PTAL. 🙇

minwoox avatar Dec 15 '22 14:12 minwoox

All addressed. PTAL. 🙇

minwoox avatar May 08 '23 11:05 minwoox

Thanks a lot for reviewing. 🙇‍♂️

minwoox avatar May 18 '23 06:05 minwoox