After 2 days of try and error I finally get the result I want. But I think this is the dumbest way to check Websocket connection.

The internet suggestions that I should use try and catch. But never play with it before I have no idea where to begin with.
var ws = "ws://"
  , ww = "ws://";

var x = new WebSocket(ws);
x.onopen = function() {

var y = new WebSocket(ww);
y.onopen = function() {

var xx  = function(w) {

var yy = function(i) {
The reason I check WebSocket connection is that some places have blocked a certain port connection such as workplace blah blah blah (port 80 is being use by PHP --> Apache to be exact). With port availability check up, people may be able to access to my app from anywhere.

PS: some place does not block any port and I want I use only one port at the time.
Thank you,