Built files from Bizgaze WebServer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

notifier.js 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  2. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. var Unibase;
  11. (function (Unibase) {
  12. let Platform;
  13. (function (Platform) {
  14. let Automation;
  15. (function (Automation) {
  16. let Components;
  17. (function (Components) {
  18. class Notifier {
  19. constructor() {
  20. this.methods = {
  21. sendNotifiation: function (reminderobject) {
  22. var isChatReminder = false;
  23. var isTask = false;
  24. if (!isMobileApp()) {
  25. if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Notification)) {
  26. }
  27. else if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Task)) {
  28. isTask = true;
  29. }
  30. else if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Chat)) {
  31. isChatReminder = true;
  32. var chat = Unibase.Platform.Connect.Components.Chat;
  33. if (chat.chatGroupId == reminderobject.refId && chat.privatewindow) {
  34. return;
  35. }
  36. }
  37. Unibase.Platform.Automation.Components.Notifier.Instance().playAudio(Platform.Automation.Enums.NotifyAlerts.Alert);
  38. if (Notification.permission != "granted")
  39. Notification.requestPermission();
  40. new Notification(reminderobject.subject, { body: reminderobject.message });
  41. if (!isChatReminder)
  42. MessageHelper.Instance().showSuccess(reminderobject.subject, '');
  43. }
  44. if (isTask) {
  45. Unibase.Themes.Compact.Components.Notification.Instance().reloadPage(reminderobject.refGuId);
  46. }
  47. isChatReminder ?
  48. $("#chatIconBadge").text(Number($("#chatIconBadge").text()) + 1).removeClass('d-none') :
  49. Unibase.Themes.Compact.Components.Notification.Instance().GetUnreadRemindersCount();
  50. }
  51. };
  52. }
  53. init() {
  54. this.seedAudioLibrary();
  55. this._notificationHub = Automation.Hubs.NotificationHub.Instance(_appsettings.notification_url());
  56. this.connection = this._notificationHub;
  57. this.start();
  58. Notifier.Instance().ClearOnlineUsers();
  59. }
  60. playAudio(audiotype) {
  61. var obj = document.createElement("audio");
  62. obj.src = this.getAudioUrl(audiotype);
  63. obj.volume = 0.10;
  64. obj.autoplay = false;
  65. obj.play();
  66. }
  67. getAudioUrl(audiotype) {
  68. return this.audiolibrary[Number(audiotype)];
  69. }
  70. ClearOnlineUsers() {
  71. var timerID = setInterval(function () {
  72. Notifier.Instance()._notificationHub.server.ClearOnlineUsers(Unibase.Platform.Membership.Infos.Identity.currentUser.sessionId, null);
  73. }, 1800000);
  74. }
  75. seedAudioLibrary() {
  76. if (this.audiolibrary === undefined)
  77. this.audiolibrary = new Array();
  78. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Alert] = "tenants/alerts/alert.mp3";
  79. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponApplied] = "tenants/alerts/coupon_applied.mp3";
  80. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponAlreadyRedeemed] = "tenants/alerts/coupon_already_redeemed.mp3";
  81. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.InvalidDuplicateCoupon] = "tenants/alerts/invalid_duplicate_coupon.mp3";
  82. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.UnAuthenticCoupon] = "tenants/alerts/unauthentic_coupon.mp3";
  83. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponBeep] = "tenants/alerts/coupon_beep.mp3";
  84. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponScrapped] = "tenants/alerts/coupon_scrapped.mp3";
  85. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Congratulations] = "tenants/alerts/congratulations_sprllproject.mp3";
  86. }
  87. getClientMethods() {
  88. return [
  89. { MethodName: "sendnotification", Method: this.methods.sendNotifiation }
  90. ];
  91. }
  92. registerClientMethods() {
  93. let _methods = this.getClientMethods();
  94. if (_methods)
  95. for (var i = 0; i < _methods.length; i++) {
  96. this.connection.register(_methods[i].MethodName, _methods[i].Method);
  97. }
  98. }
  99. start() {
  100. return __awaiter(this, void 0, void 0, function* () {
  101. try {
  102. this.registerClientMethods();
  103. this.connection.connect(function () {
  104. let identity = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
  105. console.log("connection started");
  106. let _packet = new Unibase.Platform.Automation.Packets.Connect();
  107. _packet.UnibaseId = identity.unibaseId;
  108. _packet.UserName = identity.name;
  109. _packet.UserId = identity.userId;
  110. _packet.TenantId = identity.tenantId;
  111. _packet.SessionId = identity.sessionId;
  112. Unibase.Platform.Automation.Components.Notifier.Instance()._notificationHub.server.Connect(_packet, null);
  113. });
  114. }
  115. catch (err) {
  116. console.log(err);
  117. setTimeout(this.start, 5000);
  118. }
  119. });
  120. }
  121. ;
  122. static Instance() {
  123. if (this.instance === undefined) {
  124. this.instance = new Notifier();
  125. }
  126. return this.instance;
  127. }
  128. }
  129. Components.Notifier = Notifier;
  130. })(Components = Automation.Components || (Automation.Components = {}));
  131. })(Automation = Platform.Automation || (Platform.Automation = {}));
  132. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  133. })(Unibase || (Unibase = {}));