Notify users when the browser is minimized - javascript

I am using AngularJS & SPring. I need to find a way to notify the users even when the user has minimized the application browser window OR IS there any other better option to notify the users based on a batch job.

Maybe you are looking for something like Browser Desktop Notification.
I just found this LINK and maybe this could help you.
angular.module('app', ['notifyme']). controller('appcontroller', function($scope, NotifyMe) {
$scope.nofity = function(){
var title = "I'm from Angular ?";
var body = 'This is a simple demo for the notification API Angular Service';
NotifyMe.launch(title, {
body: body,
onclick:function(){
console.log("On Click Triggered");
},
onerror:function(){
console.log("On Error Triggered");
},
onclose:function(){
console.log("On Close Triggered");
}
});
};
});
Working Fiddle from the link:

Related

Javascript/jQuery beforeunload and unload not firing

I have a page where I want my script to let the server know that the user went offline when the browser/tab/page is closed.
$(document).ready(function() {
// Inform the server that the user went online
setStatus('online');
// Inform the server that the user went offline
$(window).on('beforeunload', function() {
setStatus('offline');
});
// Inform the server that the user went offline
$(window).on('unload', function() {
setStatus('offline');
});
});
async function setStatus(status) {
let { data } = await axios.post('/status', { status: status });
}
The part where I have setStatus('online'); works but I can never seem to set the status to offline when I close the page/tab/browser.
Looking around, I found this really nice answer - I just had to put this on my server.js file:
peer.oniceconnectionstatechange = function() {
if(peer.iceConnectionState == 'disconnected') {
console.log('Disconnected');
}
}
It does take a few seconds before it registers that the peer has dropped but at least it's always firing and that's reliable enough for me.

navigator.notification.alert iOS

My alert on ios project doesn't work. I'm using ionic and angularjs to develop my app.
The problem is that when alert is show, the title is "index.html". Actually I call alert like this:
alert("aaa");
I read that cordova allows to change title, using navigator.notification.alert. But the alert is not show when I call it.
I call alert as below:
.controller('MyCtrl',function(){
$scope.myfunction = function(){
var success = function(data){
//do something
};
var failure = function(message){
navigator.notification.alert(
"This is my Alert text!",
callBackFunctionB, // Specify a function to be called
'Alert Title',
"OK"
);
};
function callBackFunctionB(){
console.log('ok');
}
}
});
I add plugin and add key in infoplist following instructions in phonegap documentation.
Anyone can help me?
I tried to remove plugin and reinstall it and now it work.

Can I use gamepads with Node-Webkit (NW.js)?

I am building a NW.js (Node-Webkit) dashboard app which I want to be able to control with a game controller (for example: XBox 360 controller or Logitech controller).
I'm calling the following onready but when I debug its not recognizing any gamepads.
angular.element(document).ready(function() {
if(canGame()) {
var prompt = "To begin using your gamepad, connect it and press any button!";
$("#gamepadPrompt").text(prompt);
$(window).on("gamepadconnected", function() {
$("#gamepadPrompt").html("Gamepad connected!");
console.log("connection event");
});
$(window).on("gamepaddisconnected", function() {
console.log("disconnection event");
$("#gamepadPrompt").text(prompt);
});
}
});
function canGame() {
return "getGamepads" in navigator;
}
When I debug the code, it doesn't appear to be detecting any gamepads. I also try:
navigator.webkitGetGamepads()
but it doesn't show any gamepads being detected either.
Has anyone successfully used gamepads with a NW.js app?
I would greatly appreciate some help getting this to work.
I found the answer to my issue. Gamepads are indeed compatible with NW.js. I however, was using an old version (~v0.08).
The code I posted earlier when running with NW.js v0.12.2.

Unable to connect to styled receiver

I am trying to build a simple JS based web app that starts a styled media receiver(hosted by Google, reads your custom CSS file). I have a developer account set up and have gone through adding the app in my account. I made sure to select the "Styled Media Receiver" type when I created it.
I am using the basic setup described here to construct my sender. I was able to get this code to work with a custom receiver. I can see in my log that the extension is detected.
Found cast extension: boadgeojelhgndaghljhdicfkmllpafd
I set up my session request with the app ID provided on the Cast developer's console.
var sessionRequest = new chrome.cast.SessionRequest(id);
Then I call:
var apiConfig = new chrome.cast.ApiConfig(this.sessionListener.bind(this),
this.receiverListener.bind(this));
Which returns the value "unavailable" to the "receiverListener" function. When I try to request a session it returns the error callback with the following data:
Object {code: "receiver_unavailable", description: null, details: null}
So, I am trying to figure out what I might be missing. Like I said I've used the same code to launch a custom receiver successfully. Here is the full code that I am using:
Polymer({
ready: function(){
window['__onGCastApiAvailable'] = function(loaded, errorInfo){
if(loaded){
this.initCast();
}
else{
console.log(errorInfo);
}
}.bind(this);
},
initCast: function(){
var id = "731AC858";
var sessionRequest = new chrome.cast.SessionRequest(id);
var apiConfig = new chrome.cast.ApiConfig(sessionRequest,
this.sessionListener.bind(this),
this.receiverListener.bind(this));
chrome.cast.initialize(apiConfig,
this.initCastSuccess.bind(this),
this.initCastError.bind(this));
},
initCastSuccess: function(){
this.castReady = true;
},
initCastError: function(e){
console.log(e);
},
startCast: function(){
chrome.cast.requestSession(this.startCastSuccess.bind(this),
this.startCastError.bind(this));
},
startCastSuccess: function(e){
console.log(e);
},
startCastError: function(e){
console.log(e); //returns Object {code: "receiver_unavailable", description: null, details: null} when "startCast" is called.
},
sessionListener: function(e){
console.log(e);
},
receiverListener: function(e){
console.log(e);//returns "unavailable"
},
});
Well it looks like I was either being impatient and it takes a while for the app to digest, or the server that hosts the Styled media receiver was down for a while. I tried it today and everything is working great.
----UPDATE----
I just tried creating a fresh styled media receiver app, and I can't get it to connect. So my guess is that there is something that has to be prepped before you can start using it.

setInterval() not working after window.open() in Android

Just a little problem: I'm making a Hybrid app developed in angular with Cordova but when I use a setInterval() function after a $window.open() the setInterval stops working, but in Chrome, it's working (but it's normal, the new window is opened in a new tab).
This is the an extract of my code :
$http.post(url)
.success(function(result, status) {
var windowWithings = $window.open(result.res);
var intervalVerif = $window.setInterval(function (){
$http.get(url)
.success(function(result) {
windowWithings.close();
$window.cancelInterval(intervalVerif);
})
.error(function(error) {
console.log(error);
});
}, 2000);
})
.error(function(error, status) {
console.log(status);
});
Thanks in advance!
EDIT:
What I searching to do with the setInterval is to check each 2000 ms if the server got the information from the new window I have opened. If it's ok for the server I close the window to come back to the previous.
When I say it's not working I want to say that the new window doesn't close but if I change the code with an alert I can see sometimes an alert before the new window had the time to open but nothing after
For Chrome, I just say that if I open the Angular app in Chrome on my laptop it's working, but if I launch my Android app created with Cordova it doesn't work.
please use $timeout and add '$timeout' in injection parameters
$timeout(function (){
$http.get(url)
.success(function(result) {
windowWithings.close();
$window.cancelInterval(intervalVerif);
})
.error(function(error) {
console.log(error);
});, 2000);

Categories