github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/examples/webchat/web/app.js (about)

     1  if (!window.location.origin) { // Some browsers (mainly IE) do not have this property, so we need to build it manually...
     2    window.location.origin = window.location.protocol + '//' + window.location.hostname + (window.location.port ? (':' + window.location.port) : '');
     3  }
     4  
     5  
     6  var sock = new SockJS(window.location.origin+'/echo')
     7  
     8  sock.onopen = function() {
     9  	// console.log('connection open');
    10  	document.getElementById("status").innerHTML = "connected";
    11  	document.getElementById("send").disabled=false;
    12  };
    13  
    14  sock.onmessage = function(e) {
    15  	document.getElementById("output").value += e.data +"\n";
    16  };
    17  
    18  sock.onclose = function() {
    19  	// console.log('connection closed');
    20  	document.getElementById("status").innerHTML = "disconnected";
    21  	document.getElementById("send").disabled=true;
    22  };