zoom_video_sdk_chat.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import { ZoomVideoSDKErrors } from './zoom_video_sdk_defines.js'
  2. import messages from './electron_zoomvideosdk_pb.js'
  3. import { setUserInfo } from './zoom_video_sdk_user_util.js'
  4. export default (function () {
  5. var instance
  6. /**
  7. * Return an instance to send and receive chat messages within video SDK session participants.
  8. * @module zoom_video_sdk_chat
  9. * @return {ZoomVideoSDKChat}
  10. */
  11. function init (opts) {
  12. const clientOpts = {...opts}
  13. // Private methods and variables
  14. if (!clientOpts.addon) {
  15. return null
  16. }
  17. const _addon = clientOpts.addon.GetChatHelper()
  18. return {
  19. // Public methods and variables
  20. /**
  21. * Determine if chat is disable
  22. * @method isChatDisabled
  23. * @return {Boolean} true if chat is disable. Otherwise returns false.
  24. */
  25. isChatDisabled: function () {
  26. if (_addon) {
  27. return _addon.IsChatDisabled()
  28. }
  29. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  30. },
  31. /**
  32. * Determine if private chat is disable
  33. * @method isPrivateChatDisabled
  34. * @return {Boolean} true if private chat is disable. Otherwise returns false.
  35. */
  36. isPrivateChatDisabled: function () {
  37. if (_addon) {
  38. return _addon.IsPrivateChatDisabled()
  39. }
  40. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  41. },
  42. /**
  43. * Send message to someone
  44. * @method sendChatToUser
  45. * @param {Object} user it's the user which you want to send to.
  46. * @param {String} msgContent the message content
  47. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  48. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  49. */
  50. sendChatToUser: function (opts) {
  51. if (_addon) {
  52. const clientOpts = {...opts}
  53. try {
  54. const user = setUserInfo(clientOpts.user)
  55. const msgContent = clientOpts.msgContent
  56. const SendChatToUserParams = new messages.SendChatToUserParams()
  57. SendChatToUserParams.setUser(user)
  58. SendChatToUserParams.setZnMsgcontent(msgContent)
  59. const bytes = SendChatToUserParams.serializeBinary()
  60. return _addon.SendChatToUser(bytes)
  61. } catch (error) {
  62. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  63. }
  64. }
  65. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  66. },
  67. /**
  68. * Send message to all
  69. * @method sendChatToAll
  70. * @param {String} msgContent the message content
  71. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  72. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  73. */
  74. sendChatToAll: function (opts) {
  75. if (_addon) {
  76. const clientOpts = {...opts}
  77. try {
  78. const msgContent = clientOpts.msgContent
  79. const SendChatToAllParams = new messages.SendChatToAllParams()
  80. SendChatToAllParams.setZnMsgcontent(msgContent)
  81. const bytes = SendChatToAllParams.serializeBinary()
  82. return _addon.SendChatToAll(bytes)
  83. } catch (error) {
  84. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  85. }
  86. }
  87. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  88. },
  89. /**
  90. * delete chat message by message id.
  91. * @method deleteChatMessage
  92. * @param {String} messageID
  93. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  94. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  95. */
  96. deleteChatMessage: function (opts) {
  97. if (_addon) {
  98. const clientOpts = {...opts}
  99. try {
  100. if (clientOpts.messageID == undefined || clientOpts.messageID == "") {
  101. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter
  102. }
  103. const messageID = clientOpts.messageID
  104. const DeleteChatMessageParams = new messages.DeleteChatMessageParams()
  105. DeleteChatMessageParams.setMessageid(messageID)
  106. const bytes = DeleteChatMessageParams.serializeBinary()
  107. return _addon.DeleteChatMessage(bytes)
  108. } catch (error) {
  109. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  110. }
  111. }
  112. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  113. },
  114. /**
  115. * Determine whether the message can be delete.
  116. * @method canChatMessageBeDeleted
  117. * @param {String} messageID
  118. * @return {Boolean} true indicates the message can be delete. Otherwise false.
  119. */
  120. canChatMessageBeDeleted: function (opts) {
  121. if (_addon) {
  122. const clientOpts = {...opts}
  123. try {
  124. if (clientOpts.messageID == undefined || clientOpts.messageID == "") {
  125. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter
  126. }
  127. const messageID = clientOpts.messageID
  128. const CanChatMessageBeDeletedParams = new messages.CanChatMessageBeDeletedParams()
  129. CanChatMessageBeDeletedParams.setMessageid(messageID)
  130. const bytes = CanChatMessageBeDeletedParams.serializeBinary()
  131. return _addon.CanChatMessageBeDeleted(bytes)
  132. } catch (error) {
  133. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  134. }
  135. }
  136. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  137. }
  138. }
  139. };
  140. return {
  141. getInstance: function (opts) {
  142. if (!instance) {
  143. instance = init(opts)
  144. }
  145. return instance
  146. }
  147. }
  148. })()