Working on live-notifications
parent
74c66fba62
commit
7ed0d32e3f
|
@ -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}"
|
||||
|
|
Loading…
Reference in New Issue