A feature in my quiz app requires setting up a timer in the controller that counts for 30 seconds and stops the quiz if there is no activity within that time frame. The timer should reset and start counting again if there is any activity. I have implemented web socket listeners for this functionality. How can I correctly set up the timer?
This snippet shows my controller code:
angular.module('quiz.controllers')
.controller('MultiPlayerQuestionController', function(
$scope,
$rootScope,
$state,
$stateParams,
$timeout,
UserService,
QuizService,
InviteService,
MessageService,
SocketService
) {
// Controller logic here
});
I attempted to call the responseTimer function I created in the controller by initializing it at the beginning like this:
responseTimer(30000);
Later on, I defined the function as follows:
var responseTimer = function (time) {
responseTimer = $timeout(stopQuiz, time);
console.log('Started timer');
};
var resetResponseTimer = function () {
$timeout.cancel(responseTimer);
responseTimer(30000);
console.log("Timer reset");
};
However, I encountered an error message:
TypeError: responseTimer is not a function