Package com.wowza.wms.websocket.model
Class WebSocketMessage
- Object
-
- com.wowza.wms.websocket.model.WebSocketMessage
-
public class WebSocketMessage extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_CLOSE_REASON
static int
HEADER_SIZE_CONTROLFRAME
static int
MASK_SIZE
static int
OPCODE_BINARY
static int
OPCODE_CLOSE
static int
OPCODE_CONTINUATION
static int
OPCODE_PING
static int
OPCODE_PONG
static int
OPCODE_TEXT
static int
OPCODE_UNKNOWN
-
Constructor Summary
Constructors Constructor Description WebSocketMessage()
WebSocketMessage(int type)
WebSocketMessage(int type, boolean bufferIncludesHeader, byte[] buffer)
WebSocketMessage(int type, boolean bufferIncludesHeader, byte[] buffer, int offset, int len)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addBuffer(byte[] buffer, int offset, int len, boolean fragmented)
Used internally to add read TCP bytes into current pending messagestatic WebSocketMessage
createMessageBinary(boolean mask, byte[] buffer)
Create binary messagestatic WebSocketMessage
createMessageBinary(boolean mask, byte[] buffer, int offset, int len)
Create binary messagestatic WebSocketMessage
createMessageBinary(boolean mask, com.wowza.util.IFasterByteArrayOutputStream buffer, int offset, int len)
Create binary messagestatic WebSocketMessage
createMessageClose(boolean mask, int reasonCode, String reasonStr)
Create a close messagestatic WebSocketMessage
createMessagePing(boolean mask)
Create a ping message (body will be 8-byte UTC in millseconds)static WebSocketMessage
createMessagePing(boolean mask, byte[] body)
Create ping messagestatic WebSocketMessage
createMessagePong(boolean mask, WebSocketMessage messagePing)
Create pong messagestatic WebSocketMessage
createMessageText(boolean mask, String messageStr)
Create text messagebyte[]
getBuffer()
Get the raw binary message data (also need offset and len)int
getCloseReason()
If close message, get the close reasonString
getCloseReasonStr()
If close message, get the close reason strint
getLen()
Get len of message buffer dataint
getOffset()
Get offset into message bufferint
getType()
Get message type, see OPCODE_*String
getValueString()
If text message, get body as stringboolean
isBinary()
Is binary messageboolean
isControlMessage()
Is message a control messageboolean
isText()
Is message text messagelong
sendMessage(com.wowza.util.IFasterByteArrayWriteReference out)
Internal method to send message over TCP connectionvoid
setType(int type)
Set message type, see OPCODE_*String
toString()
Get message as a string (use getValueString() to get the body value of text messages)
-
-
-
Field Detail
-
DEFAULT_CLOSE_REASON
public static final String DEFAULT_CLOSE_REASON
- See Also:
- Constant Field Values
-
HEADER_SIZE_CONTROLFRAME
public static final int HEADER_SIZE_CONTROLFRAME
- See Also:
- Constant Field Values
-
MASK_SIZE
public static final int MASK_SIZE
- See Also:
- Constant Field Values
-
OPCODE_UNKNOWN
public static final int OPCODE_UNKNOWN
- See Also:
- Constant Field Values
-
OPCODE_CONTINUATION
public static final int OPCODE_CONTINUATION
- See Also:
- Constant Field Values
-
OPCODE_TEXT
public static final int OPCODE_TEXT
- See Also:
- Constant Field Values
-
OPCODE_BINARY
public static final int OPCODE_BINARY
- See Also:
- Constant Field Values
-
OPCODE_CLOSE
public static final int OPCODE_CLOSE
- See Also:
- Constant Field Values
-
OPCODE_PING
public static final int OPCODE_PING
- See Also:
- Constant Field Values
-
OPCODE_PONG
public static final int OPCODE_PONG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
WebSocketMessage
public WebSocketMessage()
-
WebSocketMessage
public WebSocketMessage(int type)
-
WebSocketMessage
public WebSocketMessage(int type, boolean bufferIncludesHeader, byte[] buffer)
-
WebSocketMessage
public WebSocketMessage(int type, boolean bufferIncludesHeader, byte[] buffer, int offset, int len)
-
-
Method Detail
-
createMessagePing
public static WebSocketMessage createMessagePing(boolean mask)
Create a ping message (body will be 8-byte UTC in millseconds)- Parameters:
mask
- true, to mask message- Returns:
- WebSocketMessage
-
createMessagePing
public static WebSocketMessage createMessagePing(boolean mask, byte[] body)
Create ping message- Parameters:
mask
- true, to mask messagebody
- bytes to include as body of message- Returns:
- WebSocketMessage
-
createMessagePong
public static WebSocketMessage createMessagePong(boolean mask, WebSocketMessage messagePing)
Create pong message- Parameters:
mask
- true, to mask messagemessagePing
- ping message that is source of pong (body copied to pong message)- Returns:
- WebSocketMessage
-
createMessageClose
public static WebSocketMessage createMessageClose(boolean mask, int reasonCode, String reasonStr)
Create a close message- Parameters:
mask
- true, to mask messagereasonCode
- reason code, see IWebSocketSession.CLOSECODE_*reasonStr
- reason string, see IWebSocketSession.CLOSESTR_*- Returns:
- WebSocketMessage
-
createMessageText
public static WebSocketMessage createMessageText(boolean mask, String messageStr)
Create text message- Parameters:
mask
- true, to mask messagemessageStr
- string data- Returns:
- WebSocketMessage
-
createMessageBinary
public static WebSocketMessage createMessageBinary(boolean mask, byte[] buffer, int offset, int len)
Create binary message- Parameters:
mask
- true, to mask messagebuffer
- body bufferoffset
- offset into body bufferlen
- len of message- Returns:
- WebSocketMessage
-
createMessageBinary
public static WebSocketMessage createMessageBinary(boolean mask, com.wowza.util.IFasterByteArrayOutputStream buffer, int offset, int len)
Create binary message- Parameters:
mask
- true, to mask messagebuffer
- body bufferoffset
- offset into body bufferlen
- len of message- Returns:
- WebSocketMessage
-
createMessageBinary
public static WebSocketMessage createMessageBinary(boolean mask, byte[] buffer)
Create binary message- Parameters:
mask
- true, to mask messagebuffer
- body buffer- Returns:
- WebSocketMessage
-
isControlMessage
public boolean isControlMessage()
Is message a control message- Returns:
- true if control message (ping, ping, close...)
-
addBuffer
public void addBuffer(byte[] buffer, int offset, int len, boolean fragmented)
Used internally to add read TCP bytes into current pending message- Parameters:
buffer
- bufferoffset
- offsetlen
- lenfragmented
- true, if fragmented
-
getType
public int getType()
Get message type, see OPCODE_*- Returns:
- message type
-
isText
public boolean isText()
Is message text message- Returns:
- true if text message
-
isBinary
public boolean isBinary()
Is binary message- Returns:
- true if binary message
-
getCloseReason
public int getCloseReason()
If close message, get the close reason- Returns:
- close reason (-1 if not close message or no reason)
-
getCloseReasonStr
public String getCloseReasonStr()
If close message, get the close reason str- Returns:
- close reason str (null if not close message or no reason)
-
getValueString
public String getValueString()
If text message, get body as string- Returns:
- get body as string
-
getBuffer
public byte[] getBuffer()
Get the raw binary message data (also need offset and len)- Returns:
- raw binary message data
-
getOffset
public int getOffset()
Get offset into message buffer- Returns:
- offset into message buffer
-
getLen
public int getLen()
Get len of message buffer data- Returns:
- len of message buffer data
-
setType
public void setType(int type)
Set message type, see OPCODE_*- Parameters:
type
- message type
-
sendMessage
public long sendMessage(com.wowza.util.IFasterByteArrayWriteReference out)
Internal method to send message over TCP connection- Parameters:
out
- writer- Returns:
- number of bytes written
-
toString
public String toString()
Get message as a string (use getValueString() to get the body value of text messages)- Overrides:
toString
in classObject
-
-