zoom_video_sdk_session_info.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import { ZoomVideoSDKErrors, ZoomVideoSDKUserInfoType } from './zoom_video_sdk_defines.js'
  2. import messages from './electron_zoomvideosdk_pb.js'
  3. import { getUserInfo } from './zoom_video_sdk_user_util'
  4. export default (function () {
  5. var instance
  6. /**
  7. * Return the current session information.
  8. * @module zoom_video_sdk_session_info
  9. * @return {ZoomVideoSDKSessionInfo}
  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.GetSessionInfoCtrl()
  18. return {
  19. // Public methods and variables
  20. /**
  21. * Get the session name
  22. * @method getSessionName
  23. * @return {String} If the function succeed, the return value is session name. Otherwise returns NULL.
  24. */
  25. getSessionName: function () {
  26. if (_addon) {
  27. return _addon.GetSessionName()
  28. }
  29. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  30. },
  31. /**
  32. * Get Session Password
  33. * @method getSessionPassword
  34. * @return {String} sessionPwd
  35. */
  36. getSessionPassword: function () {
  37. if (_addon) {
  38. return _addon.GetSessionPassword()
  39. }
  40. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  41. },
  42. /**
  43. * Get the session host name
  44. * @method getSessionHostName
  45. * @return {String} If the function succeed, the return value is session host name. Otherwise returns NULL.
  46. */
  47. getSessionHostName: function () {
  48. if (_addon) {
  49. return _addon.GetSessionHostName()
  50. }
  51. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  52. },
  53. /**
  54. * Get the session host user object
  55. * @method getSessionHost
  56. * @return {Object} If the function succeed, the return value is session host user object. Otherwise returns NULL.
  57. */
  58. getSessionHost: function () {
  59. if (_addon) {
  60. try {
  61. const message = new messages.VideoSDKUser.deserializeBinary(_addon.GetSessionHost())
  62. return getUserInfo(message)
  63. } catch (error) {
  64. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  65. }
  66. }
  67. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  68. },
  69. /**
  70. * Get the session all users list
  71. * @method getRemoteUsers
  72. * @param {Number} options
  73. * @return {Array} If the function succeed, the return value is session all user list object(userid, username, customIdentity, emailAddress, isHasVideoDevice, isVideoOn, audioType, isAudioMuted, isTalking, shareStatus, isHost, isManager, videoStatisticInfo_height, videoStatisticInfo_width, videoStatisticInfo_bpf, videoStatisticInfo_fps, shareStatisticInfo_height, shareStatisticInfo_width, shareStatisticInfo_bpf, shareStatisticInfo_fps). Otherwise returns NULL.
  74. */
  75. getRemoteUsers: function (opts) {
  76. if (_addon) {
  77. const clientOpts = {...opts}
  78. const options = Number(clientOpts.options) || ZoomVideoSDKUserInfoType.UserInfoType_ALL
  79. try {
  80. const GetRemoteUsersParams = new messages.GetRemoteUsersParams()
  81. GetRemoteUsersParams.setZnOptions(options)
  82. const bytes = GetRemoteUsersParams.serializeBinary()
  83. const message = messages.UserList.deserializeBinary(_addon.GetRemoteUsers(bytes))
  84. const tempList = message.getUserList()
  85. let userList = []
  86. for (let val of tempList) {
  87. let obj = getUserInfo(val)
  88. userList.push(obj)
  89. }
  90. return userList
  91. } catch (error) {
  92. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  93. }
  94. }
  95. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  96. },
  97. /**
  98. * Get myself object
  99. * @method getMyself
  100. * @return {Object} If the function succeed, the return value is myself object. Otherwise returns NULL.
  101. */
  102. getMyself: function () {
  103. if (_addon) {
  104. const message = new messages.VideoSDKUser.deserializeBinary(_addon.GetMyself())
  105. return getUserInfo(message)
  106. }
  107. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  108. },
  109. /**
  110. * Get session audio statistic information
  111. * @method getSessionAudioStatisticInfo
  112. * @return {Array} send_info, recv_info
  113. */
  114. getSessionAudioStatisticInfo: function () {
  115. if (_addon) {
  116. const message = new messages.VideoSDKSessionAudioStatisticInfoList.deserializeBinary(_addon.GetSessionAudioStatisticInfo())
  117. const tempList = message.getAudiostatisticinfoList()
  118. let audiostatisticinfoList = []
  119. for (let val of tempList) {
  120. let obj = {
  121. frequency: val.getFrequency(),
  122. latency: val.getLatency(),
  123. jitter: val.getJitter(),
  124. packetLossAvg: val.getPacketlossavg(),
  125. packetLossMax: val.getPacketlossmax()
  126. }
  127. audiostatisticinfoList.push(obj)
  128. }
  129. return audiostatisticinfoList
  130. }
  131. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  132. },
  133. /**
  134. * Get session video statistic information
  135. * @method getSessionVideoStatisticInfo
  136. * @return {Array} send_info, recv_info
  137. */
  138. getSessionVideoStatisticInfo: function () {
  139. if (_addon) {
  140. const message = new messages.VideoSDKSessionASVStatisticInfoList.deserializeBinary(_addon.GetSessionVideoStatisticInfo())
  141. const tempList = message.getAsvstatisticinfoList()
  142. let asvstatisticinfoList = []
  143. for (let val of tempList) {
  144. let obj = {
  145. frame_width: val.getFrameWidth(),
  146. frame_height: val.getFrameHeight(),
  147. fps: val.getFps(),
  148. latency: val.getLatency(),
  149. jitter: val.getJitter()
  150. }
  151. asvstatisticinfoList.push(obj)
  152. }
  153. return asvstatisticinfoList
  154. }
  155. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  156. },
  157. /**
  158. * Get session share statistic information
  159. * @method getSessionShareStatisticInfo
  160. * @return {Array} send_info, recv_info
  161. */
  162. getSessionShareStatisticInfo: function () {
  163. if (_addon) {
  164. const message = new messages.VideoSDKSessionASVStatisticInfoList.deserializeBinary(_addon.GetSessionShareStatisticInfo())
  165. const tempList = message.getAsvstatisticinfoList()
  166. let asvstatisticinfoList = []
  167. for (let val of tempList) {
  168. let obj = {
  169. frame_width: val.getFrameWidth(),
  170. frame_height: val.getFrameHeight(),
  171. fps: val.getFps(),
  172. latency: val.getLatency(),
  173. jitter: val.getJitter()
  174. }
  175. asvstatisticinfoList.push(obj)
  176. }
  177. return asvstatisticinfoList
  178. }
  179. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  180. },
  181. /**
  182. * Get the session ID, this interface is only valid for the host.
  183. * @method getSessionID
  184. * @return {String} return If the function succeeds, the return value is session ID. Otherwise returns NULL.
  185. */
  186. getSessionID: function () {
  187. if (_addon) {
  188. return _addon.GetSessionID()
  189. }
  190. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  191. }
  192. }
  193. }
  194. return {
  195. getInstance: function (opts) {
  196. if (!instance) {
  197. instance = init(opts)
  198. }
  199. return instance
  200. }
  201. }
  202. })()