zoom_video_sdk_audio.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 manage audio controls related to the current video SDK session.
  8. * @module zoom_video_sdk_audio
  9. * @return {ZoomVideoSDKAudio}
  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.GetAudioHelper()
  18. return {
  19. // Public methods and variables
  20. /**
  21. * Start audio with voip
  22. * @method startAudio
  23. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  24. Otherwise failed. To get extended error information, see {@link ZoomVideoSDKErrors} enum.
  25. */
  26. startAudio: function () {
  27. if (_addon) {
  28. return _addon.StartAudio()
  29. }
  30. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  31. },
  32. /**
  33. * Stop voip
  34. * @method stopAudio
  35. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  36. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  37. */
  38. stopAudio: function () {
  39. if (_addon) {
  40. return _addon.StopAudio()
  41. }
  42. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  43. },
  44. /**
  45. * mute user's voip audio. 0 means current user (myself)
  46. * @method muteAudio
  47. * @param {Object} user the user which you want to mute.
  48. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  49. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  50. */
  51. muteAudio: function (opts) {
  52. if (_addon) {
  53. const clientOpts = {...opts}
  54. try {
  55. const user = setUserInfo(clientOpts.user)
  56. const MuteAudioParams = new messages.MuteAudioParams()
  57. MuteAudioParams.setUser(user)
  58. const bytes = MuteAudioParams.serializeBinary()
  59. return _addon.MuteAudio(bytes)
  60. } catch (error) {
  61. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  62. }
  63. }
  64. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  65. },
  66. /**
  67. * unMute user's voip audio
  68. * @method unMuteAudio
  69. * @param {Object} user the user which you want to unMute.
  70. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  71. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  72. */
  73. unMuteAudio: function (opts) {
  74. if (_addon) {
  75. const clientOpts = {...opts}
  76. try {
  77. const user = setUserInfo(clientOpts.user)
  78. const UnMuteAudioParams = new messages.UnMuteAudioParams()
  79. UnMuteAudioParams.setUser(user)
  80. const bytes = UnMuteAudioParams.serializeBinary()
  81. return _addon.UnMuteAudio(bytes)
  82. } catch (error) {
  83. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  84. }
  85. }
  86. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  87. },
  88. /**
  89. * Get speaker device list
  90. * @method getSpeakerList
  91. * @return {Array} If the function succeed, the return value is speaker device list, Otherwise NULL.
  92. */
  93. getSpeakerList: function () {
  94. if (_addon) {
  95. const result = _addon.GetSpeakerList()
  96. const message = messages.GetSpeakerList.deserializeBinary(result)
  97. const tempList = message.getSpeakerinfoList()
  98. let speakerList = []
  99. for (let val of tempList) {
  100. let obj = {
  101. deviceID: val.getDeviceid(),
  102. deviceName: val.getDevicename(),
  103. isSelectedDevice: val.getIsselecteddevice()
  104. }
  105. speakerList.push(obj)
  106. }
  107. return speakerList
  108. }
  109. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  110. },
  111. /**
  112. * Get mic device list
  113. * @method getMicList
  114. * @return {Array} If the function succeed, the return value is mic device list, Otherwise NULL.
  115. */
  116. getMicList: function () {
  117. if (_addon) {
  118. const result = _addon.GetMicList()
  119. const message = new messages.GetMicList.deserializeBinary(result)
  120. const tempList = message.getMicinfoList()
  121. let micList = []
  122. for (let val of tempList) {
  123. let obj = {
  124. deviceID: val.getDeviceid(),
  125. deviceName: val.getDevicename(),
  126. isSelectedDevice: val.getIsselecteddevice()
  127. }
  128. micList.push(obj)
  129. }
  130. return micList
  131. }
  132. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  133. },
  134. /**
  135. * Select some speaker device as default device
  136. * @method selectSpeaker
  137. * @param {String} deviceID device id
  138. * @param {String} deviceName device name
  139. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  140. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  141. */
  142. selectSpeaker: function (opts) {
  143. if (_addon) {
  144. const clientOpts = {...opts}
  145. try {
  146. const deviceID = clientOpts.deviceID
  147. const deviceName = clientOpts.deviceName
  148. const SelectSpeakerParams = new messages.SelectSpeakerParams()
  149. SelectSpeakerParams.setZnDeviceid(deviceID)
  150. SelectSpeakerParams.setZnDevicename(deviceName)
  151. const bytes = SelectSpeakerParams.serializeBinary()
  152. return _addon.SelectSpeaker(bytes)
  153. } catch (error) {
  154. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  155. }
  156. }
  157. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  158. },
  159. /**
  160. * Select some mic device as default device
  161. * @method selectMic
  162. * @param {String} deviceID device id
  163. * @param {String} deviceName device name
  164. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  165. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  166. */
  167. selectMic: function (opts) {
  168. if (_addon) {
  169. const clientOpts = {...opts}
  170. try {
  171. const deviceID = clientOpts.deviceID
  172. const deviceName = clientOpts.deviceName
  173. const SelectMicParams = new messages.SelectMicParams()
  174. SelectMicParams.setZnDeviceid(deviceID)
  175. SelectMicParams.setZnDevicename(deviceName)
  176. const bytes = SelectMicParams.serializeBinary()
  177. return _addon.SelectMic(bytes)
  178. } catch (error) {
  179. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  180. }
  181. }
  182. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  183. },
  184. /**
  185. * Subscribe audio raw data
  186. * @method subscribe
  187. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  188. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  189. */
  190. subscribe: function () {
  191. if (_addon) {
  192. return _addon.Subscribe()
  193. }
  194. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  195. },
  196. /**
  197. * UnSubscribe audio raw data
  198. * @method unSubscribe
  199. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  200. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  201. */
  202. unSubscribe: function () {
  203. if (_addon) {
  204. return _addon.UnSubscribe()
  205. }
  206. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  207. },
  208. /**
  209. * Play the pure audio shared by other user. Please call this interface after the callback onUserShareStatusChanged is received and the share type is ZoomVideoSDKShareType_PureAudio.
  210. * @method subscribeToSharedComputerAudio
  211. * @param {Object} user
  212. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  213. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  214. */
  215. subscribeToSharedComputerAudio: function (opts) {
  216. if (_addon) {
  217. const clientOpts = {...opts}
  218. try {
  219. const user = setUserInfo(clientOpts.user)
  220. const SubscribeToSharedComputerAudioParams = new messages.SubscribeToSharedComputerAudioParams()
  221. SubscribeToSharedComputerAudioParams.setZnUser(user)
  222. const bytes = SubscribeToSharedComputerAudioParams.serializeBinary()
  223. return _addon.SubscribeToSharedComputerAudio(bytes)
  224. } catch (error) {
  225. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  226. }
  227. }
  228. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  229. },
  230. /**
  231. * Stop playing the pure audio shared by other user.
  232. * @method unsubscribeToSharedComputerAudio
  233. * @param {Object} user
  234. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  235. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  236. */
  237. unsubscribeToSharedComputerAudio: function (opts) {
  238. if (_addon) {
  239. const clientOpts = {...opts}
  240. try {
  241. const user = setUserInfo(clientOpts.user)
  242. const UnsubscribeToSharedComputerAudioParams = new messages.UnsubscribeToSharedComputerAudioParams()
  243. UnsubscribeToSharedComputerAudioParams.setZnUser(user)
  244. const bytes = UnsubscribeToSharedComputerAudioParams.serializeBinary()
  245. return _addon.UnsubscribeToSharedComputerAudio(bytes)
  246. } catch (error) {
  247. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  248. }
  249. }
  250. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  251. }
  252. }
  253. };
  254. return {
  255. getInstance: function (opts) {
  256. if (!instance) {
  257. instance = init(opts)
  258. }
  259. return instance
  260. }
  261. }
  262. })()