123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
- return new (P || (P = Promise))(function (resolve, reject) {
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
- step((generator = generator.apply(thisArg, _arguments || [])).next());
- });
- };
- var Unibase;
- (function (Unibase) {
- let Platform;
- (function (Platform) {
- let Automation;
- (function (Automation) {
- let Components;
- (function (Components) {
- class Notifier {
- constructor() {
- this.methods = {
- sendNotifiation: function (reminderobject) {
- var isChatReminder = false;
- var isTask = false;
- if (!isMobileApp()) {
- if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Notification)) {
- }
- else if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Task)) {
- isTask = true;
- }
- else if (reminderobject.reminderType == Number(Unibase.Platform.Communications.Enums.ReminderType.Chat)) {
- isChatReminder = true;
- var chat = Unibase.Platform.Connect.Components.Chat;
- if (chat.chatGroupId == reminderobject.refId && chat.privatewindow) {
- return;
- }
- }
- Unibase.Platform.Automation.Components.Notifier.Instance().playAudio(Platform.Automation.Enums.NotifyAlerts.Alert);
- if (Notification.permission != "granted")
- Notification.requestPermission();
- new Notification(reminderobject.subject, { body: reminderobject.message });
- if (!isChatReminder)
- MessageHelper.Instance().showSuccess(reminderobject.subject, '');
- }
- if (isTask) {
- Unibase.Themes.Compact.Components.Notification.Instance().reloadPage(reminderobject.refGuId);
- }
- isChatReminder ?
- $("#chatIconBadge").text(Number($("#chatIconBadge").text()) + 1).removeClass('d-none') :
- Unibase.Themes.Compact.Components.Notification.Instance().GetUnreadRemindersCount();
- }
- };
- }
- init() {
- this.seedAudioLibrary();
- this._notificationHub = Automation.Hubs.NotificationHub.Instance(_appsettings.notification_url());
- this.connection = this._notificationHub;
- this.start();
- Notifier.Instance().ClearOnlineUsers();
- }
- playAudio(audiotype) {
- var obj = document.createElement("audio");
- obj.src = this.getAudioUrl(audiotype);
- obj.volume = 0.10;
- obj.autoplay = false;
- obj.play();
- }
- getAudioUrl(audiotype) {
- return this.audiolibrary[Number(audiotype)];
- }
- ClearOnlineUsers() {
- var timerID = setInterval(function () {
- Notifier.Instance()._notificationHub.server.ClearOnlineUsers(Unibase.Platform.Membership.Infos.Identity.currentUser.sessionId, null);
- }, 1800000);
- }
- seedAudioLibrary() {
- if (this.audiolibrary === undefined)
- this.audiolibrary = new Array();
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Alert] = "tenants/alerts/alert.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponApplied] = "tenants/alerts/coupon_applied.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponAlreadyRedeemed] = "tenants/alerts/coupon_already_redeemed.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.InvalidDuplicateCoupon] = "tenants/alerts/invalid_duplicate_coupon.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.UnAuthenticCoupon] = "tenants/alerts/unauthentic_coupon.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponBeep] = "tenants/alerts/coupon_beep.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.CouponScrapped] = "tenants/alerts/coupon_scrapped.mp3";
- this.audiolibrary[Platform.Automation.Enums.NotifyAlerts.Congratulations] = "tenants/alerts/congratulations_sprllproject.mp3";
- }
- getClientMethods() {
- return [
- { MethodName: "sendnotification", Method: this.methods.sendNotifiation }
- ];
- }
- registerClientMethods() {
- let _methods = this.getClientMethods();
- if (_methods)
- for (var i = 0; i < _methods.length; i++) {
- this.connection.register(_methods[i].MethodName, _methods[i].Method);
- }
- }
- start() {
- return __awaiter(this, void 0, void 0, function* () {
- try {
- this.registerClientMethods();
- this.connection.connect(function () {
- let identity = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
- console.log("connection started");
- let _packet = new Unibase.Platform.Automation.Packets.Connect();
- _packet.UnibaseId = identity.unibaseId;
- _packet.UserName = identity.name;
- _packet.UserId = identity.userId;
- _packet.TenantId = identity.tenantId;
- _packet.SessionId = identity.sessionId;
- Unibase.Platform.Automation.Components.Notifier.Instance()._notificationHub.server.Connect(_packet, null);
- });
- }
- catch (err) {
- console.log(err);
- setTimeout(this.start, 5000);
- }
- });
- }
- ;
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new Notifier();
- }
- return this.instance;
- }
- }
- Components.Notifier = Notifier;
- })(Components = Automation.Components || (Automation.Components = {}));
- })(Automation = Platform.Automation || (Platform.Automation = {}));
- })(Platform = Unibase.Platform || (Unibase.Platform = {}));
- })(Unibase || (Unibase = {}));
|