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.

chatter.js 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 Connect;
  15. (function (Connect) {
  16. let Components;
  17. (function (Components) {
  18. class Chatter {
  19. constructor() {
  20. this.methods = {
  21. onMessageSent: function (packet) {
  22. console.log('Connected !' + packet.fromUserId + packet.message);
  23. },
  24. onUserTyping: function (packet) {
  25. if (packet.isTyping)
  26. Unibase.Platform.Connect.Components.Chat.Instance().showtyping(packet.userName, packet.fromUserId, packet.chatGroupId, packet.isPrivate);
  27. else
  28. Unibase.Platform.Connect.Components.Chat.Instance().hidestatus(packet.chatGroupId, packet.userName);
  29. },
  30. onMessageReceived: function (packet) {
  31. Unibase.Platform.Connect.Components.Chat.Instance().onMessageReceived(packet);
  32. },
  33. EnableVedio: function (packet) {
  34. Unibase.Platform.Connect.Components.Chat.Instance().EnableVedio(packet);
  35. },
  36. UpdateDeliveryStatus: function (packet) {
  37. Unibase.Platform.Connect.Components.Chat.Instance().UpdateDeliveryStatus(packet);
  38. },
  39. UpdateReadStatus: function (packet) {
  40. Unibase.Platform.Connect.Components.Chat.Instance().UpdateReadStatus(packet);
  41. },
  42. onUserDisconnected: function (packet) {
  43. },
  44. Editedmsg: function (packet) {
  45. Unibase.Platform.Connect.Components.Chat.Instance().editedMsg(packet);
  46. },
  47. Deleteforeveryone: function (packet) {
  48. Unibase.Platform.Connect.Components.Chat.Instance().deleteall(packet);
  49. },
  50. ChangeProfileImage: function (object) {
  51. Unibase.Platform.Connect.Components.Chat.Instance().updateProfile(object.photoUrl, object.chatGroupId);
  52. },
  53. OnGroupNameChanged: function (object) {
  54. Unibase.Platform.Connect.Components.Chat.Instance().updateGroupName(object.groupName, object.chatgroupid);
  55. },
  56. OnPrivateWindowOpened: function (chatGroupId) {
  57. Unibase.Platform.Connect.Components.Chat.Instance().OnPrivateWindowOpened(chatGroupId);
  58. },
  59. EnableMeeting: function (MeetingId, UserId) {
  60. Unibase.Platform.Connect.Components.Chat.Instance().EnableMeeting(MeetingId, UserId);
  61. },
  62. addParticipants: function (chatGrpDetails) {
  63. Unibase.Platform.Connect.Components.Chat.Instance().addParticipants(chatGrpDetails);
  64. },
  65. onlinestatus: function (userid, onlinestatus) {
  66. Unibase.Platform.Connect.Components.Chat.Instance().onlinestatus(userid, onlinestatus);
  67. },
  68. updatedstatus: function (users) {
  69. Unibase.Platform.Connect.Components.Chat.Instance().status(users);
  70. },
  71. GetChatUnreadCount: function (chatcount) {
  72. $('#chatIconBadge').text(chatcount).removeClass('d-none');
  73. },
  74. updatechatcount: function () {
  75. $('#chatIconBadge').text(Number($('#chatIconBadge').text()) + 1).removeClass('d-none');
  76. },
  77. removeadmin: function (recipientId, chatGroupId) {
  78. Unibase.Platform.Connect.Components.Chat.Instance().removeAdmin(recipientId, chatGroupId);
  79. },
  80. makeadmin: function (recipientId, chatGroupId) {
  81. Unibase.Platform.Connect.Components.Chat.Instance().makeAdmin(recipientId, chatGroupId);
  82. },
  83. removeparticipant: function (recipientId, chatGroupId) {
  84. Unibase.Platform.Connect.Components.Chat.Instance().removeParticipants(recipientId, chatGroupId);
  85. }
  86. };
  87. }
  88. init() {
  89. this._chatHub = Unibase.Platform.Connect.Hubs.ChatHub.Instance(_appsettings.chathub_url());
  90. this.connection = this._chatHub;
  91. this.start();
  92. }
  93. getClientMethods() {
  94. return [
  95. { MethodName: "removeadmin", Method: this.methods.removeadmin },
  96. { MethodName: "makeadmin", Method: this.methods.makeadmin },
  97. { MethodName: "removeparticipant", Method: this.methods.removeparticipant },
  98. { MethodName: "onMessageSent", Method: this.methods.onMessageSent },
  99. { MethodName: "onUserTyping", Method: this.methods.onUserTyping },
  100. { MethodName: "onMessageReceived", Method: this.methods.onMessageReceived },
  101. { MethodName: "EnableVedio", Method: this.methods.EnableVedio },
  102. { MethodName: "UpdateDeliveryStatus", Method: this.methods.UpdateDeliveryStatus },
  103. { MethodName: "UpdateReadStatus", Method: this.methods.UpdateReadStatus },
  104. { MethodName: "onUserDisconnected", Method: this.methods.onUserDisconnected },
  105. { MethodName: "Editedmsg", Method: this.methods.Editedmsg },
  106. { MethodName: "Deleteforeveryone", Method: this.methods.Deleteforeveryone },
  107. { MethodName: "ChangeProfileImage", Method: this.methods.ChangeProfileImage },
  108. { MethodName: "OnPrivateWindowOpened", Method: this.methods.OnPrivateWindowOpened },
  109. { MethodName: "OnGroupNameChanged", Method: this.methods.OnGroupNameChanged },
  110. { MethodName: "EnableMeeting", Method: this.methods.EnableMeeting },
  111. { MethodName: "addParticipants", Method: this.methods.addParticipants },
  112. { MethodName: "onlinestatus", Method: this.methods.onlinestatus },
  113. { MethodName: "updatedstatus", Method: this.methods.updatedstatus },
  114. { MethodName: "GetChatUnreadCount", Method: this.methods.GetChatUnreadCount },
  115. { MethodName: "updatechatcount", Method: this.methods.updatechatcount },
  116. ];
  117. }
  118. registerClientMethods() {
  119. let _methods = this.getClientMethods();
  120. if (_methods)
  121. for (var i = 0; i < _methods.length; i++) {
  122. this.connection.register(_methods[i].MethodName, _methods[i].Method);
  123. }
  124. }
  125. start() {
  126. return __awaiter(this, void 0, void 0, function* () {
  127. try {
  128. this.registerClientMethods();
  129. this.connection.connect(function () {
  130. let identity = Unibase.Platform.Membership.Infos.Identity.getCurrentUser();
  131. let _packet = new Unibase.Platform.Connect.Server.Packets.Connect();
  132. _packet.SessionId = identity.sessionId;
  133. _packet.UnibaseId = identity.unibaseId;
  134. _packet.UserId = identity.userId;
  135. _packet.UserName = identity.name;
  136. _packet.ActiveChatGroupId = 0;
  137. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserConnected(_packet, null);
  138. });
  139. }
  140. catch (err) {
  141. console.log(err);
  142. setTimeout(this.start, 5000);
  143. }
  144. });
  145. }
  146. ;
  147. onTyping(packet, callback) {
  148. if (!Components.Chat.isBlock) {
  149. packet.IsTyping = true;
  150. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserTyping(packet, callback);
  151. }
  152. }
  153. onTypingStop(packet, callback) {
  154. if (!Components.Chat.isBlock) {
  155. packet.IsTyping = false;
  156. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UserTyping(packet, callback);
  157. }
  158. }
  159. onMessageSent(packet, callback) {
  160. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.SendPrivateMessage(packet, callback);
  161. }
  162. openvideo(packet) {
  163. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OpenVideo(packet);
  164. }
  165. updateActiveChatGroup(packet, callback) {
  166. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateActiveChatGroup(packet, callback);
  167. }
  168. updateDeliveryStatus(packet, callback) {
  169. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateDeliveryStatus(packet, callback);
  170. }
  171. updateReadStatus(packet, callback) {
  172. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.UpdateReadStatus(packet, callback);
  173. }
  174. editMessage(packet, callback) {
  175. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EditMessage(packet, callback);
  176. }
  177. Deleteforeveryone(packet, callback) {
  178. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.Deleteall(packet, callback);
  179. }
  180. updateLastMessage(packet, callback) {
  181. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.updateLastMessage(packet, callback);
  182. }
  183. OnPrivateWindowOpened(packet, callback) {
  184. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OnPrivateWindowOpened(packet, callback);
  185. }
  186. OnGroupNameChanged(packet, callback) {
  187. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.OnGroupNameChanged(packet, callback);
  188. }
  189. EnableAudio(packet, callback) {
  190. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EnableAudio(packet, callback);
  191. }
  192. EnableVedio(packet, callback) {
  193. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.EnableVedio(packet, callback);
  194. }
  195. GetUnreadChatCount() {
  196. var sessionid = Unibase.Platform.Membership.Infos.Identity.currentUser.sessionId;
  197. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.GetUnreadChatCount(sessionid);
  198. }
  199. addParticipants(chatGrpDetails) {
  200. Unibase.Platform.Connect.Components.Chatter.instance._chatHub.server.addParticipantsInGrp(chatGrpDetails);
  201. }
  202. static Instance() {
  203. if (this.instance === undefined) {
  204. this.instance = new Chatter();
  205. }
  206. return this.instance;
  207. }
  208. }
  209. Components.Chatter = Chatter;
  210. })(Components = Connect.Components || (Connect.Components = {}));
  211. })(Connect = Platform.Connect || (Platform.Connect = {}));
  212. })(Platform = Unibase.Platform || (Unibase.Platform = {}));
  213. })(Unibase || (Unibase = {}));