var ws; function logging(log) { console.log(log); } function connectSocketServer(port, callback) { var support = "MozWebSocket" in window ? 'MozWebSocket' : ("WebSocket" in window ? 'WebSocket' : null); // logging("connectSocketServer-support:" + support) if (support == null) { // //たっちなうコンポーネントによる打刻 // var object = document.getElementById("Reader"); // if (object == null) { // window.alert('object == null'); // var newObject = document.createElement("object"); // newObject.setAttribute("id", "Reader"); // newObject.setAttribute("classid", "CLSID:78360229-738D-4E15-BFAC-D448543C6BC1"); // newObject.setAttribute("codebase", "https://www.hayato.info/touchnowcomponent.cab#version=1,0,0,3"); // document.body.appendChild(newObject); // } // return; } else { //WebSocketによる打刻 disconnectWebSocket(); ws = new window[support]('ws://127.0.0.1:' + port + '/'); ws.onmessage = function (evt) { logging(evt.data); var uid = JSON.parse(evt.data).tagid; onSocketReceiveUID(uid); }; ws.onopen = function () { logging("onopen"); onSocketConnect(true); }; ws.onclose = function () { logging("onclose"); onSocketConnect(false); } } } function disconnectWebSocket() { logging("disconnectWebSocket") if (ws) { ws.close(); } } function send(message){ ws.send(message); } function connectSocket(port) { logging("connectSocket:" + port) connectSocketServer(port); }