zoom_video_sdk_audio_setting.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import { ZoomVideoSDKErrors, ZoomVideoSDKSuppressBackgroundNoiseLevel, ZoomVideoSDKEchoCancellationLevel } from './zoom_video_sdk_defines.js'
  2. import messages from './electron_zoomvideosdk_pb.js'
  3. export default (function () {
  4. var instance
  5. /**
  6. * Zoom Video SDK Audio Setting
  7. * @module zoom_video_sdk_audio_setting
  8. * @return {ZoomVideoSDKAudioSetting}
  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.GetAudioSetting()
  17. return {
  18. // Public methods and variables
  19. /**
  20. * Get the suppress background noise level.
  21. * @method getSuppressBackgroundNoiseLevel
  22. * @return {Object} contains err and level. the level value is suppress background noise level. {@link ZoomVideoSDKSuppressBackgroundNoiseLevel} enum.
  23. */
  24. getSuppressBackgroundNoiseLevel: function (opts) {
  25. if (_addon) {
  26. try {
  27. return _addon.GetSuppressBackgroundNoiseLevel()
  28. } catch (error) {
  29. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  30. }
  31. }
  32. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  33. },
  34. /**
  35. * Set the suppress background noise level.
  36. * @method setSuppressBackgroundNoiseLevel
  37. * @param {Number} level The new suppress background noise level to be set {@link ZoomVideoSDKSuppressBackgroundNoiseLevel} enum.
  38. * @return {Object} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  39. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  40. */
  41. setSuppressBackgroundNoiseLevel: function (opts) {
  42. if (_addon) {
  43. const clientOpts = {...opts}
  44. try {
  45. const level = clientOpts.level || ZoomVideoSDKSuppressBackgroundNoiseLevel.ZoomVideoSDKSuppressBackgroundNoiseLevel_Auto
  46. const SetSuppressBackgroundNoiseLevelParams = new messages.SetSuppressBackgroundNoiseLevelParams()
  47. SetSuppressBackgroundNoiseLevelParams.setLevel(level)
  48. const bytes = SetSuppressBackgroundNoiseLevelParams.serializeBinary()
  49. return _addon.SetSuppressBackgroundNoiseLevel(bytes)
  50. } catch (error) {
  51. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  52. }
  53. }
  54. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  55. },
  56. /**
  57. * Enable or disable the original input of mic.
  58. * @method enableMicOriginalInput
  59. * @param {Boolean} bEnable TRUE indicates to enable the original input of mic.
  60. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  61. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  62. */
  63. enableMicOriginalInput: function (opts) {
  64. if (_addon) {
  65. const clientOpts = {...opts}
  66. try {
  67. const bEnable = clientOpts.bEnable
  68. const EnableMicOriginalInputParams = new messages.EnableMicOriginalInputParams()
  69. EnableMicOriginalInputParams.setBenable(bEnable)
  70. const bytes = EnableMicOriginalInputParams.serializeBinary()
  71. return _addon.EnableMicOriginalInput(bytes)
  72. } catch (error) {
  73. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  74. }
  75. }
  76. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  77. },
  78. /**
  79. * Get the flag to enable/disable the original input of mic.
  80. * @method isMicOriginalInputEnable
  81. * @return {Object} contains err and bEnable.
  82. */
  83. isMicOriginalInputEnable: function () {
  84. if (_addon) {
  85. try {
  86. return _addon.IsMicOriginalInputEnable()
  87. } catch (error) {
  88. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  89. }
  90. }
  91. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  92. },
  93. /**
  94. * Set whether to enable the function of high fidelity music mode or not. This function is valid only if mic original input is enabled, otherwise invalid.
  95. * @method EnableHighFidelityMusicMode
  96. * @param {Boolean} bEnable True means to enable the function, FALSE not.
  97. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  98. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  99. */
  100. enableHighFidelityMusicMode: function (opts) {
  101. if (_addon) {
  102. const clientOpts = {...opts}
  103. try {
  104. const bEnable = clientOpts.bEnable
  105. const EnableHighFidelityMusicModeParams = new messages.EnableHighFidelityMusicModeParams()
  106. EnableHighFidelityMusicModeParams.setBenable(bEnable)
  107. const bytes = EnableHighFidelityMusicModeParams.serializeBinary()
  108. return _addon.EnableHighFidelityMusicMode(bytes)
  109. } catch (error) {
  110. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  111. }
  112. }
  113. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  114. },
  115. /**
  116. * Check whether the high fidelity music mode is enabled or not.
  117. * @method isHighFidelityMusicModeEnable
  118. * @return {Object} contains err and bEnable. If bEnable is TRUE, it means the echo cancellation is enabled
  119. */
  120. isHighFidelityMusicModeEnable: function () {
  121. if (_addon) {
  122. try {
  123. return _addon.IsHighFidelityMusicModeEnable()
  124. } catch (error) {
  125. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  126. }
  127. }
  128. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  129. },
  130. /**
  131. * Set whether to disable the function of echo cancellation or not. This function is valid only if mic original input is enabled, otherwise invalid.
  132. * @method enableEchoCancellation
  133. * @param {Boolean} bEnable True means to enable the function, FALSE not.
  134. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  135. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  136. */
  137. enableEchoCancellation: function (opts) {
  138. if (_addon) {
  139. const clientOpts = {...opts}
  140. try {
  141. const bEnable = clientOpts.bEnable
  142. const EnableEchoCancellationParams = new messages.EnableEchoCancellationParams()
  143. EnableEchoCancellationParams.setBenable(bEnable)
  144. const bytes = EnableEchoCancellationParams.serializeBinary()
  145. return _addon.EnableEchoCancellation(bytes)
  146. } catch (error) {
  147. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  148. }
  149. }
  150. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  151. },
  152. /**
  153. * Check whether the echo cancellation is enabled or not.
  154. * @method isEchoCancellationEnable
  155. * @return {Object} contains err and bEnable. If bEnable is TRUE, it means the echo cancellation is disabled
  156. */
  157. isEchoCancellationEnable: function () {
  158. if (_addon) {
  159. try {
  160. return _addon.IsEchoCancellationEnable()
  161. } catch (error) {
  162. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  163. }
  164. }
  165. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  166. },
  167. /**
  168. * Enable or disable the stereo audio. This function is valid only if mic original input is enabled, otherwise invalid.
  169. * @method enableStereoAudio
  170. * @param {Boolean} bEnable TRUE indicates to enable the stereo audio.
  171. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  172. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  173. */
  174. enableStereoAudio: function (opts) {
  175. if (_addon) {
  176. const clientOpts = {...opts}
  177. try {
  178. const bEnable = clientOpts.bEnable
  179. const EnableStereoAudioParams = new messages.EnableStereoAudioParams()
  180. EnableStereoAudioParams.setBenable(bEnable)
  181. const bytes = EnableStereoAudioParams.serializeBinary()
  182. return _addon.EnableStereoAudio(bytes)
  183. } catch (error) {
  184. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  185. }
  186. }
  187. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  188. },
  189. /**
  190. * Get the flag to enable/disable the stereo audio.
  191. * @method isStereoAudioEnable
  192. * @return {Object} contains err and bEnable.
  193. */
  194. isStereoAudioEnable: function () {
  195. if (_addon) {
  196. try {
  197. return _addon.IsStereoAudioEnable()
  198. } catch (error) {
  199. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  200. }
  201. }
  202. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  203. },
  204. /**
  205. * Get the echo cancellation level.
  206. * @method getEchoCancellationLevel
  207. * @return {Object} contains err and level. level echo cancellation level.
  208. */
  209. getEchoCancellationLevel: function () {
  210. if (_addon) {
  211. try {
  212. return _addon.GetEchoCancellationLevel()
  213. } catch (error) {
  214. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  215. }
  216. }
  217. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  218. },
  219. /**
  220. * Set the echo cancellation level.
  221. * @method setEchoCancellationLevel
  222. * @param {Number} level The new echo cancellation level to be set {@link ZoomVideoSDKEchoCancellationLevel} enum.
  223. * @return {Object} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  224. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  225. */
  226. setEchoCancellationLevel: function (opts) {
  227. if (_addon) {
  228. const clientOpts = {...opts}
  229. try {
  230. const level = clientOpts.level || ZoomVideoSDKEchoCancellationLevel.ZoomVideoSDKEchoCancellationLevel_Default
  231. const SetEchoCancellationLevelParams = new messages.SetEchoCancellationLevelParams()
  232. SetEchoCancellationLevelParams.setLevel(level)
  233. const bytes = SetEchoCancellationLevelParams.serializeBinary()
  234. return _addon.SetEchoCancellationLevel(bytes)
  235. } catch (error) {
  236. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  237. }
  238. }
  239. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  240. }
  241. }
  242. };
  243. return {
  244. getInstance: function (opts) {
  245. if (!instance) {
  246. instance = init(opts)
  247. }
  248. return instance
  249. }
  250. }
  251. })()