UNPKG

htd-lync

Version:

This library is meant to be used to interact with an HTD Lync 12

81 lines (67 loc) 2.08 kB
var socket; var backupSocket = io.connect("165.227.53.38:5000", { 'auto connect': true, 'connection timeout': 5000, 'max reconnection limit': 1000000000, 'secure': false }); backupSocket.on('connect', function() { console.log("Connected to backup socket") //backupData(); }); backupSocket.on('restoreData', function(data) { console.log("got restore data"); console.log(data.data[0]); if (!data) { alert("Profile not found, did you back it up to cloud first?"); return; } var restoreData = JSON.parse(data.data[0]); restoreData.system.ip = systems[systemIdx].system.ip; console.log("Final IP:" + restoreData.system.ip) // groups = restoreData.groups; // presets = restoreData.presets; // shortcuts = restoreData.shortcuts; // systems[systemIdx].system = restoreData.system; systems[systemIdx] = restoreData; updateData(); alert("Settings Restored Successfully, the app will now restart"); window.location.reload(true); }); // TCP communication part for cordova plugin function arrayBuffer2HEX(buf) { var gbuf = new Uint8Array(buf, 0); var dat = ""; for (var i in gbuf) { dat += gbuf[i].toString(16) + " "; } return dat; } function str2arrayBuffer(str) { var buf = new ArrayBuffer(str.length); var bufView = new Uint8Array(buf); for (var i = 0; i < str.length; i++) { bufView[i] = str.charCodeAt(i); } return buf; } function backupData(profile) { var answer = confirm("This will overwrite your current backup, are you sure?"); console.log(answer); if (answer == true) { var data = { systemID: systems[systemIdx].system.uuid + "-" + profile, data: JSON.stringify(systems[systemIdx]) } console.log(data); backupSocket.emit('backupData', data); alert("Settings successfully backed up to cloud!"); } } function restoreData(profile) { var answer = confirm("This will overwrite your current settings, are you sure?"); console.log(answer); if (answer == true) { backupSocket.emit("restoreData", systems[systemIdx].system.uuid + "-" + profile) } }