var FileHandler = function(event) { // console.log(event); data = event.data; // console.log(" -->" + data); try { var obj = JSON.parse(data); switch (obj.action) { case 'ping': case 'poing': break; case 'onListProjects': onListProjects(obj); break; case 'onListProject': onListProject(obj); break; case 'onListFile': onListFile(obj); break; case 'onDeleteFile': onDeleteFile(obj); break; case 'onRenameFile': onRenameFile(obj); break; case 'onSaveFile': onSaveFile(obj); default: logComm(obj); break; } } catch (err) { console.log(err); } }; var logComm = function(obj) { console.log(obj); }; var getFileWsUrl = function(host) { var prefix = "ws://"; if (document.location.href.startsWith("https")) prefix = "wss://"; var path = document.location.pathname.lastIndexOf("/"); path = document.location.pathname.substr(0, path + 1); path += "Projects"; return prefix + host + path; }; var getHost = function() { var host = $("#targetHost"); if (host.length == 0) host = document.location.host; else host = host[0].value; return host; } var initFileController = function() { var host = getHost(); var url = getFileWsUrl(host); url = localStorage.cmaddr; // console.log("[ideapi22] addr:" + url); var wssocket = new WebSocket(url); global.filewssocket = wssocket; wssocket.onerror = function(error) { console.log(error); }; wssocket.onopen = function(error) { var pingObj = {}; pingObj.action = "ping"; wssocket.send(JSON.stringify(pingObj)); listProjects(); listDumpMemoryDir(); }; wssocket.onmessage = FileHandler; // ===========init fileTabDiv $("#se2").selectmenu(); $("#tabdiv").editableSelect({ filter : false }); }; var listDumpMemoryDir = function() { var pingObj = {}; pingObj.action = "listProject"; pingObj.project = "memoryDumps"; global.filewssocket.send(JSON.stringify(pingObj)); } // ====== wsHandler var onListProjects = function(obj) { var data = JSON.parse(obj.data); global.projects = data; var html = "