JSFiddle - React, Tailwind, and code Playground

by bogdan_vq

JavaScript

var echoSocket = new WebSocket("ws://echo.websocket.org");

if(echoSocket.readyState === WebSocket.CONNECTING){
    console.log("connecting");
}
    
var msg = {
    type: "message",
    text: "value",
    id:   "2wf57f",
    date: Date.now()
  };

  // Send the msg object as a JSON-formatted string.
  //echoSocket.send(JSON.stringify(msg));


echoSocket.onopen = function(){
   
    
    
    if(echoSocket.readyState === WebSocket.OPEN){
         console.log("open");
    }
    
    if(echoSocket.readyState === WebSocket.CONNECTING){
         console.log("connecting");
    }
    
    //echoSocket.send("initial data");
    
}

echoSocket.onclose = function(e){
    
    console.log("close",e);
}
echoSocket.close(1000, "normal")