I started using Firebase a couple of weeks ago, and had Firebase Queue running on my node.js server code. Clients could push messages to queue/tasks, and the server would resolve them. I cannot replicate this after Firebase has changed to version 3, even though Firebase Queue has been updated and no-one else seems to be having problems. It is probably just a minor bug in my code, but I haven't found it after a couple of days, and I would appreciate it if someone could point it out for me.
Here I have my server code. It should print to the console whenever a task is added to the queue, but it isn't. The push on the last line demonstrates that it is able to connect to the server.
var firebase = require('firebase');
var Queue = require('firebase-queue');
firebase.initializeApp({
serviceAccount: 'serviceAccountCredentials.json',
databaseURL: 'https://heretikchess-250ed.firebaseio.com/'
});
var ref = firebase.database().ref('queue');
var queue = new Queue(ref, function(data, progress, resolve, reject) {
console.log('This should print whenever a task is pushed onto the queue.')
console.log(data);
setTimeout(function() {
resolve();
}, 1000);
});
ref.push('this is a push from the server');
//This push works fine, so there's no problem connecting to the server.
And here is my client code. The pushes to queue/tasks are successful.
<!doctype html>
<html lang='en'>
<head>
<meta charset="utf-8">
<title>Why won't my code work?</title>
<script src="https://www.gstatic.com/firebasejs/3.0.0/firebase.js"></script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
</head>
<body>
<div>
<h3>Submit push to firebase</h3>
<button id='submitbutton' class='btn btn-default' type='button'>Submit</button>
</div>
<script>
var config = {
apiKey: "AIzaSyCJKI3tjnnuOIcx2rnOuSTUgncuDbbxfwg",
authDomain: "heretikchess-250ed.firebaseapp.com",
databaseURL: "https://heretikchess-250ed.firebaseio.com",
storageBucket: "heretikchess-250ed.appspot.com",
};
firebase.initializeApp(config);
var ref = firebase.database().ref('queue/tasks');
//Send message to queue/tasks
$('#submitbutton').click(function() {
ref.push('this is a push from the client');
})
</script>
</body>
</html>