저는 node 및 socket.io를 처음 사용합니다. 방금 푸시 알림을 사용하여 Chrome 확장 프로그램을 완료했습니다. 크롬 브라우저가 닫히면 알림이 전송되지 않는 문제가 있습니다. 서버가 아래와 같이 알림을 보내고 알림이 전송되지 않습니다.노드 - 브라우저가 닫힐 때 알림 푸시
info - transport end (socket end)
debug - set close timeout for client kgcuzAOgn5-lrnuQI0Qb
debug - cleared close timeout for client kgcuzAOgn5-lrnuQI0Qb
debug - cleared heartbeat interval for client kgcuzAOgn5-lrnuQI0Qb
debug - discarding transport
여기 Pls는 날이 문제를 해결하는 데 도움이
서버
io.sockets.on('connection', function (socket) {
fs.watch('example.xml', function (curr, prev) {
fs.readFile('example.xml', function (err, data) {
if (err) throw err;
parser.parseString(data);
});
});
parser.addListener('end', function(result) {
// adding the time of the latest update
//result.time = new Date();
socket.volatile.emit('notification' , result);
});
});
클라이언트
var socket = new io.connect('http://website:8000');
console.log('client connected');
socket.on('notification', function(data){
console.log("message recieved1 = "+data);
console.log("message recieved = "+data);
showNotification(data)
chrome.browserAction.setBadgeText({ text : "1" });
});
function showNotification(data){
var havePermission = window.webkitNotifications.checkPermission();
if (havePermission == 0) {
// 0 is PERMISSION_ALLOWED
var notification = webkitNotifications.createNotification(
'http://website.com/favicon.ico', // icon url - can be relative
'Hello!', // notification title
data // notification body text
);
// Hide the notification after the configured duration.
//setTimeout(function(){ notification.cancel(); }, 5000);
notification.onclick = function() {
window.open("http://website.com/favicon.gif");
notification.close();
resetBadgeText();
}
chrome.browserAction.setBadgeText({"text":"1"});
notification.show();
} else {
window.webkitNotifications.requestPermission();
}
}
내 코드입니다.
아마도이 문제를 해결하려면 다음 작업을 수행 할 수 있습니다. http://stackoverflow.com/questions/3699357/event-calling-before-page-unload – TheHippo