Package com.wowza.wms.websocket.model
Class WebSocketMessage
Object
com.wowza.wms.websocket.model.WebSocketMessage
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorsConstructorDescriptionWebSocketMessage
(int type) WebSocketMessage
(int type, boolean bufferIncludesHeader, byte[] buffer) WebSocketMessage
(int type, boolean bufferIncludesHeader, byte[] buffer, int offset, int len) -
Method Summary
Modifier and TypeMethodDescriptionvoid
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[]
Get the raw binary message data (also need offset and len)int
If close message, get the close reasonIf close message, get the close reason strint
getLen()
Get len of message buffer dataint
Get offset into message bufferint
getType()
Get message type, see OPCODE_*If text message, get body as stringboolean
isBinary()
Is binary messageboolean
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_*toString()
Get message as a string (use getValueString() to get the body value of text messages)
-
Field Details
-
DEFAULT_CLOSE_REASON
- See Also:
-
HEADER_SIZE_CONTROLFRAME
public static final int HEADER_SIZE_CONTROLFRAME- See Also:
-
MASK_SIZE
public static final int MASK_SIZE- See Also:
-
OPCODE_UNKNOWN
public static final int OPCODE_UNKNOWN- See Also:
-
OPCODE_CONTINUATION
public static final int OPCODE_CONTINUATION- See Also:
-
OPCODE_TEXT
public static final int OPCODE_TEXT- See Also:
-
OPCODE_BINARY
public static final int OPCODE_BINARY- See Also:
-
OPCODE_CLOSE
public static final int OPCODE_CLOSE- See Also:
-
OPCODE_PING
public static final int OPCODE_PING- See Also:
-
OPCODE_PONG
public static final int OPCODE_PONG- See Also:
-
-
Constructor Details
-
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 Details
-
createMessagePing
Create a ping message (body will be 8-byte UTC in millseconds)- Parameters:
mask
- true, to mask message- Returns:
- WebSocketMessage
-
createMessagePing
Create ping message- Parameters:
mask
- true, to mask messagebody
- bytes to include as body of message- Returns:
- WebSocketMessage
-
createMessagePong
Create pong message- Parameters:
mask
- true, to mask messagemessagePing
- ping message that is source of pong (body copied to pong message)- Returns:
- WebSocketMessage
-
createMessageClose
Create a close message- Parameters:
mask
- true, to mask messagereasonCode
- reason code, see IWebSocketSession.CLOSECODE_*reasonStr
- reason string, see IWebSocketSession.CLOSESTR_*- Returns:
- WebSocketMessage
-
createMessageText
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
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
If close message, get the close reason str- Returns:
- close reason str (null if not close message or no reason)
-
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
Get message as a string (use getValueString() to get the body value of text messages)
-