# HG changeset patch # User Thierry Florac # Date 1542732555 -3600 # Node ID 19e28ae921daf32ab252bfe7d47283b79ce56099 # Parent cd8c5dc6fa9ea0a5de6c52703fbbee14809e80e6 Corrected current window protocol test to activate secured websockets when needed diff -r cd8c5dc6fa9e -r 19e28ae921da src/pyams_notify/skin/resources/js/pyams_notify.js --- a/src/pyams_notify/skin/resources/js/pyams_notify.js Fri Nov 16 15:20:22 2018 +0100 +++ b/src/pyams_notify/skin/resources/js/pyams_notify.js Tue Nov 20 17:49:15 2018 +0100 @@ -12,7 +12,7 @@ var tcp_handler = $('[data-ams-notify-server]', '#user-activity').data('ams-notify-server'); if (tcp_handler) { var protocol = 'ws'; - if (window.location.protocol === 'https') { + if (window.location.protocol === 'https:') { protocol += 's'; } var ws = $.WebSocket(protocol + '://' + tcp_handler + '/subscribe'); diff -r cd8c5dc6fa9e -r 19e28ae921da src/pyams_notify/skin/resources/js/pyams_notify.min.js --- a/src/pyams_notify/skin/resources/js/pyams_notify.min.js Fri Nov 16 15:20:22 2018 +0100 +++ b/src/pyams_notify/skin/resources/js/pyams_notify.min.js Tue Nov 20 17:49:15 2018 +0100 @@ -1,1 +1,1 @@ -!function(f,n){"use strict";var l=n.MyAMS,d={connection:null,initConnection:function(){var t=f("[data-ams-notify-server]","#user-activity").data("ams-notify-server");if(t){var n="ws";"https"===window.location.protocol&&(n+="s");var o=f.WebSocket(n+"://"+t+"/subscribe");o.onopen=d.onSocketOpened,o.onmessage=d.onSocketMessage,o.onerror=d.onSocketError,o.onclose=d.onSocketClosed,d.connection=o,setInterval(d.checkConnection,3e4)}},checkConnection:function(){null!==d.connection&&d.connection.readyState!==WebSocket.CLOSED||d.initConnection()},onSocketOpened:function(t){n.console&&n.console.debug("WS notifications connection opened"),l.ajax.post("get-notifications-context.json",{},function(t){""!==t.principal.id&&(d.connection.send(JSON.stringify({action:"subscribe",principal:t.principal,context:t.context})),l.ajax.post("get-user-notifications.json",{},d.showNotifications))})},onSocketMessage:function(t){var n=JSON.parse(t.data);d.notifyOnDesktop(n),d.notifyInWebpage(n)},onSocketError:function(t){n.console&&n.console.log(t)},onSocketClosed:function(t){d.connection=null,n.console&&n.console.debug("WS connection closed")},notifyOnDesktop:function(n){function o(){var t={title:n.title,body:n.message,icon:n.source.avatar};new Notification(t.title,t).onclick=function(){n.url&&window.open(n.url)}}window.Notification&&"denied"!==Notification.permission&&("default"===Notification.permission?Notification.requestPermission(function(t){"granted"===t&&o()}):o())},createNotification:function(t){var n=f("
  • "),o=f(""),i=f("").addClass("msg").attr("href",t.url);return t.source.avatar?f("").addClass("air air-top-left margin-top-2").attr("src",t.source.avatar).appendTo(i):f("").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(i),f("").text(t.timestamp).appendTo(i),f("").addClass("from").text(t.source.title).appendTo(i),f("").addClass("msg-body").text(t.message).appendTo(i),i.appendTo(o),o.appendTo(n),n},notifyInWebpage:function(t){var n=f(".badge","#user-activity >span"),o=parseInt(n.text());n.text(o+1);var i=f(".notification-body","#user-activity");d.createNotification(t).prependTo(i),l.skin.checkNotification()},showNotifications:function(t){var n=t.timestamp,o=t.notifications,i=f(".badge","#user-activity >span"),e=f(".notification-body","#user-activity"),a=f("li",e).length;if(e.empty(),0"),i=t(""),e=t("").addClass("msg").attr("href",n.url);return n.source.avatar?t("").addClass("air air-top-left margin-top-2").attr("src",n.source.avatar).appendTo(e):t("").addClass("fa fa-2x fa-user air air-top-left img margin-left-5 margin-top-2").appendTo(e),t("").text(n.timestamp).appendTo(e),t("").addClass("from").text(n.source.title).appendTo(e),t("").addClass("msg-body").text(n.message).appendTo(e),e.appendTo(i),i.appendTo(o),o},notifyInWebpage:function(n){var e=t(".badge","#user-activity >span"),a=parseInt(e.text());e.text(a+1);var c=t(".notification-body","#user-activity");i.createNotification(n).prependTo(c),o.skin.checkNotification()},showNotifications:function(n){var e=n.timestamp,a=n.notifications,c=t(".badge","#user-activity >span"),s=t(".notification-body","#user-activity"),r=t("li",s).length;if(s.empty(),a.length>0){s.prev("p").hide();for(var p=0;p