zoom_video_sdk_live_stream.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 live streaming during a video SDK session.
  7. * @module zoom_video_sdk_live_stream
  8. * @return {ZoomVideoSDKLiveStream}
  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.GetLiveStreamHelper()
  17. return {
  18. // Public methods and variables
  19. /**
  20. * start live steam
  21. * @method startLiveStream
  22. * @param {String} streamUrl the live stream url
  23. * @param {String} msgContent the live stream key
  24. * @param {String} broadcastUrl the live stream broadcast url
  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. startLiveStream: function (opts) {
  29. if (_addon) {
  30. const clientOpts = {...opts}
  31. try {
  32. const streamUrl = clientOpts.streamUrl
  33. const key = clientOpts.key
  34. const broadcastUrl = clientOpts.broadcastUrl
  35. const StartLiveStreamParams = new messages.StartLiveStreamParams()
  36. StartLiveStreamParams.setZnStreamurl(streamUrl)
  37. StartLiveStreamParams.setZnKey(key)
  38. StartLiveStreamParams.setZnBroadcasturl(broadcastUrl)
  39. const bytes = StartLiveStreamParams.serializeBinary()
  40. return _addon.StartLiveStream(bytes)
  41. } catch (error) {
  42. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Invalid_Parameter;
  43. }
  44. }
  45. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  46. },
  47. /**
  48. * stop live steam
  49. * @method stopLiveStream
  50. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  51. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  52. */
  53. stopLiveStream: function () {
  54. if (_addon) {
  55. return _addon.StopLiveStream()
  56. }
  57. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  58. },
  59. /**
  60. * Can start live steam
  61. * @method canStartLiveStream
  62. * @return {Number} If the function succeed, the return value is ZoomVideoSDKErrors_Success.
  63. Otherwise failed. To get extended error information, {@link ZoomVideoSDKErrors} enum.
  64. */
  65. canStartLiveStream: function () {
  66. if (_addon) {
  67. return _addon.CanStartLiveStream()
  68. }
  69. return ZoomVideoSDKErrors.ZoomVideoSDKErrors_Internal_Error
  70. }
  71. }
  72. };
  73. return {
  74. getInstance: function (opts) {
  75. if (!instance) {
  76. instance = init(opts)
  77. }
  78. return instance
  79. }
  80. }
  81. })()