Firebase allows for real-time database synchronization for all connected clients
var database;
function setup() {
// Initialize Firebase, these values can be obtained in the Firebase web app
var config = {
apiKey: "#######",
authDomain: "#######",
databaseURL: "########",
projectId: "########",
storageBucket: "",
messagingSenderId: "#######"
};
firebase.initializeApp(config);
database = firebase.database();
var ref = database.ref('sketches'); //table or 'Node' you want to open a reference on
ref.on('value', gotData, errData);
}
//Data will come in as an object with properties, where each property name is the unique GUID for that record
function gotData(data){
items = [];
var value = data.val();
for(key in value){
items.push(value[key]);
}
}
function errData(error){
console.log(error);
}
function saveData(){
var data = currPath.format();
if(currPath.key == null){
var res = database.ref('sketches').push(data); //Add new records
currPath.key = res.key;
} else {
var ref = database.ref('sketches/' + currPath.key); //Update a record
if(ref != null){
ref.set(data);
} else {
currPath.key = null;
saveData();
}
}
}