Question

I'm interested in using Firebase, but have some questions.

One demo I'm really interested in is the drawing demo: https://www.firebase.com/tutorial/#session/lijxbwexqv1

The key thing I'm curious about is how sessions in Firebase are handled and established. How is a random session key being created, and also how is it being put in the URL to establish where the data is coming from (see code below).

//Create a reference to the pixel data for our drawing.
var pixelDataRef = new Firebase('https://lijxbwexqv1.firebaseio-demo.com/');

I'd like to create an educational app. Where the user is shown a picture of something, and then on their phone are seeing corresponding information to the picture they're being shown. I know this is different from the drawing demo, but the concepts of sessions is similar. Basically each user would have a "session" or a firebase data set--that they could access using a custom URL.

Any help or pointers (docs even) regarding the establishment and storage sessions would be greatly appreciated.

Thanks in advanced.

Était-ce utile?

La solution

The "session" keys are random strings. They are generated in the source as follows:

UserSession.prototype.generateSessionID_ = function () {
  if (window.isDebugMode) {
    return "chat";
  } else {
    var chars = "abcdefghijklmnopqrstuvwxyz0123456789";
    var retVal = chars.charAt(Math.floor(Math.random() * 26, 1));
    for (var i = 0; i < 10; i++) {
      retVal = retVal + chars.charAt(Math.floor(Math.random() * chars.length, 1));
    }
    return retVal;
  }
}

You could also simply use Firebase.push(), which generates random ids that also serve as sequential, chronological record ids:

function generateSessionId(ref) {
   return ref.push().name();
}

var fb = new Firebase(URL);
console.log( generateSessionId(fb) );
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top