123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- 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 Connect;
- (function (Connect) {
- let Components;
- (function (Components) {
- class Chatter {
- constructor() {
- this.methods = {
- onMessageSent: function (packet) {
- console.log('Connected !' + packet.fromUserId + packet.message);
- },
- onUserTyping: function (packet) {
- if (packet.isTyping)
- Unibase.Platform.Connect.Components.Chat.Instance().showtyping(packet.userName, packet.fromUserId, packet.chatGroupId, packet.isPrivate);
- else
- Unibase.Platform.Connect.Components.Chat.Instance().hidestatus(packet.chatGroupId, packet.userName);
- },
- onMessageReceived: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().onMessageReceived(packet);
- },
- EnableVedio: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().EnableVedio(packet);
- },
- UpdateDeliveryStatus: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().UpdateDeliveryStatus(packet);
- },
- UpdateReadStatus: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().UpdateReadStatus(packet);
- },
- onUserDisconnected: function (packet) {
- },
- Editedmsg: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().editedMsg(packet);
- },
- Deleteforeveryone: function (packet) {
- Unibase.Platform.Connect.Components.Chat.Instance().deleteall(packet);
- },
- ChangeProfileImage: function (object) {
- Unibase.Platform.Connect.Components.Chat.Instance().updateProfile(object.photoUrl, object.chatGroupId);
- },
- OnGroupNameChanged: function (object) {
- Unibase.Platform.Connect.Components.Chat.Instance().updateGroupName(object.groupName, object.chatgroupid);
- },
- OnPrivateWindowOpened: function (chatGroupId) {
- Unibase.Platform.Connect.Components.Chat.Instance().OnPrivateWindowOpened(chatGroupId);
- },
- EnableMeeting: function (MeetingId, UserId) {
- Unibase.Platform.Connect.Components.Chat.Instance().EnableMeeting(MeetingId, UserId);
- },
- addParticipants: function (chatGrpDetails) {
- Unibase.Platform.Connect.Components.Chat.Instance().addParticipants(chatGrpDetails);
- },
- onlinestatus: function (userid, onlinestatus) {
- Unibase.Platform.Connect.Components.Chat.Instance().onlinestatus(userid, onlinestatus);
- },
- updatedstatus: function (users) {
- Unibase.Platform.Connect.Components.Chat.Instance().status(users);
- },
- GetChatUnreadCount: function (chatcount) {
- $('#chatIconBadge').text(chatcount).removeClass('d-none');
- },
- updatechatcount: function () {
- $('#chatIconBadge').text(Number($('#chatIconBadge').text()) + 1).removeClass('d-none');
- },
- removeadmin: function (recipientId, chatGroupId) {
- Unibase.Platform.Connect.Components.Chat.Instance().removeAdmin(recipientId, chatGroupId);
- },
- makeadmin: function (recipientId, chatGroupId) {
- Unibase.Platform.Connect.Components.Chat.Instance().makeAdmin(recipientId, chatGroupId);
- },
- removeparticipant: function (recipientId, chatGroupId) {
- Unibase.Platform.Connect.Components.Chat.Instance().removeParticipants(recipientId, chatGroupId);
- }
- };
- }
- init() {
- this._chatHub = Unibase.Platform.Connect.Hubs.ChatHub.Instance(_appsettings.chathub_url());
- this.connection = this._chatHub;
- this.start();
- }
- getClientMethods() {
- return [
- { MethodName: "removeadmin", Method: this.methods.removeadmin },
- { MethodName: "makeadmin", Method: this.methods.makeadmin },
- { MethodName: "removeparticipant", Method: this.methods.removeparticipant },
- { MethodName: "onMessageSent", Method: this.methods.onMessageSent },
- { MethodName: "onUserTyping", Method: this.methods.onUserTyping },
- { MethodName: "onMessageReceived", Method: this.methods.onMessageReceived },
- { MethodName: "EnableVedio", Method: this.methods.EnableVedio },
- { MethodName: "UpdateDeliveryStatus", Method: this.methods.UpdateDeliveryStatus },
- { MethodName: "UpdateReadStatus", Method: this.methods.UpdateReadStatus },
- { MethodName: "onUserDisconnected", Method: this.methods.onUserDisconnected },
- { MethodName: "Editedmsg", Method: this.methods.Editedmsg },
- { MethodName: "Deleteforeveryone", Method: this.methods.Deleteforeveryone },
- { MethodName: "ChangeProfileImage", Method: this.methods.ChangeProfileImage },
- { MethodName: "OnPrivateWindowOpened", Method: this.methods.OnPrivateWindowOpened },
- { MethodName: "OnGroupNameChanged", Method: this.methods.OnGroupNameChanged },
- { MethodName: "EnableMeeting", Method: this.methods.EnableMeeting },
- { MethodName: "addParticipants", Method: this.methods.addParticipants },
- { MethodName: "onlinestatus", Method: this.methods.onlinestatus },
- { MethodName: "updatedstatus", Method: this.methods.updatedstatus },
- { MethodName: "GetChatUnreadCount", Method: this.methods.GetChatUnreadCount },
- { MethodName: "updatechatcount", Method: this.methods.updatechatcount },
- ];
- }
- 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();
- let _packet = new Unibase.Platform.Connect.Server.Packets.Connect();
- _packet.SessionId = identity.sessionId;
- _packet.UnibaseId = identity.unibaseId;
- _packet.UserId = identity.userId;
- _packet.UserName = identity.name;
- _packet.ActiveChatGroupId = 0;
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserConnected(_packet, null);
- });
- }
- catch (err) {
- console.log(err);
- setTimeout(this.start, 5000);
- }
- });
- }
- ;
- onTyping(packet, callback) {
- if (!Components.Chat.isBlock) {
- packet.IsTyping = true;
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserTyping(packet, callback);
- }
- }
- onTypingStop(packet, callback) {
- if (!Components.Chat.isBlock) {
- packet.IsTyping = false;
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserTyping(packet, callback);
- }
- }
- onMessageSent(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.SendPrivateMessage(packet, callback);
- }
- openvideo(packet) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OpenVideo(packet);
- }
- updateActiveChatGroup(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateActiveChatGroup(packet, callback);
- }
- updateDeliveryStatus(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateDeliveryStatus(packet, callback);
- }
- updateReadStatus(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateReadStatus(packet, callback);
- }
- editMessage(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EditMessage(packet, callback);
- }
- Deleteforeveryone(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.Deleteall(packet, callback);
- }
- updateLastMessage(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.updateLastMessage(packet, callback);
- }
- OnPrivateWindowOpened(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OnPrivateWindowOpened(packet, callback);
- }
- OnGroupNameChanged(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OnGroupNameChanged(packet, callback);
- }
- EnableAudio(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EnableAudio(packet, callback);
- }
- EnableVedio(packet, callback) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EnableVedio(packet, callback);
- }
- GetUnreadChatCount() {
- var sessionid = Unibase.Platform.Membership.Infos.Identity.currentUser.sessionId;
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.GetUnreadChatCount(sessionid);
- }
- addParticipants(chatGrpDetails) {
- Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.addParticipantsInGrp(chatGrpDetails);
- }
- static Instance() {
- if (this.instance === undefined) {
- this.instance = new Chatter();
- }
- return this.instance;
- }
- }
- Components.Chatter = Chatter;
- })(Components = Connect.Components || (Connect.Components = {}));
- })(Connect = Platform.Connect || (Platform.Connect = {}));
- })(Platform = Unibase.Platform || (Unibase.Platform = {}));
- })(Unibase || (Unibase = {}));
|