zoom_video_sdk_share.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 screen sharing during a video SDK session.
  7. * @module zoom_video_sdk_share
  8. * @return {ZoomVideoSDKShare}
  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.GetShareHelper() || null
  17. return {
  18. // Public methods and variables
  19. /**
  20. * Share a window
  21. * @method startShareView
  22. * @param {String} handle the window handle that will to be share
  23. * @param {Boolean} isWithDeviceAudio true is share computer sound when share screen/window, otherwise not.
  24. * @param {Boolean} isOptimizeForSharedVideo true is optimize the frame rate when share screen/window, otherwise not.
  25. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  26. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  27. */
  28. startShareView: function (opts) {
  29. if (_addon) {
  30. const clientOpts = {...opts}
  31. try {
  32. const handle = clientOpts.handle
  33. const isWithDeviceAudio = clientOpts.isWithDeviceAudio || false
  34. const isOptimizeForSharedVideo = clientOpts.isOptimizeForSharedVideo || false
  35. const StartShareViewParams = new messages.StartShareViewParams()
  36. StartShareViewParams.setZnHandle(handle)
  37. StartShareViewParams.setIswithdeviceaudio(isWithDeviceAudio)
  38. StartShareViewParams.setIsoptimizeforsharedvideo(isOptimizeForSharedVideo)
  39. const bytes = StartShareViewParams.serializeBinary()
  40. return _addon.StartShareView(bytes)
  41. } catch (error) {
  42. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  43. }
  44. }
  45. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  46. },
  47. /**
  48. * Share a screen
  49. * @method startShareScreen
  50. * @param {String} monitorID the screen name that will to be share
  51. * @param {Boolean} isWithDeviceAudio true is share computer sound when share screen/window, otherwise not.
  52. * @param {Boolean} isOptimizeForSharedVideo true is optimize the frame rate when share screen/window, otherwise not.
  53. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  54. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  55. */
  56. startShareScreen: function (opts) {
  57. if (_addon) {
  58. const clientOpts = {...opts}
  59. try {
  60. const monitorID = clientOpts.monitorID
  61. const isWithDeviceAudio = clientOpts.isWithDeviceAudio || false
  62. const isOptimizeForSharedVideo = clientOpts.isOptimizeForSharedVideo || false
  63. const StartShareScreenParams = new messages.StartShareScreenParams()
  64. StartShareScreenParams.setZnMonitorid(monitorID)
  65. StartShareScreenParams.setIswithdeviceaudio(isWithDeviceAudio)
  66. StartShareScreenParams.setIsoptimizeforsharedvideo(isOptimizeForSharedVideo)
  67. const bytes = StartShareScreenParams.serializeBinary()
  68. return _addon.StartShareScreen(bytes)
  69. } catch (error) {
  70. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  71. }
  72. }
  73. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  74. },
  75. /**
  76. * Start sharing only the computer audio.
  77. * @method startShareComputerAudio
  78. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  79. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  80. */
  81. startShareComputerAudio: function () {
  82. if (_addon) {
  83. return _addon.StartShareComputerAudio()
  84. }
  85. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  86. },
  87. /**
  88. * Stop share
  89. * @method stopShare
  90. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  91. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  92. */
  93. stopShare: function () {
  94. if (_addon) {
  95. return _addon.StopShare()
  96. }
  97. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  98. },
  99. /**
  100. * Determine if myself is sharing
  101. * @method isSharingOut
  102. * @return {Boolean} true if myself is sharing. Otherwise returns false.
  103. */
  104. isSharingOut: function () {
  105. if (_addon) {
  106. return _addon.IsSharingOut()
  107. }
  108. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  109. },
  110. /**
  111. * Determine if myself is sharing screen
  112. * @method isScreenSharingOut
  113. * @return {Boolean} true if myself is sharing screen. Otherwise returns false.
  114. */
  115. isScreenSharingOut: function () {
  116. if (_addon) {
  117. return _addon.IsScreenSharingOut()
  118. }
  119. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  120. },
  121. /**
  122. * Determine if other user is sharing
  123. * @method isOtherSharing
  124. * @return {Boolean} true if other user is sharing screen. Otherwise returns false.
  125. */
  126. isOtherSharing: function () {
  127. if (_addon) {
  128. return _addon.IsOtherSharing()
  129. }
  130. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  131. },
  132. /**
  133. * Lock current share.(only host call)
  134. * @method lockShare
  135. * @param {Boolean} bLock
  136. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  137. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  138. */
  139. lockShare: function (opts) {
  140. if (_addon) {
  141. const clientOpts = {...opts}
  142. try {
  143. const bLock = clientOpts.bLock
  144. const LockShareParams = new messages.LockShareParams()
  145. LockShareParams.setZnBlock(bLock)
  146. const bytes = LockShareParams.serializeBinary()
  147. return _addon.LockShare(bytes)
  148. } catch (error) {
  149. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  150. }
  151. }
  152. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  153. },
  154. /**
  155. * Determine if share is locked
  156. * @method isShareLocked
  157. * @return {Boolean} true if share is locked. Otherwise returns false.
  158. */
  159. isShareLocked: function () {
  160. if (_addon) {
  161. return _addon.IsShareLocked()
  162. }
  163. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  164. },
  165. /**
  166. * Enable or disable the computer sound when sharing, if virtual speaker is enabled, don't support share audio.
  167. * @method enableShareDeviceAudio
  168. * @param {Boolean} bEnable, true indicates to enable. false disable.
  169. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  170. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  171. */
  172. enableShareDeviceAudio: function (opts) {
  173. if (_addon) {
  174. const clientOpts = {...opts}
  175. try {
  176. const bEnable = clientOpts.bEnable
  177. const EnableShareDeviceAudioParams = new messages.EnableShareDeviceAudioParams()
  178. EnableShareDeviceAudioParams.setEnable(bEnable)
  179. const bytes = EnableShareDeviceAudioParams.serializeBinary()
  180. return _addon.EnableShareDeviceAudio(bytes)
  181. } catch (error) {
  182. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  183. }
  184. }
  185. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  186. },
  187. /**
  188. * Determine if share computer sound is enabled.
  189. * @method isShareDeviceAudioEnabled
  190. * @return {Boolean} true if enabled. Otherwise returns false.
  191. */
  192. isShareDeviceAudioEnabled: function () {
  193. if (_addon) {
  194. return _addon.IsShareDeviceAudioEnabled()
  195. }
  196. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  197. },
  198. /**
  199. * Enable or disable the optimization of frame rate, you can enable it when there is video in shared content.
  200. * @method enableOptimizeForSharedVideo
  201. * @param {Boolean} bEnable, true indicates to enable. false disable.
  202. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  203. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  204. */
  205. enableOptimizeForSharedVideo: function (opts) {
  206. if (_addon) {
  207. const clientOpts = {...opts}
  208. try {
  209. const bEnable = clientOpts.bEnable
  210. const EnableOptimizeForSharedVideoParams = new messages.EnableOptimizeForSharedVideoParams()
  211. EnableOptimizeForSharedVideoParams.setEnable(bEnable)
  212. const bytes = EnableOptimizeForSharedVideoParams.serializeBinary()
  213. return _addon.EnableOptimizeForSharedVideo(bytes)
  214. } catch (error) {
  215. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  216. }
  217. }
  218. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  219. },
  220. /**
  221. * Determine if optimization for shared video is enabled.
  222. * @method isOptimizeForSharedVideoEnabled
  223. * @return {Boolean} true if enabled. otherwise returns false.
  224. */
  225. isOptimizeForSharedVideoEnabled: function () {
  226. if (_addon) {
  227. return _addon.IsOptimizeForSharedVideoEnabled()
  228. }
  229. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  230. },
  231. /**
  232. * Start sharing a camera feed specified by the cameraID as the second camera.
  233. * @method startShare2ndCamera
  234. * @param {String} cameraID, The camera ID.Warning: This must be a different camera than the one sending your primary video.
  235. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  236. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  237. */
  238. startShare2ndCamera: function (opts) {
  239. if (_addon) {
  240. const clientOpts = {...opts}
  241. try {
  242. const cameraID = clientOpts.cameraID
  243. const StartShare2ndCameraParams = new messages.StartShare2ndCameraParams()
  244. StartShare2ndCameraParams.setZnCameraid(cameraID)
  245. const bytes = StartShare2ndCameraParams.serializeBinary()
  246. return _addon.StartShare2ndCamera(bytes)
  247. } catch (error) {
  248. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  249. }
  250. }
  251. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  252. },
  253. /**
  254. * Subscribe to the raw data stream of the camera that is shared as the second camera.
  255. * @method subscribeMyShareCamera
  256. * @param {Number} recv_handle, Data handler.
  257. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  258. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  259. */
  260. subscribeMyShareCamera: function (opts) {
  261. if (_addon) {
  262. const clientOpts = {...opts}
  263. try {
  264. const recv_handle = clientOpts.recv_handle
  265. const SubscribeMyShareCameraParams = new messages.SubscribeMyShareCameraParams()
  266. SubscribeMyShareCameraParams.setZnRecvHandle(recv_handle)
  267. const bytes = SubscribeMyShareCameraParams.serializeBinary()
  268. return _addon.SubscribeMyShareCamera(bytes)
  269. } catch (error) {
  270. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  271. }
  272. }
  273. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  274. },
  275. /**
  276. * Unsubscribe to the raw data stream of the camera that is shared as the second camera.
  277. * @method unSubscribeMyShareCamera
  278. * @return {ZoomSDKError} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  279. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  280. */
  281. unSubscribeMyShareCamera: function () {
  282. if (_addon) {
  283. return _addon.UnSubscribeMyShareCamera()
  284. }
  285. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  286. }
  287. }
  288. };
  289. return {
  290. getInstance: function (opts) {
  291. if (!instance) {
  292. instance = init(opts)
  293. }
  294. return instance
  295. }
  296. }
  297. })()