I am facing a major issue in sending data from my StartingWebGazer service to WorkspaceController.js. The startingWebGazer service utilizes webgazer.js to evaluate prediction points, which are then passed to the xprediction and yprediction variables within StartingWebGazer.js.
app.service('startingWebGazer', function () {
this.startgazer = function () {
window.onload = function () {
webgazer.setRegression('ridge') /* must set regression and tracker */
.setTracker('clmtrackr')
.setGazeListener(function (data, elapsedTime) {
if (data == null) {
return
}
var xprediction = data.x; //x coordinates relative to viewport
console.log(xprediction);
return xprediction;
}).begin()
.showPredictionPoints(true);
var setup = function () {
var canvas = document.getElementById("plotting_canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
canvas.style.position = 'fixed';
};
function checkIfReady() {
if (webgazer.isReady()) {
setup();
} else {
setTimeout(checkIfReady, 100);
}
}
setTimeout(checkIfReady, 100);
};
window.onbeforeunload = function () {
console.log('user wants to leave the page');
window.localStorage.clear();
}
}});
I need to pass xprediction to WorkspaceController.js for future evaluations within the controller.
app.controller('WorkspaceController', ['$scope', 'startingWebGazer', function ($scope, startingWebGazer) {
$scope.startingWebGazer = startingWebGazer;
console.log($scope.startingWebGazer);
console.log('data in workspace', $scope.startingWebGazer.startgazer());}]);
However, I am encountering an issue where startgazer is undefined even though xprediction evaluates correctly (as shown by the console.log output). https://i.sstatic.net/Jj6gy.png
What could be causing this problem? Why can I see xprediction in the console.log but not pass it to the controller? What steps should I take to resolve this?