title: How to manage correctly websocket messages?
body: <p>I have a webpage which communicate via WebSocket with a WinForm, it's the first time i'm using WebSocket, and i've set a json structure for the communication with my webpage then by checking the json param &quot;type&quot; i do some stuff on it's value.</p>
  <p>Till now it's a chain of <code>else if</code> but it is the correct way to manage it?</p>
  <p>Here is how my code looks like:</p>
  <pre><code>  websocket.onmessage = function (e) {
      var data = JSON.parse(e.data);
      if (data.type === &quot;err_login&quot;) {
        var feedback = $(&quot;#modalLogin .invalid-feedback&quot;);
        $(&quot;#modalLogin .codope&quot;).val(&quot;&quot;);
        $(&quot;#modalLogin .password&quot;).val(&quot;&quot;);
        feedback.find(&quot;h5&quot;).text(data.content.title);
        feedback.addClass(&quot;d-block&quot;);
      } else if (data.type === &quot;err&quot;) {
        var content = data.content;
        Swal.fire({
          heightAuto: false,
          title: content.title,
          text: content.text,
          icon: &quot;warning&quot;,
          allowOutsideClick: false,
          showDenyButton: true,
          buttonsStyling: false,
          customClass: {
            confirmButton: &quot;btn btn-lg btn-primary btn-swal&quot;,
            denyButton: &quot;btn btn-lg btn-warning ml-3 btn-swal&quot;,
          },
          confirmButtonText: &quot;OK&quot;,
          denyButtonText: arrLang[lang][&quot;assistenza&quot;],
        }).then((result) =&gt; {
          if (result.isDenied) {
            $(&quot;#modalAssistenza&quot;).modal(&quot;show&quot;);
          }
        });
      } else if (data.type === &quot;prod&quot;) {
        addProdotto(data.content);
      } else if (data.type === &quot;sbt&quot;) {
        subtotale(data.content);
      } else if (data.type === &quot;fid&quot;) {
        addFidelity(data.content);
      } else if (data.type === &quot;lot&quot;) {
        addLotteria(data.content.lotteria);
      } else if (data.type === &quot;reset&quot;) {
        reset();
      } else if (data.type === &quot;closed&quot;) {
        $(&quot;#modalOffline&quot;).modal(&quot;show&quot;);
      } else if (data.type === &quot;lang&quot;) {
        changeLanguage(data.content.lang);
      }else if (data.type === &quot;payement_text&quot;) {
        setPaymentText(data.content)
      }else if (data.type === &quot;payement_success&quot;) {
        var content = data.content;
        Swal.fire({
          heightAuto: false,
          title: content.title,
          text: content.text,
          icon: &quot;success&quot;,
          showConfirmButton: false,
          allowOutsideClick: false,
          allowEscapeKey: false,
        })
      }else if (data.type === &quot;payement_success_close&quot;) {
        Swal.close();
      }else if (data.type === &quot;payement_error&quot;) {
        var content = data.content;
        Swal.fire({
          heightAuto: false,
          title: content.title,
          text: content.text,
          icon: &quot;error&quot;,
          allowOutsideClick: false,
          buttonsStyling: false,
          customClass: {
            confirmButton: &quot;btn btn-lg btn-primary btn-swal&quot;,
          },
          confirmButtonText: &quot;OK&quot;,
        }).then((result) =&gt; {
          if (result.isConfirmed) {
            websocket.send(`&lt;PAY&gt;&lt;/PAY&gt;`);
            pagamentoIndietro();
          }
        });
      }
    };
  </code></pre>
  <p>Should i manage it in a different way?</p>