Skip to content

Websocket2 Class

wagyourtail edited this page Sep 20, 2020 · 5 revisions

1.1.9+

Websocket2(String) 1.1.9+

Example: new Websocket2(address)

Initialize, to call this it is easiest to refer to Request.

onConnect 1.1.9+

put a function here for callback. Example:

// headers is a map of String, List<String>

ws.onConnect = (webSocket, headers) => {
    chat.log(headers);
}

onTextMessage 1.1.9+

put a function here for callback. Example:

ws.onTextMessage = (webSocket, message) => {
    chat.log(message);
}

onDisconnect 1.1.9+

put a function here for callback. Example:

ws.onDisconnect = (webSocket, disconnect) => {
    chat.log(closeData.reason);
}

onError 1.1.9+

put a function here for callback. Example:

ws.onClose = (webSocket, err) => {
    chat.log(err);
}

onFrame 1.1.9+

put a function here for callback.

frame is of the WebSocketFrame type

Example:

ws.onFrame = (webSocket, frame) => {
    chat.log(frame);
}

connect() 1.1.9+

A function that tells the websocket to connect

returns this object

ws.connect()

close() 1.1.9+

A function that tells the websocket to close

returns this object

ws.close()

close(closeCode) 1.1.9+

A function that tells the websocket to close with a specified close code

returns this object

ws.close(1) // closes the connection with close code 1

sendText(text) 1.1.9+

A function that sends a text message to the websocket

returns this object

ws.sendText("text")

getWs() 1.1.9+

A function that returns the NeoVisionaries WebSocket object

realWs = ws.getWs()

Disconnect class 1.1.9+

class {
    this.serverFrame; //frame from server if it exists
    this.clientFrame; //frame from client always exists
    this.isServer; //boolean whether or not the remote server disconnected you

    constructor(serverFrame, clientFrame, isServer);
}
Clone this wiki locally