github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/igm/sockjs-go.v2/examples/webecho/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 var origin = window.location.origin; 6 7 // options usage example 8 var options = { 9 debug: true, 10 devel: true, 11 protocols_whitelist: ['websocket', 'xdr-streaming', 'xhr-streaming', 'iframe-eventsource', 'iframe-htmlfile', 'xdr-polling', 'xhr-polling', 'iframe-xhr-polling', 'jsonp-polling'] 12 }; 13 14 var sock = new SockJS(origin+'/echo', undefined, options); 15 16 sock.onopen = function() { 17 //console.log('connection open'); 18 document.getElementById("status").innerHTML = "connected"; 19 document.getElementById("send").disabled=false; 20 }; 21 22 sock.onmessage = function(e) { 23 document.getElementById("output").value += e.data +"\n"; 24 }; 25 26 sock.onclose = function() { 27 document.getElementById("status").innerHTML = "connection closed"; 28 //console.log('connection closed'); 29 }; 30 31 function send() { 32 text = document.getElementById("input").value; 33 sock.send(document.getElementById("input").value); return false; 34 }