zoom_video_sdk_phone.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { ZoomVideoSDKErrors } from './zoom_video_sdk_defines.js'
  2. import messages from './electron_zoomvideosdk_pb.js'
  3. export default (function () {
  4. var instance
  5. /**
  6. * Return an instance to manage phone invitations during a video SDK session.
  7. * @module zoom_video_sdk_phone
  8. * @return {ZoomVideoSDKLocalPhone}
  9. */
  10. function init(opts) {
  11. const clientOpts = {...opts}
  12. // Private methods and variables
  13. if (!clientOpts.addon) {
  14. return null
  15. }
  16. const _addon = clientOpts.addon.GetPhoneHelper()
  17. return {
  18. // Public methods and variables
  19. /**
  20. * Determine whether the session supports to join by the phone or not.
  21. * @method isSupportPhoneFeature
  22. * @return {Boolean} true indicates to support to join by phone. false not.
  23. */
  24. isSupportPhoneFeature: function () {
  25. if (_addon) {
  26. return _addon.IsSupportPhoneFeature()
  27. }
  28. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  29. },
  30. /**
  31. * Get the list of the country information where the session supports to join by telephone.
  32. * @method getSupportCountryInfo
  33. * @return {Array} List of the country information returns if the session supports to join by telephone. Otherwise null.
  34. */
  35. getSupportCountryInfo: function () {
  36. if (_addon) {
  37. const result = _addon.GetSupportCountryInfo()
  38. const message = messages.GetPhoneSupportCountryList.deserializeBinary(result)
  39. const tempList = message.getPhonesupportcountryinfoList()
  40. let phoneSupportCountryList = []
  41. for (let val of tempList) {
  42. let obj = {
  43. countryID: val.getCountryid(),
  44. countryName: val.getCountryname(),
  45. countryCode: val.getCountrycode()
  46. }
  47. phoneSupportCountryList.push(obj)
  48. }
  49. return phoneSupportCountryList
  50. }
  51. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  52. },
  53. /**
  54. * Invite the specified user to join the session by call out.
  55. * @method inviteByPhone
  56. * @param {String} countryCode The country code of the specified user must be in the support list.
  57. * @param {String} phoneNumber The phone number of specified user.
  58. * @param {String} name The screen name of the specified user in the session.
  59. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  60. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  61. */
  62. inviteByPhone: function (opts) {
  63. if (_addon) {
  64. const clientOpts = {...opts}
  65. try {
  66. const countryCode = clientOpts.countryCode
  67. const phoneNumber = clientOpts.phoneNumber
  68. const name = clientOpts.name
  69. const InviteByPhoneParams = new messages.InviteByPhoneParams()
  70. InviteByPhoneParams.setCountrycode(countryCode)
  71. InviteByPhoneParams.setPhonenumber(phoneNumber)
  72. InviteByPhoneParams.setName(name)
  73. const bytes = InviteByPhoneParams.serializeBinary()
  74. return _addon.InviteByPhone(bytes)
  75. } catch (error) {
  76. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  77. }
  78. }
  79. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  80. },
  81. /**
  82. * Cancel the invitation that is being invited by phone.
  83. * @method cancelInviteByPhone
  84. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  85. Otherwise failed. To get extended error information, see {@link ZoomVideoSDKErrors} enum.
  86. */
  87. cancelInviteByPhone: function () {
  88. if (_addon) {
  89. return _addon.CancelInviteByPhone()
  90. }
  91. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  92. },
  93. /**
  94. * Get the process of the invitation by phone.
  95. * @method getInviteByPhoneStatus
  96. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  97. Otherwise failed. To get extended error information, see {@link ZoomVideoSDKErrors} enum.
  98. */
  99. getInviteByPhoneStatus: function () {
  100. if (_addon) {
  101. return _addon.GetInviteByPhoneStatus()
  102. }
  103. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  104. }
  105. };
  106. }
  107. return {
  108. getInstance: function (opts) {
  109. if (!instance) {
  110. instance = init(opts)
  111. }
  112. return instance
  113. }
  114. }
  115. })()