@hivegpt/hiveai-angular 0.0.157 → 0.0.159

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('@angular/platform-browser'), require('rxjs'), require('rxjs/operators'), require('rxjs/webSocket'), require('@angular/common'), require('@angular/forms'), require('@angular/material/icon'), require('@angular/material/sidenav')) :
3
- typeof define === 'function' && define.amd ? define('@hivegpt/hiveai-angular', ['exports', '@angular/common/http', '@angular/core', '@angular/platform-browser', 'rxjs', 'rxjs/operators', 'rxjs/webSocket', '@angular/common', '@angular/forms', '@angular/material/icon', '@angular/material/sidenav'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.hivegpt = global.hivegpt || {}, global.hivegpt['hiveai-angular'] = {}), global.ng.common.http, global.ng.core, global.ng.platformBrowser, global.rxjs, global.rxjs.operators, global.rxjs.webSocket, global.ng.common, global.ng.forms, global.ng.material.icon, global.ng.material.sidenav));
5
- }(this, (function (exports, http, i0, platformBrowser, rxjs, operators, webSocket, common, forms, icon, sidenav) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common/http'), require('@angular/core'), require('@angular/platform-browser'), require('rxjs'), require('rxjs/operators'), require('ngx-socket-io'), require('@angular/common'), require('@angular/forms'), require('@angular/material/icon'), require('@angular/material/sidenav')) :
3
+ typeof define === 'function' && define.amd ? define('@hivegpt/hiveai-angular', ['exports', '@angular/common/http', '@angular/core', '@angular/platform-browser', 'rxjs', 'rxjs/operators', 'ngx-socket-io', '@angular/common', '@angular/forms', '@angular/material/icon', '@angular/material/sidenav'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.hivegpt = global.hivegpt || {}, global.hivegpt['hiveai-angular'] = {}), global.ng.common.http, global.ng.core, global.ng.platformBrowser, global.rxjs, global.rxjs.operators, global.ngxSocketIo, global.ng.common, global.ng.forms, global.ng.material.icon, global.ng.material.sidenav));
5
+ }(this, (function (exports, http, i0, platformBrowser, rxjs, operators, ngxSocketIo, common, forms, icon, sidenav) { 'use strict';
6
6
 
7
7
  /******************************************************************************
8
8
  Copyright (c) Microsoft Corporation.
@@ -521,6 +521,7 @@
521
521
  var ConversationService = /** @class */ (function () {
522
522
  function ConversationService() {
523
523
  this.storageKey = 'conversationKey';
524
+ this.userSepecificNotification = new rxjs.Subject();
524
525
  }
525
526
  ConversationService.prototype.generateKey = function () {
526
527
  var timestamp = Math.floor(new Date().getTime() / 1000).toString(16);
@@ -543,6 +544,13 @@
543
544
  this.ensureKeyExists(storageKey, key);
544
545
  return localStorage.getItem(storageKey);
545
546
  };
547
+ ConversationService.prototype.sendValidatedUserData = function (message) {
548
+ //console.log('lgging messages', message, new Date());\
549
+ this.userSepecificNotification.next(message);
550
+ };
551
+ ConversationService.prototype.getUserSpecificNotification = function () {
552
+ return this.userSepecificNotification.asObservable();
553
+ };
546
554
  return ConversationService;
547
555
  }());
548
556
  ConversationService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ConversationService_Factory() { return new ConversationService(); }, token: ConversationService, providedIn: "root" });
@@ -553,45 +561,86 @@
553
561
  ];
554
562
  ConversationService.ctorParameters = function () { return []; };
555
563
 
