Object built-in object

Object WebSocketMessage

websocket message object

Creation method:

1 2 3
var ws = require("ws"); var msg = new ws.Message();

Inheritance

Constructor

WebSocketMessage

Package processing message object constructor

1 2 3 4
new WebSocketMessage(Integer type = ws.BINARY, Boolean masked = true, Boolean compress = false, Integer maxSize = 67108864);

Call parameters:

  • type : Integer, websocket message type, the default is websocket.BINARY
  • masked : Boolean, websocket message mask, the default is true
  • compress : Boolean, mark whether the message is compressed, the default is false
  • maxSize : Integer, the maximum packet size, in MB, the default is 67108864 (64M)

constant

TEXT

Specify message type 1, which represents a text type

1
const WebSocketMessage.TEXT = 1;

BINARY

Specify message type 2, which represents a binary type

1
const WebSocketMessage.BINARY = 2;

Member attributes

masked

Boolean, query and read websocket mask mark, default is true

1
Boolean WebSocketMessage.masked;

compress

Boolean, query and read websocket compression status, default is false

1
Boolean WebSocketMessage.compress;

maxSize

Integer, query and set the maximum packet size, in bytes, the default is 67108864 (64M)

1
Integer WebSocketMessage.maxSize;

value

String, the basic content of the message

1
String WebSocketMessage.value;

params

NArray, the basic parameters of the message

1
readonly NArray WebSocketMessage.params;

type

Integer, message type

1
Integer WebSocketMessage.type;

data

Value, query the data of the message

1
readonly Value WebSocketMessage.data;

body

SeekableStream , a stream object containing the data part of the message

1
SeekableStream WebSocketMessage.body;

length

Long, the length of the message data part

1
readonly Long WebSocketMessage.length;

stream

Stream , the stream object when querying the message readFrom

1
readonly Stream WebSocketMessage.stream;

lastError

String, query and set the last error of message processing

1
String WebSocketMessage.lastError;

Member function

read

Read data of the specified size from the stream, this method is an alias of the corresponding method of body

1
Buffer WebSocketMessage.read(Integer bytes = -1) async;

Call parameters:

  • bytes : Integer, specify the amount of data to be read, the default is to read random-sized data blocks, the size of the data read depends on the device

Return result:

  • Buffer , returns the data read from the stream, if there is no data to read, or the connection is interrupted, it returns null

readAll

Read all remaining data from the stream, this method is an alias of the corresponding method of body

1
Buffer WebSocketMessage.readAll() async;

Return result:

  • Buffer , returns the data read from the stream, if there is no data to read, or the connection is interrupted, it returns null

write

Write the given data, this method is the alias of the corresponding method of body

1
WebSocketMessage.write(Buffer data) async;

Call parameters:

  • data : Buffer , given the data to be written

json

Write the given data in JSON encoding

1
Value WebSocketMessage.json(Value data);

Call parameters:

  • data : Value, given the data to be written

Return result:

  • Value , this method will not return data

Parse the data in the message in JSON encoding

1
Value WebSocketMessage.json();

Return result:

  • Value , returns the parsed result

end

Set the current message processing to end, and the Chain processor will not continue subsequent transactions

1
WebSocketMessage.end();

isEnded

Query whether the current message is over

1
Boolean WebSocketMessage.isEnded();

Return result:

  • Boolean , return true at the end

clear

Clear the content of the message

1
WebSocketMessage.clear();

sendTo

Send a formatted message to the given stream object

1
WebSocketMessage.sendTo(Stream stm) async;

Call parameters:

  • stm : Stream , specifies the stream object that receives formatted messages

readFrom

Read the formatted message from the given cache stream object, and parse the filling object

1
WebSocketMessage.readFrom(Stream stm) async;

Call parameters:

  • stm : Stream , specifies the stream object for reading formatted messages

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String WebSocketMessage.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value WebSocketMessage.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable