zoom_video_sdk_remote_camera_control.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. function checkCameraCtrlRange(range) {
  5. if (range < 10) {
  6. return 10
  7. } else if (range > 100) {
  8. return 100
  9. } else {
  10. return range
  11. }
  12. }
  13. export default (function () {
  14. var instance
  15. /**
  16. * Get the helper class instance to access the remote camera control.
  17. * @module zoom_video_sdk_remote_camera_control
  18. * @return {ZoomVideoSDKRemoteCameraControl}
  19. */
  20. function init(opts) {
  21. const clientOpts = {...opts}
  22. // Private methods and variables
  23. if (!clientOpts.addon) {
  24. return null
  25. }
  26. const _addon = clientOpts.addon.GetRemoteCameraCtrlHelper()
  27. return {
  28. // Public methods and variables
  29. /**
  30. * Request to control remote camera.
  31. * @method requestControlRemoteCamera
  32. * @param {Object} user
  33. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  34. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  35. */
  36. requestControlRemoteCamera: function (opts) {
  37. if (_addon) {
  38. const clientOpts = {...opts}
  39. try {
  40. const user = setUserInfo(clientOpts.user)
  41. const RequestControlRemoteCameraParams = new messages.RequestControlRemoteCameraParams()
  42. RequestControlRemoteCameraParams.setUser(user)
  43. const bytes = RequestControlRemoteCameraParams.serializeBinary()
  44. return _addon.RequestControlRemoteCamera(bytes)
  45. } catch (error) {
  46. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  47. }
  48. }
  49. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  50. },
  51. /**
  52. * Give up control of the remote camera.
  53. * @method giveUpControlRemoteCamera
  54. * @param {Object} user
  55. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  56. Otherwise failed. To get extended error information, see {@link ZoomVideoSDKErrors} enum.
  57. */
  58. giveUpControlRemoteCamera: function (opts) {
  59. if (_addon) {
  60. const clientOpts = {...opts}
  61. try {
  62. const user = setUserInfo(clientOpts.user)
  63. const GiveUpControlRemoteCameraParams = new messages.GiveUpControlRemoteCameraParams()
  64. GiveUpControlRemoteCameraParams.setUser(user)
  65. const bytes = GiveUpControlRemoteCameraParams.serializeBinary()
  66. return _addon.GiveUpControlRemoteCamera(bytes)
  67. } catch (error) {
  68. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  69. }
  70. }
  71. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  72. },
  73. /**
  74. * Turn the camera to the left.
  75. * @method turnLeft
  76. * @param {Number} Rotation range, 10 <= range <= 100.
  77. * @param {Object} user
  78. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  79. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  80. */
  81. turnLeft: function (opts) {
  82. if (_addon) {
  83. const clientOpts = {...opts}
  84. try {
  85. let range = checkCameraCtrlRange(clientOpts.range)
  86. const user = setUserInfo(clientOpts.user)
  87. const RemoteCameraCtrlTurnLeftParams = new messages.RemoteCameraCtrlTurnLeftParams()
  88. RemoteCameraCtrlTurnLeftParams.setRange(range)
  89. RemoteCameraCtrlTurnLeftParams.setUser(user)
  90. const bytes = RemoteCameraCtrlTurnLeftParams.serializeBinary()
  91. return _addon.TurnLeft(bytes)
  92. } catch (error) {
  93. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  94. }
  95. }
  96. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  97. },
  98. /**
  99. * Turn the camera to the right.
  100. * @method turnRight
  101. * @param {Number} Rotation range, 10 <= range <= 100.
  102. * @param {Object} user
  103. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  104. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  105. */
  106. turnRight: function (opts) {
  107. if (_addon) {
  108. const clientOpts = {...opts}
  109. try {
  110. const range = checkCameraCtrlRange(clientOpts.range)
  111. const user = setUserInfo(clientOpts.user)
  112. const RemoteCameraCtrlTurnRightParams = new messages.RemoteCameraCtrlTurnRightParams()
  113. RemoteCameraCtrlTurnRightParams.setRange(range)
  114. RemoteCameraCtrlTurnRightParams.setUser(user)
  115. const bytes = RemoteCameraCtrlTurnRightParams.serializeBinary()
  116. return _addon.TurnRight(bytes)
  117. } catch (error) {
  118. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  119. }
  120. }
  121. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  122. },
  123. /**
  124. * Turn the camera up.
  125. * @method turnUp
  126. * @param {Number} Rotation range, 10 <= range <= 100.
  127. * @param {Object} user
  128. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  129. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  130. */
  131. turnUp: function (opts) {
  132. if (_addon) {
  133. const clientOpts = {...opts}
  134. try {
  135. const range = checkCameraCtrlRange(clientOpts.range)
  136. const user = setUserInfo(clientOpts.user)
  137. const RemoteCameraCtrlTurnUpParams = new messages.RemoteCameraCtrlTurnUpParams()
  138. RemoteCameraCtrlTurnUpParams.setRange(range)
  139. RemoteCameraCtrlTurnUpParams.setUser(user)
  140. const bytes = RemoteCameraCtrlTurnUpParams.serializeBinary()
  141. return _addon.TurnUp(bytes)
  142. } catch (error) {
  143. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  144. }
  145. }
  146. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  147. },
  148. /**
  149. * Turn the camera down.
  150. * @method turnDown
  151. * @param {Number} Rotation range, 10 <= range <= 100.
  152. * @param {Object} user
  153. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  154. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  155. */
  156. turnDown: function (opts) {
  157. if (_addon) {
  158. const clientOpts = {...opts}
  159. try {
  160. const range = checkCameraCtrlRange(clientOpts.range)
  161. const user = setUserInfo(clientOpts.user)
  162. const RemoteCameraCtrlTurnDownParams = new messages.RemoteCameraCtrlTurnDownParams()
  163. RemoteCameraCtrlTurnDownParams.setRange(range)
  164. RemoteCameraCtrlTurnDownParams.setUser(user)
  165. const bytes = RemoteCameraCtrlTurnDownParams.serializeBinary()
  166. return _addon.TurnDown(bytes)
  167. } catch (error) {
  168. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  169. }
  170. }
  171. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  172. },
  173. /**
  174. * Zoom the camera in.
  175. * @method zoomIn
  176. * @param {Number} Zoom range, 10 <= range <= 100.
  177. * @param {Object} user
  178. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  179. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  180. */
  181. zoomIn: function (opts) {
  182. if (_addon) {
  183. const clientOpts = {...opts}
  184. try {
  185. const range = checkCameraCtrlRange(clientOpts.range)
  186. const user = setUserInfo(clientOpts.user)
  187. const RemoteCameraCtrlZoomInParams = new messages.RemoteCameraCtrlZoomInParams()
  188. RemoteCameraCtrlZoomInParams.setRange(range)
  189. RemoteCameraCtrlZoomInParams.setUser(user)
  190. const bytes = RemoteCameraCtrlZoomInParams.serializeBinary()
  191. return _addon.ZoomIn(bytes)
  192. } catch (error) {
  193. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  194. }
  195. }
  196. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  197. },
  198. /**
  199. * Zoom the camera out.
  200. * @method zoomOut
  201. * @param {Number} Zoom range, 10 <= range <= 100.
  202. * @param {Object} user
  203. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  204. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  205. */
  206. zoomOut: function (opts) {
  207. if (_addon) {
  208. const clientOpts = {...opts}
  209. try {
  210. const range = checkCameraCtrlRange(clientOpts.range)
  211. const user = setUserInfo(clientOpts.user)
  212. const RemoteCameraCtrlZoomOutParams = new messages.RemoteCameraCtrlZoomOutParams()
  213. RemoteCameraCtrlZoomOutParams.setRange(range)
  214. RemoteCameraCtrlZoomOutParams.setUser(user)
  215. const bytes = RemoteCameraCtrlZoomOutParams.serializeBinary()
  216. return _addon.ZoomOut(bytes)
  217. } catch (error) {
  218. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  219. }
  220. }
  221. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  222. }
  223. }
  224. };
  225. return {
  226. getInstance: function (opts) {
  227. if (!instance) {
  228. instance = init(opts)
  229. }
  230. return instance
  231. }
  232. }
  233. })()