zoom_video_sdk_cmd.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 use command channel features during a video SDK session.
  7. * @module zoom_video_sdk_cmd
  8. * @return {ZoomVideoSDKCmd}
  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.GetCmdChannel()
  17. return {
  18. // Public methods and variables
  19. /**
  20. * Send custom commands to other users in the current session.
  21. * @method sendCommand
  22. * @param {Object} user, the user who will receive the command, if receiver is NULL, send to all.
  23. * @param {String} strCmd, the customized command.
  24. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  25. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  26. */
  27. sendCommand: function (opts) {
  28. if (_addon) {
  29. const clientOpts = {...opts}
  30. try {
  31. const user = clientOpts.user
  32. const strCmd = clientOpts.strCmd
  33. const SendCommandParams = new messages.SendCommandParams()
  34. SendCommandParams.setUser(user)
  35. SendCommandParams.setStrcmd(strCmd)
  36. const bytes = SendCommandParams.serializeBinary()
  37. return _addon.SendCommand(bytes)
  38. } catch (error) {
  39. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  40. }
  41. }
  42. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  43. }
  44. }
  45. };
  46. return {
  47. getInstance: function (opts) {
  48. if (!instance) {
  49. instance = init(opts)
  50. }
  51. return instance
  52. }
  53. }
  54. })()