Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. // JavaScript Document
  2.  
  3. // Initialize Firebase
  4. var config = {
  5. apiKey: "AIzaSyDuQZCwIWwWO8SftZHHVax3eNmwvy6YGj0",
  6. authDomain: "captiate-variables.firebaseapp.com",
  7. databaseURL: "https://captiate-variables.firebaseio.com",
  8. projectId: "captiate-variables",
  9. storageBucket: "captiate-variables.appspot.com",
  10. messagingSenderId: "844765632528"
  11. };
  12.  
  13. firebase.initializeApp(config);
  14. var firestore = firebase.firestore();
  15. const docRef = firestore.collection("variables").doc("spkoOZ4GZloduEGIYTxM");
  16.  
  17.  
  18. //listen for Captivate to tell us it's loaded and ready
  19. window.addEventListener("moduleReadyEvent", function(evt) {
  20. //evt.Data carries the interface object.
  21. //It is same as window.cpAPIInterface
  22. var interfaceObj = evt.Data;
  23. var eventEmitterObj = interfaceObj.getEventEmitter();
  24.  
  25. //listen for variable change
  26. cpAPIEventEmitter.addEventListener("CPAPI_VARIABLEVALUECHANGED",
  27. function(){updateVariable(
  28. "variables",
  29. "spkoOZ4GZloduEGIYTxM",
  30. "hotDogStatus",
  31. window.cpAPIInterface.getVariableValue("v_visited")
  32. )},"v_visited");
  33. });
  34.  
  35.  
  36. function updateVariable(collection, doc, variable, newValue){
  37. firestore.collection(collection).doc(doc).set({
  38. variable: newValue
  39. }).then(function() {
  40. console.log("Document "+ variable +" successfully updated to: " + newValue);
  41. }).catch(function(error) {
  42. console.error("Error writing document: " + variable, error);
  43. });
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement