Regarding the protocols
parameter, here's what the WHATWG Standard has to say:
protocols is either a string or an array of strings. If it is a string, it is equivalent to an array consisting of just that string; if it is omitted, it is equivalent to the empty array. Each string in the array is a subprotocol name. The connection will only be established if the server reports that it has selected one of these subprotocols. The subprotocol names have to match the requirements for elements that comprise the value of Sec-WebSocket-Protocol
fields as defined by The WebSocket protocol.
So refer to your server's implentation as to what to send for that parameter, if anything at all.
The "Can not 'send' WebSocket message when WebSocket state is CONNECTING" message shouldn't occur when connecting but very well could occur if you tried to send too soon; the message specifically occurs when send()
is called during the connecting phase. You can delay the send message until the connection is establashed as so:
const socket = new WebSocket('ws://159.89.92.113:4343');
socket.onopen = (event) => {
socket.send('Hello World');
};
Finally, here's a working end-to-end example of a WebSocket setup using a Tabris.js app as the client client with a websocket server:
https://github.com/eclipsesource/tabris-js/tree/2.x/examples/web-socket
Simply:
git clone https://github.com/eclipsesource/tabris-js
cd tabris-js
git checkout 2.x
cd examples/web-socket
npm install
tabris serve
and start the server in another window, from that same directory npm run server
*Note this was written for Tabris.js 2.x, so you'll either want to test it with a 2.x client or migrate it to 3.x.