564
+ var NotificationSocket = /** @class */ (function (_super) {
565
+ __extends(NotificationSocket, _super);
566
+ function NotificationSocket() {
567
+ return _super.call(this, socketConfig) || this;
568
+ }
569
+ return NotificationSocket;
570
+ }(ngxSocketIo.Socket));
571
+ NotificationSocket.decorators = [
572
+ { type: i0.Injectable }
573
+ ];
574
+ NotificationSocket.ctorParameters = function () { return []; };
575
+ var socketConfig = {
576
+ url: prod_environment.SocketUrl,
577
+ options: {
578
+ transports: ['websocket', 'polling'],
579
+ reconnection: true,
580
+ autoConnect: true,
581
+ upgrade: true,
582
+ reconnectionDelay: 1000,
583
+ reconnectionDelayMax: 5000,
584
+ reconnectionAttempts: Infinity
585
+ }
586
+ };
587
+
556
588
  var SocketService = /** @class */ (function () {
557
- function SocketService() {
558
- this.connect();
589
+ function SocketService(conversationService, notificationSocket) {
590
+ this.conversationService = conversationService;
591
+ this.notificationSocket = notificationSocket;
592
+ this.isCommonSocketInitialized = false;
593
+ this.isUserSpecificSocketInitialized = false;
594
+ this.isUserSpecificEventReleased = true;
595
+ this.messageQueue = [];
596
+ this.releaseInterval = 1000;
597
+ this.intervalSetup = false;
598
+ this.startReleasingMessages();
559
599
  }
560
- SocketService.prototype.connect = function () {
561
- var _this = this;
562
- var url = prod_environment;
563
- this.socket$ = webSocket.webSocket(url.SocketUrl);
564
- this.socket$.subscribe(function (message) { return _this.onMessage(message); }, function (err) { return console.error('WebSocket error', err); }, function () { return console.warn('WebSocket closed'); });
565
- };
566
- SocketService.prototype.onMessage = function (message) {
567
- console.log('Received message:', message);
568
- // Handle incoming messages
600
+ SocketService.prototype.isSocketInitialized = function (isCommon) {
601
+ return isCommon
602
+ ? this.isCommonSocketInitialized
603
+ : this.isUserSpecificSocketInitialized &&
604
+ !this.isUserSpecificEventReleased;
569
605
  };
570
- SocketService.prototype.sendMessage = function (message) {
571
- this.socket$.next(message);
606
+ SocketService.prototype.disconnectSocketConnection = function () {
607
+ this.notificationSocket.disconnect();
572
608
  };
573
- SocketService.prototype.close = function () {
574
- this.socket$.complete();
609
+ SocketService.prototype.registerUserSpecificHiveSocket = function (botId, conversation_id) {
610
+ var _this = this;
611
+ this.notificationSocket.emit('joinData', {
612
+ groupId: "Hive_AI_Notifs_" + botId + "_" + conversation_id,
613
+ });
614
+ this.notificationSocket
615
+ .fromEvent('commonNotification')
616
+ .subscribe(function (res) {
617
+ _this.conversationService.sendValidatedUserData(res);
618
+ });
575
619
  };
576
- SocketService.prototype.onEvent = function (eventName) {
620
+ SocketService.prototype.startReleasingMessages = function () {
577
621
  var _this = this;
578
- return new rxjs.Observable(function (observer) {
579
- _this.socket$.subscribe(function (message) {
580
- if (message.event === eventName) {
581
- observer.next(message.data);
622
+ if (!this.intervalSetup) {
623
+ setInterval(function () {
624
+ if (_this.messageQueue.length > 0) {
625
+ var message = _this.messageQueue.shift(); // Remove the first message from the queue
626
+ // this.campaignService.sendValidatedUserData(message);
582
627
  }
583
- });
584
- });
628
+ }, this.releaseInterval);
629
+ this.intervalSetup = true; // Prevents multiple intervals
630
+ }
585
631
  };
586
632
  return SocketService;
587
633
  }());
588
- SocketService.ɵprov = i0.ɵɵdefineInjectable({ factory: function SocketService_Factory() { return new SocketService(); }, token: SocketService, providedIn: "root" });
634
+ SocketService.ɵprov = i0.ɵɵdefineInjectable({ factory: function SocketService_Factory() { return new SocketService(i0.ɵɵinject(ConversationService), i0.ɵɵinject(NotificationSocket)); }, token: SocketService, providedIn: "root" });
589
635
  SocketService.decorators = [
590
636
  { type: i0.Injectable, args: [{
591
637
  providedIn: 'root'
592
638
  },] }
593
639
  ];
594
- SocketService.ctorParameters = function () { return []; };
640
+ SocketService.ctorParameters = function () { return [
641
+ { type: ConversationService },
642
+ { type: NotificationSocket }
643
+ ]; };
595
644
 
596
645
  var ChatDrawerComponent = /** @class */ (function () {
597
646
  function ChatDrawerComponent(cdr, http, sanitizer, elementRef, renderer, socketService, conversation
@@ -726,22 +775,27 @@
726
775
  this.fetchAgents();
727
776
  this.cdr.markForCheck();
728
777
  this.initializeSocketAndListen();
778
+ setTimeout(function () {
779
+ _this.listenSockets();
780
+ }, 200);
729
781
  };
730
- ChatDrawerComponent.prototype.initializeSocketAndListen = function () {
782
+ ChatDrawerComponent.prototype.initializeSocket = function () {
783
+ this.socketService.registerUserSpecificHiveSocket(this.botId, this.conversationKey);
784
+ };
785
+ ChatDrawerComponent.prototype.listenSockets = function () {
731
786
  var _this = this;
732
- this.eventSubscription = this.socketService.onEvent('webresult').subscribe(function (data) {
733
- console.log('Event received webresult:', data);
734
- _this.handleEvent(data, 'webresult');
735
- });
736
- this.eventSubscription = this.socketService.onEvent('answer').subscribe(function (data) {
737
- console.log('Event received answer:', data);
738
- _this.handleEvent(data, 'answer');
739
- });
740
- this.eventSubscription = this.socketService.onEvent('graph').subscribe(function (data) {
741
- console.log('Event received graph:', data);
742
- _this.handleEvent(data, 'graph');
787
+ this.eventSubscription = this.conversation
788
+ .getUserSpecificNotification()
789
+ .subscribe(function (res) {
790
+ console.log("Socket Data");
791
+ console.log(res);
792
+ }, function (err) {
793
+ _this.eventSubscription.unsubscribe();
794
+ console.error('Error in fetching data from socket');
743
795
  });
744
796
  };
797
+ ChatDrawerComponent.prototype.initializeSocketAndListen = function () {
798
+ };
745
799
  ChatDrawerComponent.prototype.handleEvent = function (data, type) {
746
800
  switch (type) {
747
801
  case 'webresult':
@@ -758,7 +812,7 @@
758
812
  if (this.eventSubscription) {
759
813
  this.eventSubscription.unsubscribe();
760
814
  }
761
- this.socketService.close();
815
+ //this.socketService.close();
762
816
  };
763
817
  ChatDrawerComponent.prototype.changeTemperature = function (newTemperature) {
764
818
  if (this.loading)
@@ -1882,8 +1936,9 @@
1882
1936
  exports.HiveGptModule = HiveGptModule;
1883
1937
  exports.ɵa = SocketService;
1884
1938
  exports.ɵb = ConversationService;
1885
- exports.ɵc = VideoPlayerComponent;
1886
- exports.ɵd = SafeHtmlPipe;
1939
+ exports.ɵc = NotificationSocket;
1940
+ exports.ɵd = VideoPlayerComponent;
1941
+ exports.ɵe = SafeHtmlPipe;
1887
1942
 
1888
1943
  Object.defineProperty(exports, '__esModule', { value: true });
1889
1944