Working on live-notifications

stable
Jesús Espino 2017-03-30 16:11:57 +02:00
parent 74c66fba62
commit 7ed0d32e3f
1 changed files with 30 additions and 0 deletions

View File

@ -87,6 +87,35 @@ class EventsService
@liveAnnouncementService.show(data.title, data.desc)
@rootScope.$digest()
liveNotifications: ->
userId = @.auth.userData.get('id')
subscribe = () =>
@.subscribe null, "live_notifications.#{userId}", (data) =>
notification = new Notification(data.title, {
icon: "/#{window._version}/images/favicon.png",
body: data.body,
tag: data.id
})
notification.onshow = () =>
if data.timeout and data.timeout > 0
setTimeout =>
notification.close()
,
data.timeout
if data.url
notification.onclick = () =>
window.open data.url
if !Notification
console.log("This browser does not support desktop notification")
else if Notification.permission == "granted"
subscribe()
else if Notification.permission != 'denied'
Notification.requestPermission (permission) =>
if (permission == "granted")
subscribe()
###########################################
# Heartbeat (Ping - Pong)
###########################################
@ -216,6 +245,7 @@ class EventsService
@.sendMessage(message)
@.startHeartBeatMessages()
@.notifications()
@.liveNotifications()
onMessage: (event) ->
@.log.debug "WebSocket message received: #{event.data}"