Skip to content

WebSocket Class

wagyourtail edited this page Jul 23, 2020 · 6 revisions

1.1.8+ (broken until first 1.1.9 beta)

the WebSocket class extends WebSocketClient

WebSocket(String) 1.1.8+

Example: new WebSocket(uri)

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

onOpen 1.1.8+

put a function here for callback. Example:

ws.onOpen = (webSocket, handshake) => {
    chat.log(handshake.getHttpStatusMessage());
}

onMessage 1.1.8+

put a function here for callback. Example:

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

onClose 1.1.8+

put a function here for callback. Example:

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

onError 1.1.8+

put a function here for callback. Example:

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

closeData class 1.1.8+

class {
    this.code; //int status code
    this.reason; //string reason
    this.remote; //boolean

    constructor(code, reason, remote);
}
Clone this wiki locally