@ -39,6 +39,9 @@ public class WebSocketMessage {
@@ -39,6 +39,9 @@ public class WebSocketMessage {
private final DataBuffer payload ;
@Nullable
private final Object nativeMessage ;
/ * *
* Constructor for a WebSocketMessage .
@ -47,13 +50,25 @@ public class WebSocketMessage {
@@ -47,13 +50,25 @@ public class WebSocketMessage {
* then invoke this constructor .
* /
public WebSocketMessage ( Type type , DataBuffer payload ) {
this ( type , payload , null ) ;
}
/ * *
* Constructor for an inbound message with access to the underlying message .
* @param type the type of WebSocket message
* @param payload the message content
* @param nativeMessage the message from the API of the underlying WebSocket
* library , if applicable .
* @since 5 . 3
* /
public WebSocketMessage ( Type type , DataBuffer payload , @Nullable Object nativeMessage ) {
Assert . notNull ( type , "'type' must not be null" ) ;
Assert . notNull ( payload , "'payload' must not be null" ) ;
this . type = type ;
this . payload = payload ;
this . nativeMessage = nativeMessage ;
}
/ * *
* Return the message type ( text , binary , etc ) .
* /
@ -68,6 +83,21 @@ public class WebSocketMessage {
@@ -68,6 +83,21 @@ public class WebSocketMessage {
return this . payload ;
}
/ * *
* Return the message from the API of the underlying WebSocket library . This
* is applicable for inbound messages only and when the underlying message
* has additional fields other than the content . Currently this is the case
* for Reactor Netty only .
* @param < T > the type to cast the underlying message to
* @return the underlying message , or { @code null }
* @since 5 . 3
* /
@Nullable
@SuppressWarnings ( "unchecked" )
public < T > T getNativeMessage ( ) {
return ( T ) this . nativeMessage ;
}
/ * *
* A variant of { @link # getPayloadAsText ( Charset ) } that uses { @code UTF - 8 }
* for decoding the raw content to text .