Built files from Bizgaze WebServer
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

notifier.js 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. }
  59. playAudio(audiotype) {
  60. var obj = document.createElement("audio");
  61. obj.src = this.getAudioUrl(audiotype);
  62. obj.volume = 0.10;
  63. obj.autoplay = false;
  64. obj.play();
  65. }
  66. getAudioUrl(audiotype) {
  67. return this.audiolibrary[Number(audiotype)];
  68. }
  69. seedAudioLibrary() {
  70. if (this.audiolibrary === undefined)
  71. this.audiolibrary = new Array();
  72. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Alert] = "tenants/alerts/alert.mp3";
  73. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponApplied] = "tenants/alerts/coupon_applied.mp3";
  74. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponAlreadyRedeemed] = "tenants/alerts/coupon_already_redeemed.mp3";
  75. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.InvalidDuplicateCoupon] = "tenants/alerts/invalid_duplicate_coupon.mp3";
  76. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.UnAuthenticCoupon] = "tenants/alerts/unauthentic_coupon.mp3";
  77. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponBeep] = "tenants/alerts/coupon_beep.mp3";
  78. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponScrapped] = "tenants/alerts/coupon_scrapped.mp3";
  79. this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Congratulations] = "tenants/alerts/congratulations_sprllproject.mp3";
  80. }
  81. getClientMethods() {
  82. return [
  83. { MethodName: "sendnotification", Method: this.methods.sendNotifiation }
  84. ];
  85. }
  86. registerClientMethods() {
  87. let _methods = this.getClientMethods();
  88. if (_methods)
  89. for (var i = 0; i < _methods.length; i++) {
  90. this.connection.register(_methods[i].MethodName, _methods[i].Method);
  91. }
  92. }
  93. start() {
  94. return __awaiter(this, void 0, void 0, function* () {
  95. try {
  96. this.registerClientMethods();
  97. this.connection.connect(function () {
  98. let identity = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
  99. console.log("connection started");
  100. let _packet = new Unibase.Platform.Automation.Packets.Connect();
  101. _packet.UnibaseId = identity.unibaseId;
  102. _packet.UserName = identity.name;
  103. _packet.UserId = identity.userId;
  104. _packet.TenantId = identity.tenantId;
  105. _packet.SessionId = identity.sessionId;
  106. Unibase.Platform.Automation.Components.Notifier.Instance()._notificationHub.server.Connect(_packet, null);
  107. });
  108. }
  109. catch (err) {
  110. console.log(err);
  111. setTimeout(this.start, 5000);
  112. }
  113. });
  114. }
  115. ;
  116. static Instance() {
  117. if (this.instance === undefined) {
  118. this.instance = new Notifier();
  119. }
  120. return this.instance;
  121. }
  122. }
  123. Components.Notifier = Notifier;
  124. })(Components = Automation.Components || (Automation.Components = {}));
  125. })(Automation = Platform.Automation || (Platform.Automation = {}));
  126. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  127. })(Unibase || (Unibase = {}));